10000 Throws when HEAD is missing · mm201/libgit2sharp@3e65630 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3e65630

Browse files
committed
Throws when HEAD is missing
Fix libgit2#351
1 parent e72a1a4 commit 3e65630

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

LibGit2Sharp.Tests/RepositoryFixture.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

LibGit2Sharp/Repository.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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);

0 commit comments

Comments
 (0)
0