|
1 | 1 | using System.Linq;
|
2 | 2 | using LibGit2Sharp.Tests.TestHelpers;
|
3 | 3 | using Xunit;
|
| 4 | +using System; |
4 | 5 |
|
5 | 6 | namespace LibGit2Sharp.Tests
|
6 | 7 | {
|
@@ -49,5 +50,35 @@ public void CanDescribeACommit()
|
49 | 50 | new DescribeOptions{ AlwaysRenderLongFormat = true }));
|
50 | 51 | }
|
51 | 52 | }
|
| 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 | + } |
52 | 83 | }
|
53 | 84 | }
|
0 commit comments