File tree 2 files changed +20
-0
lines changed
2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -502,5 +502,20 @@ public void CanReadRepositoryMessage()
502
502
Assert . Equal ( testMessage , repo . Info . Message ) ;
503
503
}
504
504
}
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
+ }
505
520
}
506
521
}
Original file line number Diff line number Diff line change @@ -164,6 +164,11 @@ public Branch Head
164
164
{
165
165
Reference reference = Refs . Head ;
166
166
167
+ if ( reference == null )
168
+ {
169
+ throw new LibGit2SharpException ( "Corrupt repository. The 'HEAD' reference is missing." ) ;
170
+ }
171
+
167
172
if ( reference is SymbolicReference )
168
173
{
169
174
return new Branch ( this , reference ) ;
You can’t perform that action at this time.
0 commit comments