Skip to content

Commit 8528d4c

Browse files
committed
Enforce creation of unborn branch test coverage
1 parent 8effe57 commit 8528d4c

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

LibGit2Sharp.Tests/BranchFixture.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,40 @@ public void CanCreateBranch(string name)
4242
}
4343
}
4444

45+
[Fact]
46+
public void CanCreateAnUnbornBranch()
47+
{
48+
string path = CloneStandardTestRepo();
49+
using (var repo = new Repository(path))
50+
{
51+
// No branch named orphan
52+
Assert.Null(repo.Branches["orphan"]);
53+
54+
// HEAD doesn't point to an unborn branch
55+
Assert.False(repo.Info.IsHeadUnborn);
56+
57+
// Let's move the HEAD to this branch to be created
58+
repo.Refs.UpdateTarget("HEAD", "refs/heads/orphan");
59+
Assert.True(repo.Info.IsHeadUnborn);
60+
61+
// The branch still doesn't exist
62+
Assert.Null(repo.Branches["orphan"]);
63+
64+
// Create a commit against HEAD
65+
Commit c = repo.Commit("New initial root commit", Constants.Signature, Constants.Signature);
66+
67+
// Ensure this commit has no parent
68+
Assert.Equal(0, c.Parents.Count());
69+
70+
// The branch now exists...
71+
Branch orphan = repo.Branches["orphan"];
72+
Assert.NotNull(orphan);
73+
74+
// ...and points to that newly created commit
75+
Assert.Equal(c, orphan.Tip);
76+
}
77+
}
78+
4579
[Fact]
4680
public void CanCreateBranchUsingAbbreviatedSha()
4781
{

0 commit comments

Comments
 (0)