@@ -15,6 +15,7 @@ public void CanGetBlobAsText()
1515 using ( var repo = new Repository ( path ) )
1616 {
1717 var blob = repo . Lookup < Blob > ( "a8233120f6ad708f843d861ce2b7228ec4e3dec6" ) ;
18+ Assert . False ( blob . IsMissing ) ;
1819
1920 var text = blob . GetContentText ( ) ;
2021
@@ -36,6 +37,7 @@ public void CanGetBlobAsFilteredText(string autocrlf, string expectedText)
3637 repo . Config . Set ( "core.autocrlf" , autocrlf ) ;
3738
3839 var blob = repo . Lookup < Blob > ( "a8233120f6ad708f843d861ce2b7228ec4e3dec6" ) ;
40+ Assert . False ( blob . IsMissing ) ;
3941
4042 var text = blob . GetContentText ( new FilteringOptions ( "foo.txt" ) ) ;
4143
@@ -67,6 +69,7 @@ public void CanGetBlobAsTextWithVariousEncodings(string encodingName, int expect
6769 var commit = repo . Commit ( "bom" , Constants . Signature , Constants . Signature ) ;
6870
6971 var blob = ( Blob ) commit . Tree [ bomFile ] . Target ;
72+ Assert . False ( blob . IsMissing ) ;
7073 Assert . Equal ( expectedContentBytes , blob . Size ) ;
7174 using ( var stream = blob . GetContentStream ( ) )
7275 {
@@ -92,6 +95,7 @@ public void CanGetBlobSize()
9295 using ( var repo = new Repository ( path ) )
9396 {
9497 var blob = repo . Lookup < Blob > ( "a8233120f6ad708f843d861ce2b7228ec4e3dec6" ) ;
98+ Assert . False ( blob . IsMissing ) ;
9599 Assert . Equal ( 10 , blob . Size ) ;
96100 }
97101 }
@@ -104,6 +108,7 @@ public void CanLookUpBlob()
104108 {
105109 var blob = repo . Lookup < Blob > ( "a8233120f6ad708f843d861ce2b7228ec4e3dec6" ) ;
106110 Assert . NotNull ( blob ) ;
111+ Assert . False ( blob . IsMissing ) ;
107112 }
108113 }
109114
@@ -114,6 +119,7 @@ public void CanReadBlobStream()
114119 using ( var repo = new Repository ( path ) )
115120 {
116121 var blob = repo . Lookup < Blob > ( "a8233120f6ad708f843d861ce2b7228ec4e3dec6" ) ;
122+ Assert . False ( blob . IsMissing ) ;
117123
118124 var contentStream = blob . GetContentStream ( ) ;
119125 Assert . Equal ( blob . Size , contentStream . Length ) ;
@@ -140,6 +146,7 @@ public void CanReadBlobFilteredStream(string autocrlf, string expectedContent)
140146 repo . Config . Set ( "core.autocrlf" , autocrlf ) ;
141147
142148 var blob = repo . Lookup < Blob > ( "a8233120f6ad708f843d861ce2b7228ec4e3dec6" ) ;
149+ Assert . False ( blob . IsMissing ) ;
143150
144151 var contentStream = blob . GetContentStream ( new FilteringOptions ( "foo.txt" ) ) ;
145152 Assert . Equal ( expectedContent . Length , contentStream . Length ) ;
@@ -164,6 +171,7 @@ public void CanReadBlobFilteredStreamOfUnmodifiedBinary()
164171 using ( var stream = new MemoryStream ( binaryContent ) )
165172 {
166173 Blob blob = repo . ObjectDatabase . CreateBlob ( stream ) ;
174+ Assert . False ( blob . IsMissing ) ;
167175
168176 using ( var filtered = blob . GetContentStream ( new FilteringOptions ( "foo.txt" ) ) )
169177 {
@@ -196,6 +204,7 @@ public void CanStageAFileGeneratedFromABlobContentStream()
196204 Assert . Equal ( "baae1fb3760a73481ced1fa03dc15614142c19ef" , entry . Id . Sha ) ;
197205
198206 var blob = repo . Lookup < Blob > ( entry . Id . Sha ) ;
207+ Assert . False ( blob . IsMissing ) ;
199208
200209 using ( Stream stream = blob . GetContentStream ( ) )
201210 using ( Stream file = File . OpenWrite ( Path . Combine ( repo . Info . WorkingDirectory , "small.fromblob.txt" ) ) )
@@ -217,10 +226,35 @@ public void CanTellIfTheBlobContentLooksLikeBinary()
217226 using ( var repo = new Repository ( path ) )
218227 {
219228 var blob = repo . Lookup < Blob > ( "a8233120f6ad708f843d861ce2b7228ec4e3dec6" ) ;
229+ Assert . False ( blob . IsMissing ) ;
220230 Assert . False ( blob . IsBinary ) ;
221231 }
222232 }
223233
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+
224258 private static void SkipIfNotSupported ( string autocrlf )
225259 {
226260 InconclusiveIf ( ( ) => autocrlf == "true" && Constants . IsRunningOnUnix , "Non-Windows does not support core.autocrlf = true" ) ;
0 commit comments