Skip to content

Commit c71e656

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 c71e656

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

LibGit2Sharp.Tests/DescribeFixture.cs

Lines changed: 34 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,38 @@ public void CanDescribeACommit()
4950
new DescribeOptions{ AlwaysRenderLongFormat = true }));
5051
}
5152
}
53+
54+
[Fact]
55+
public void CanFollowFirstParent()
56+
{
57+
string path = SandboxStandardTestRepo();
58+
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
59+
var options = new RepositoryOptions { GlobalConfigurationLocation = configPath };
60+
61+
using (var repo = new Repository(path, options))
62+
{
63+
var branch = repo.CreateBranch("branch");
64+
65+
// Make an earlier tag on master
66+
repo.Commit("A", repo.Config.BuildSignature(DateTimeOffset.Now), repo.Config.BuildSignature(DateTimeOffset.Now), new CommitOptions { AllowEmptyCommit = true });
67+
repo.ApplyTag("firstParentTag");
68+
69+
// Make a later tag on branch
70+
repo.Checkout(branch);
71+
repo.Commit("B", repo.Config.BuildSignature(DateTimeOffset.Now), repo.Config.BuildSignature(DateTimeOffset.Now), new CommitOptions { AllowEmptyCommit = true });
72+
repo.ApplyTag("mostRecentTag");
73+
74+
repo.Checkout("master");
75+
repo.Commit("C", repo.Config.BuildSignature(DateTimeOffset.Now), repo.Config.BuildSignature(DateTimeOffset.Now), new CommitOptions { AllowEmptyCommit = true });
76+
repo.Merge(branch, repo.Config.BuildSignature(DateTimeOffset.Now), new MergeOptions() { FastForwardStrategy = FastForwardStrategy.NoFastForward });
77+
78+
// With OnlyFollowFirstParent = false, the most recent tag reachable should be returned
79+
Assert.Equal("mostRecentTag", repo.Describe(repo.Head.Tip, new DescribeOptions { OnlyFollowFirstParent = false, MinimumCommitIdAbbreviatedSize = 0, Strategy = DescribeStrategy.Tags }));
80+
81+
// With OnlyFollowFirstParent = true, the most recent tag on the current branch should be returned
82+
Assert.Equal("firstParentTag", repo.Describe(repo.Head.Tip, new DescribeOptions { OnlyFollowFirstParent = true, MinimumCommitIdAbbreviatedSize = 0, Strategy = DescribeStrategy.Tags }));
83+
84+
}
85+
}
5286
}
5387
}

0 commit comments

Comments
 (0)