File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -502,5 +502,20 @@ public void CanReadRepositoryMessage()
502502 Assert . Equal ( testMessage , repo . Info . Message ) ;
503503 }
504504 }
505+
506+ [ Fact ]
507+ public void AccessingADeletedHeadThrows ( )
508+ {
509+ SelfCleaningDirectory scd = BuildSelfCleaningDirectory ( ) ;
510+
511+ using ( var repo = Repository . Init ( scd . DirectoryPath ) )
512+ {
513+ Assert . NotNull ( repo . Head ) ;
514+
515+ File . Delete ( Path . Combine ( repo . Info . Path , "HEAD" ) ) ;
516+
517+ Assert . Throws < LibGit2SharpException > ( ( ) => repo . Head ) ;
518+ }
519+ }
505520 }
506521}
Original file line number Diff line number Diff line change @@ -164,6 +164,11 @@ public Branch Head
164164 {
165165 Reference reference = Refs . Head ;
166166
167+ if ( reference == null )
168+ {
169+ throw new LibGit2SharpException ( "Corrupt repository. The 'HEAD' reference is missing." ) ;
170+ }
171+
167172 if ( reference is SymbolicReference )
168173 {
169174 return new Branch ( this , reference ) ;
You can’t perform that action at this time.
0 commit comments