Skip to content

Commit 2b65bff

Browse files
committed
Add test for DescribeOptions.OnlyFollowFirstParent
This commit adds a test that sets up a branch where there is a less recent tag on the same branch and a more recent tag on a merged branch. When Describe is called with OnlyFollowFirstParent = false, the latter tag should be returned, and vice versa.
1 parent 507e3a8 commit 2b65bff

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

LibGit2Sharp.Tests/DescribeFixture.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Linq;
22
using LibGit2Sharp.Tests.TestHelpers;
33
using Xunit;
4+
using System;
45

56
namespace LibGit2Sharp.Tests
67
{
@@ -49,5 +50,35 @@ public void CanDescribeACommit()
4950
new DescribeOptions{ AlwaysRenderLongFormat = true }));
5051
}
5152
}
53+
54+
[Fact]
55+
public void CanFollowFirstParent()
56+
{
57+
string path = SandboxStandardTestRepo();
58+
using (var repo = new Repository(path))
59+
{
60+
var branch = repo.CreateBranch("branch");
61+
62+
// Make an earlier tag on master
63+
repo.Commit("A", Constants.Signature, Constants.Signature, new CommitOptions { AllowEmptyCommit = true });
64+
repo.ApplyTag("firstParentTag");
65+
66+
// Make a later tag on branch
67+
repo.Checkout(branch);
68+
repo.Commit("B", Constants.Signature, Constants.Signature, new CommitOptions { AllowEmptyCommit = true });
69+
repo.ApplyTag("mostRecentTag");
70+
71+
repo.Checkout("master");
72+
repo.Commit("C", Constants.Signature, Constants.Signature, new CommitOptions { AllowEmptyCommit = true });
73+
repo.Merge(branch, Constants.Signature, new MergeOptions() { FastForwardStrategy = FastForwardStrategy.NoFastForward });
74+
75+
// With OnlyFollowFirstParent = false, the most recent tag reachable should be returned
76+
Assert.Equal("mostRecentTag-3-gf17be71", repo.Describe(repo.Head.Tip, new DescribeOptions { OnlyFollowFirstParent = false, Strategy = DescribeStrategy.Tags }));
77+
78+
// With OnlyFollowFirstParent = true, the most recent tag on the current branch should be returned
79+
Assert.Equal("firstParentTag-2-gf17be71", repo.Describe(repo.Head.Tip, new DescribeOptions { OnlyFollowFirstParent = true, Strategy = DescribeStrategy.Tags }));
80+
81+
}
82+
}
5283
}
5384
}

0 commit comments

Comments
 (0)