File tree 7 files changed +75
-3
lines changed
7 files changed +75
-3
lines changed Original file line number Diff line number Diff line change
1
+ use gix_hash:: ObjectId ;
1
2
use gix_object:: Exists ;
2
3
use std:: ops:: DerefMut ;
3
4
@@ -129,6 +130,12 @@ impl gix_object::Write for crate::Repository {
129
130
130
131
impl gix_object:: FindHeader for crate :: Repository {
131
132
fn try_header ( & self , id : & gix_hash:: oid ) -> Result < Option < gix_object:: Header > , gix_object:: find:: Error > {
133
+ if id == ObjectId :: empty_tree ( self . object_hash ( ) ) {
134
+ return Ok ( Some ( gix_object:: Header {
135
+ kind : gix_object:: Kind :: Tree ,
136
+ size : 0 ,
137
+ } ) ) ;
138
+ }
132
139
self . objects . try_header ( id)
133
140
}
134
141
}
@@ -139,12 +146,22 @@ impl gix_object::Find for crate::Repository {
139
146
id : & gix_hash:: oid ,
140
147
buffer : & ' a mut Vec < u8 > ,
141
148
) -> Result < Option < gix_object:: Data < ' a > > , gix_object:: find:: Error > {
149
+ if id == ObjectId :: empty_tree ( self . object_hash ( ) ) {
150
+ buffer. clear ( ) ;
151
+ return Ok ( Some ( gix_object:: Data {
152
+ kind : gix_object:: Kind :: Tree ,
153
+ data : & [ ] ,
154
+ } ) ) ;
155
+ }
142
156
self . objects . try_find ( id, buffer)
143
157
}
144
158
}
145
159
146
160
impl gix_object:: Exists for crate :: Repository {
147
161
fn exists ( & self , id : & gix_hash:: oid ) -> bool {
162
+ if id == ObjectId :: empty_tree ( self . object_hash ( ) ) {
163
+ return true ;
164
+ }
148
165
self . objects . exists ( id)
149
166
}
150
167
}
Original file line number Diff line number Diff line change @@ -140,7 +140,7 @@ impl crate::Repository {
140
140
/// Note that this is an expensive operation as it requires recursively traversing the entire tree to unpack it into the index.
141
141
pub fn index_from_tree ( & self , tree : & gix_hash:: oid ) -> Result < gix_index:: File , super :: index_from_tree:: Error > {
142
142
Ok ( gix_index:: File :: from_state (
143
- gix_index:: State :: from_tree ( tree, & self . objects , self . config . protect_options ( ) ?) . map_err ( |err| {
143
+ gix_index:: State :: from_tree ( tree, self , self . config . protect_options ( ) ?) . map_err ( |err| {
144
144
super :: index_from_tree:: Error :: IndexFromTree {
145
145
id : tree. into ( ) ,
146
146
source : err,
Original file line number Diff line number Diff line change 53
53
crate :: head:: peel:: to_object:: Error :: Unborn { .. } ,
54
54
) ,
55
55
) ,
56
- ) ) => None ,
56
+ ) ) => Some ( gix_hash :: ObjectId :: empty_tree ( self . repo . object_hash ( ) ) ) ,
57
57
Err ( err) => return Err ( err. into ( ) ) ,
58
58
} ,
59
59
Some ( Some ( tree_id) ) => Some ( tree_id) ,
Original file line number Diff line number Diff line change @@ -34,4 +34,10 @@ git init racy-git
34
34
git init untracked-unborn
35
35
(cd untracked-unborn
36
36
touch untracked
37
- )
37
+ )
38
+
39
+ git init untracked-added
40
+ (cd untracked-added
41
+ echo content > added
42
+ git add added
43
+ )
Original file line number Diff line number Diff line change 1
1
use crate :: util:: named_subrepo_opts;
2
2
use gix_testtools:: tempfile;
3
3
4
+ mod object_database_impl {
5
+ use gix_object:: { Exists , Find , FindHeader } ;
6
+
7
+ #[ test]
8
+ fn empty_tree_is_always_present ( ) -> crate :: Result {
9
+ let repo = crate :: named_subrepo_opts ( "make_basic_repo.sh" , "unborn" , gix:: open:: Options :: isolated ( ) ) ?;
10
+ let empty_tree = gix:: ObjectId :: empty_tree ( repo. object_hash ( ) ) ;
11
+ assert ! ( repo. exists( & empty_tree) ) ;
12
+ assert_eq ! (
13
+ repo. try_header( & empty_tree) ?. expect( "tree present" ) ,
14
+ gix_object:: Header {
15
+ kind: gix_object:: Kind :: Tree ,
16
+ size: 0
17
+ }
18
+ ) ;
19
+ let mut buf = repo. empty_reusable_buffer ( ) ;
20
+ buf. push ( 42 ) ;
21
+ assert_eq ! (
22
+ repo. try_find( & empty_tree, & mut buf) ?. expect( "tree present" ) . kind,
23
+ gix_object:: Kind :: Tree
24
+ ) ;
25
+ assert_eq ! ( buf. len( ) , 0 , "the data in the buffer matches the empty tree" ) ;
26
+ Ok ( ( ) )
27
+ }
28
+ }
29
+
4
30
#[ cfg( feature = "tree-editor" ) ]
5
31
mod edit_tree {
6
32
use crate :: util:: hex_to_id;
Original file line number Diff line number Diff line change @@ -113,6 +113,29 @@ mod into_iter {
113
113
Ok ( ( ) )
114
114
}
115
115
116
+ #[ test]
117
+ fn untracked_added ( ) -> crate :: Result {
118
+ let repo = repo ( "untracked-added" ) ?;
119
+ let mut status = repo. status ( gix:: progress:: Discard ) ?. into_iter ( None ) ?;
120
+ let mut items: Vec < _ > = status. by_ref ( ) . filter_map ( Result :: ok) . collect ( ) ;
121
+ items. sort_by ( |a, b| a. location ( ) . cmp ( b. location ( ) ) ) ;
122
+ insta:: assert_debug_snapshot!( items, @r#"
123
+ [
124
+ TreeIndex(
125
+ Addition {
126
+ location: "added",
127
+ index: 0,
128
+ entry_mode: Mode(
129
+ FILE,
130
+ ),
131
+ id: Sha1(d95f3ad14dee633a758d2e331151e950dd13e4ed),
132
+ },
133
+ ),
134
+ ]
135
+ "# ) ;
136
+ Ok ( ( ) )
137
+ }
138
+
116
139
#[ test]
117
140
fn error_during_tree_traversal_causes_failure ( ) -> crate :: Result {
118
141
let repo = repo ( "untracked-only" ) ?;
You can’t perform that action at this time.
0 commit comments