@@ -15,6 +15,7 @@ public void CanGetBlobAsText()
15
15
using ( var repo = new Repository ( path ) )
16
16
{
17
17
var blob = repo . Lookup < Blob > ( "a8233120f6ad708f843d861ce2b7228ec4e3dec6" ) ;
18
+ Assert . False ( blob . IsMissing ) ;
18
19
19
20
var text = blob . GetContentText ( ) ;
20
21
@@ -36,6 +37,7 @@ public void CanGetBlobAsFilteredText(string autocrlf, string expectedText)
36
37
repo . Config . Set ( "core.autocrlf" , autocrlf ) ;
37
38
38
39
var blob = repo . Lookup < Blob > ( "a8233120f6ad708f843d861ce2b7228ec4e3dec6" ) ;
40
+ Assert . False ( blob . IsMissing ) ;
39
41
40
42
var text = blob . GetContentText ( new FilteringOptions ( "foo.txt" ) ) ;
41
43
@@ -67,6 +69,7 @@ public void CanGetBlobAsTextWithVariousEncodings(string encodingName, int expect
67
69
var commit = repo . Commit ( "bom" , Constants . Signature , Constants . Signature ) ;
68
70
69
71
var blob = ( Blob ) commit . Tree [ bomFile ] . Target ;
72
+ Assert . False ( blob . IsMissing ) ;
70
73
Assert . Equal ( expectedContentBytes , blob . Size ) ;
71
74
using ( var stream = blob . GetContentStream ( ) )
72
75
{
@@ -92,6 +95,7 @@ public void CanGetBlobSize()
92
95
using ( var repo = new Repository ( path ) )
93
96
{
94
97
var blob = repo . Lookup < Blob > ( "a8233120f6ad708f843d861ce2b7228ec4e3dec6" ) ;
98
+ Assert . False ( blob . IsMissing ) ;
95
99
Assert . Equal ( 10 , blob . Size ) ;
96
100
}
97
101
}
@@ -104,6 +108,7 @@ public void CanLookUpBlob()
104
108
{
105
109
var blob = repo . Lookup < Blob > ( "a8233120f6ad708f843d861ce2b7228ec4e3dec6" ) ;
106
110
Assert . NotNull ( blob ) ;
111
+ Assert . False ( blob . IsMissing ) ;
107
112
}
108
113
}
109
114
@@ -114,6 +119,7 @@ public void CanReadBlobStream()
114
119
using ( var repo = new Repository ( path ) )
115
120
{
116
121
var blob = repo . Lookup < Blob > ( "a8233120f6ad708f843d861ce2b7228ec4e3dec6" ) ;
122
+ Assert . False ( blob . IsMissing ) ;
117
123
118
124
var contentStream = blob . GetContentStream ( ) ;
119
125
Assert . Equal ( blob . Size , contentStream . Length ) ;
@@ -140,6 +146,7 @@ public void CanReadBlobFilteredStream(string autocrlf, string expectedContent)
140
146
repo . Config . Set ( "core.autocrlf" , autocrlf ) ;
141
147
142
148
var blob = repo . Lookup < Blob > ( "a8233120f6ad708f843d861ce2b7228ec4e3dec6" ) ;
149
+ Assert . False ( blob . IsMissing ) ;
143
150
144
151
var contentStream = blob . GetContentStream ( new FilteringOptions ( "foo.txt" ) ) ;
145
152
Assert . Equal ( expectedContent . Length , contentStream . Length ) ;
@@ -164,6 +171,7 @@ public void CanReadBlobFilteredStreamOfUnmodifiedBinary()
164
171
using ( var stream = new MemoryStream ( binaryContent ) )
165
172
{
166
173
Blob blob = repo . ObjectDatabase . CreateBlob ( stream ) ;
174
+ Assert . False ( blob . IsMissing ) ;
167
175
168
176
using ( var filtered = blob . GetContentStream ( new FilteringOptions ( "foo.txt" ) ) )
169
177
{
@@ -196,6 +204,7 @@ public void CanStageAFileGeneratedFromABlobContentStream()
196
204
Assert . Equal ( "baae1fb3760a73481ced1fa03dc15614142c19ef" , entry . Id . Sha ) ;
197
205
198
206
var blob = repo . Lookup < Blob > ( entry . Id . Sha ) ;
207
+ Assert . False ( blob . IsMissing ) ;
199
208
200
209
using ( Stream stream = blob . GetContentStream ( ) )
201
210
using ( Stream file = File . OpenWrite ( Path . Combine ( repo . Info . WorkingDirectory , "small.fromblob.txt" ) ) )
@@ -217,10 +226,35 @@ public void CanTellIfTheBlobContentLooksLikeBinary()
217
226
using ( var repo = new Repository ( path ) )
218
227
{
219
228
var blob = repo . Lookup < Blob > ( "a8233120f6ad708f843d861ce2b7228ec4e3dec6" ) ;
229
+ Assert . False ( blob . IsMissing ) ;
220
230
Assert . False ( blob . IsBinary ) ;
221
231
}
222
232
}
223
233
234
+ [ Fact ]
235
+ public void CanTellIsABlobIsMissing ( )
236
+ {
237
+ string repoPath = SandboxBareTestRepo ( ) ;
238
+
239
+ // Manually delete the objects directory to simulate a partial clone
240
+ Directory . Delete ( Path . Combine ( repoPath , "objects" , "a8" ) , true ) ;
241
+
242
+ using ( var repo = new Repository ( repoPath ) )
243
+ {
244
+ // Look for the commit that reference the blob which is now missing
245
+ var commit = repo . Lookup < Commit > ( "4a202b346bb0fb0db7eff3cffeb3c70babbd2045" ) ;
246
+ var blob = ( Blob ) commit . Tree [ "README" ] . Target ;
247
+
248
+ Assert . Equal ( "a8233120f6ad708f843d861ce2b7228ec4e3dec6" , blob . Sha ) ;
249
+ Assert . NotNull ( blob ) ;
250
+ Assert . True ( blob . IsMissing ) ;
251
+ Assert . Throws < NotFoundException > ( ( ) => blob . Size ) ;
252
+ Assert . Throws < NotFoundException > ( ( ) => blob . IsBinary ) ;
253
+ Assert . Throws < NotFoundException > ( ( ) => blob . GetContentText ( ) ) ;
254
+ Assert . Throws < NotFoundException > ( ( ) => blob . GetContentText ( new FilteringOptions ( "foo.txt" ) ) ) ;
255
+ }
256
+ }
257
+
224
258
private static void SkipIfNotSupported ( string autocrlf )
225
259
{
226
260
InconclusiveIf ( ( ) => autocrlf == "true" && Constants . IsRunningOnUnix , "Non-Windows does not support core.autocrlf = true" ) ;
0 commit comments