@@ -17,6 +17,7 @@ public void CanCompareTwoTreeEntries()
17
17
using ( var repo = new Repository ( path ) )
18
18
{
19
19
var tree = repo . Lookup < Tree > ( sha ) ;
20
+ Assert . False ( tree . IsMissing ) ;
20
21
TreeEntry treeEntry1 = tree [ "README" ] ;
21
22
TreeEntry treeEntry2 = tree [ "README" ] ;
22
23
Assert . Equal ( treeEntry2 , treeEntry1 ) ;
@@ -31,6 +32,7 @@ public void CanConvertEntryToBlob()
31
32
using ( var repo = new Repository ( path ) )
32
33
{
33
34
var tree = repo . Lookup < Tree > ( sha ) ;
35
+ Assert . False ( tree . IsMissing ) ;
34
36
TreeEntry treeEntry = tree [ "README" ] ;
35
37
36
38
var blob = treeEntry . Target as Blob ;
@@ -45,6 +47,7 @@ public void CanConvertEntryToTree()
45
47
using ( var repo = new Repository ( path ) )
46
48
{
47
49
var tree = repo . Lookup < Tree > ( sha ) ;
50
+ Assert . False ( tree . IsMissing ) ;
48
51
TreeEntry treeEntry = tree [ "1" ] ;
49
52
50
53
var subtree = treeEntry . Target as Tree ;
@@ -59,6 +62,7 @@ public void CanEnumerateBlobs()
59
62
using ( var repo = new Repository ( path ) )
60
63
{
61
64
var tree = repo . Lookup < Tree > ( sha ) ;
65
+ Assert . False ( tree . IsMissing ) ;
62
66
63
67
IEnumerable < Blob > blobs = tree
64
68
. Where ( e => e . TargetType == TreeEntryTargetType . Blob )
@@ -76,6 +80,7 @@ public void CanEnumerateSubTrees()
76
80
using ( var repo = new Repository ( path ) )
77
81
{
78
82
var tree = repo . Lookup < Tree > ( sha ) ;
83
+ Assert . False ( tree . IsMissing ) ;
79
84
80
85
IEnumerable < Tree > subTrees = tree
81
86
. Where ( e => e . TargetType == TreeEntryTargetType . Tree )
@@ -93,6 +98,7 @@ public void CanEnumerateTreeEntries()
93
98
using ( var repo = new Repository ( path ) )
94
99
{
95
100
var tree = repo . Lookup < Tree > ( sha ) ;
101
+ Assert . False ( tree . IsMissing ) ;
96
102
Assert . Equal ( tree . Count , tree . Count ( ) ) ;
97
103
98
104
Assert . Equal ( new [ ] { "1" , "README" , "branch_file.txt" , "new.txt" } , tree . Select ( te => te . Name ) . ToArray ( ) ) ;
@@ -106,6 +112,7 @@ public void CanGetEntryByName()
106
112
using ( var repo = new Repository ( path ) )
107
113
{
108
114
var tree = repo . Lookup < Tree > ( sha ) ;
115
+ Assert . False ( tree . IsMissing ) ;
109
116
TreeEntry treeEntry = tree [ "README" ] ;
110
117
Assert . Equal ( "a8233120f6ad708f843d861ce2b7228ec4e3dec6" , treeEntry . Target . Sha ) ;
111
118
Assert . Equal ( "README" , treeEntry . Name ) ;
@@ -119,6 +126,7 @@ public void GettingAnUknownTreeEntryReturnsNull()
119
126
using ( var repo = new Repository ( path ) )
120
127
{
121
128
var tree = repo . Lookup < Tree > ( sha ) ;
129
+ Assert . False ( tree . IsMissing ) ;
122
130
TreeEntry treeEntry = tree [ "I-do-not-exist" ] ;
123
131
Assert . Null ( treeEntry ) ;
124
132
}
@@ -131,6 +139,7 @@ public void CanGetEntryCountFromTree()
131
139
using ( var repo = new Repository ( path ) )
132
140
{
133
141
var tree = repo . Lookup < Tree > ( sha ) ;
142
+ Assert . False ( tree . IsMissing ) ;
134
143
Assert . Equal ( 4 , tree . Count ) ;
135
144
}
136
145
}
@@ -142,6 +151,7 @@ public void CanReadEntryAttributes()
142
151
using ( var repo = new Repository ( path ) )
143
152
{
144
153
var tree = repo . Lookup < Tree > ( sha ) ;
154
+ Assert . False ( tree . IsMissing ) ;
145
155
Assert . Equal ( Mode . NonExecutableFile , tree [ "README" ] . Mode ) ;
146
156
}
147
157
}
@@ -154,6 +164,7 @@ public void CanReadTheTreeData()
154
164
{
155
165
var tree = repo . Lookup < Tree > ( sha ) ;
156
166
Assert . NotNull ( tree ) ;
167
+ Assert . False ( tree . IsMissing ) ;
157
168
}
158
169
}
159
170
@@ -165,6 +176,7 @@ public void TreeDataIsPresent()
165
176
{
166
177
GitObject tree = repo . Lookup ( sha ) ;
167
178
Assert . NotNull ( tree ) ;
179
+ Assert . False ( tree . IsMissing ) ;
168
180
}
169
181
}
170
182
@@ -175,6 +187,7 @@ public void TreeUsesPosixStylePaths()
175
187
{
176
188
/* From a commit tree */
177
189
var commitTree = repo . Lookup < Commit > ( "4c062a6" ) . Tree ;
190
+ Assert . False ( commitTree . IsMissing ) ;
178
191
Assert . NotNull ( commitTree [ "1/branch_file.txt" ] ) ;
179
192
Assert . Null ( commitTree [ "1\\ branch_file.txt" ] ) ;
180
193
}
@@ -188,6 +201,7 @@ public void CanRetrieveTreeEntryPath()
188
201
{
189
202
/* From a commit tree */
190
203
var commitTree = repo . Lookup < Commit > ( "4c062a6" ) . Tree ;
204
+ Assert . False ( commitTree . IsMissing ) ;
191
205
192
206
TreeEntry treeTreeEntry = commitTree [ "1" ] ;
193
207
Assert . Equal ( "1" , treeTreeEntry . Path ) ;
@@ -201,6 +215,7 @@ public void CanRetrieveTreeEntryPath()
201
215
// tree but exposes a complete path through its Path property
202
216
var subTree = treeTreeEntry . Target as Tree ;
203
217
Assert . NotNull ( subTree ) ;
218
+ Assert . False ( subTree . IsMissing ) ;
204
219
TreeEntry anInstance = subTree [ "branch_file.txt" ] ;
205
220
206
221
Assert . NotEqual ( "branch_file.txt" , anInstance . Path ) ;
@@ -239,6 +254,7 @@ public void CanParseSymlinkTreeEntries()
239
254
. Add ( "A symlink" , linkContent , Mode . SymbolicLink ) ;
240
255
241
256
Tree t = repo . ObjectDatabase . CreateTree ( td ) ;
257
+ Assert . False ( t . IsMissing ) ;
242
258
243
259
var te = t [ "A symlink" ] ;
244
260
@@ -248,5 +264,31 @@ public void CanParseSymlinkTreeEntries()
248
264
Assert . Equal ( linkContent , te . Target ) ;
249
265
}
250
266
}
267
+
268
+ [ Fact ]
269
+ public void CanTellIfATreeIsMissing ( )
270
+ {
271
+ var path = SandboxBareTestRepo ( ) ;
272
+
273
+ // Manually delete the objects directory to simulate a partial clone
274
+ Directory . Delete ( Path . Combine ( path , "objects" , "fd" ) , true ) ;
275
+
276
+ using ( var repo = new Repository ( path ) )
277
+ {
278
+ // Look up for the commit that reference the tree which is now missing
279
+ var commit = repo . Lookup < Commit > ( "4a202b346bb0fb0db7eff3cffeb3c70babbd2045" ) ;
280
+
281
+ Assert . True ( commit . Tree . IsMissing ) ;
282
+ Assert . Equal ( "fd093bff70906175335656e6ce6ae05783708765" , commit . Tree . Sha ) ;
283
+ Assert . Throws < NotFoundException > ( ( ) => commit . Tree . Count ) ;
284
+ Assert . Throws < NotFoundException > ( ( ) => commit . Tree . Count ( ) ) ;
285
+ Assert . Throws < NotFoundException > ( ( ) => commit . Tree [ "README" ] ) ;
286
+ Assert . Throws < NotFoundException > ( ( ) => commit . Tree . ToArray ( ) ) ;
287
+ Assert . Throws < NotFoundException > ( ( ) =>
288
+ {
289
+ foreach ( var _ in commit . Tree ) { }
290
+ } ) ;
291
+ }
292
+ }
251
293
}
252
294
}
0 commit comments