Permalink
Browse files

Throws when HEAD is missing

Fix #351
  • Loading branch information...
1 parent e72a1a4 commit 3e6563007178cfd1cb41cb277aad5b1341dcb66c @nulltoken nulltoken committed Mar 1, 2013
Showing with 20 additions and 0 deletions.
  1. +15 −0 LibGit2Sharp.Tests/RepositoryFixture.cs
  2. +5 −0 LibGit2Sharp/Repository.cs
@@ -502,5 +502,20 @@ public void CanReadRepositoryMessage()
Assert.Equal(testMessage, repo.Info.Message);
}
}
+
+ [Fact]
+ public void AccessingADeletedHeadThrows()
+ {
+ SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
+
+ using (var repo = Repository.Init(scd.DirectoryPath))
+ {
+ Assert.NotNull(repo.Head);
+
+ File.Delete(Path.Combine(repo.Info.Path, "HEAD"));
+
+ Assert.Throws<LibGit2SharpException>(() => repo.Head);
+ }
+ }
}
}
@@ -164,6 +164,11 @@ public Branch Head
{
Reference reference = Refs.Head;
+ if (reference == null)
+ {
+ throw new LibGit2SharpException("Corrupt repository. The 'HEAD' reference is missing.");
+ }
+
if (reference is SymbolicReference)
{
return new Branch(this, reference);

0 comments on commit 3e65630

Please sign in to comment.