Skip to content

Support only_follow_first_parent #1190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 21, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions LibGit2Sharp.Tests/DescribeFixture.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Linq;
using LibGit2Sharp.Tests.TestHelpers;
using Xunit;
using System;

namespace LibGit2Sharp.Tests
{
@@ -49,5 +50,35 @@ public void CanDescribeACommit()
new DescribeOptions{ AlwaysRenderLongFormat = true }));
}
}

[Fact]
public void CanFollowFirstParent()
{
string path = SandboxStandardTestRepo();
using (var repo = new Repository(path))
{
var branch = repo.CreateBranch("branch");

// Make an earlier tag on master
repo.Commit("A", Constants.Signature, Constants.Signature, new CommitOptions { AllowEmptyCommit = true });
repo.ApplyTag("firstParentTag");

// Make a later tag on branch
repo.Checkout(branch);
repo.Commit("B", Constants.Signature, Constants.Signature, new CommitOptions { AllowEmptyCommit = true });
repo.ApplyTag("mostRecentTag");

repo.Checkout("master");
repo.Commit("C", Constants.Signature, Constants.Signature, new CommitOptions { AllowEmptyCommit = true });
repo.Merge(branch, Constants.Signature, new MergeOptions() { FastForwardStrategy = FastForwardStrategy.NoFastForward });

// With OnlyFollowFirstParent = false, the most recent tag reachable should be returned
Assert.Equal("mostRecentTag-3-gf17be71", repo.Describe(repo.Head.Tip, new DescribeOptions { OnlyFollowFirstParent = false, Strategy = DescribeStrategy.Tags }));

// With OnlyFollowFirstParent = true, the most recent tag on the current branch should be returned
Assert.Equal("firstParentTag-2-gf17be71", repo.Describe(repo.Head.Tip, new DescribeOptions { OnlyFollowFirstParent = true, Strategy = DescribeStrategy.Tags }));

}
}
}
}
2 changes: 1 addition & 1 deletion LibGit2Sharp/Core/Proxy.cs
Original file line number Diff line number Diff line change
@@ -644,7 +644,7 @@ public static string git_describe_commit(
Version = 1,
DescribeStrategy = options.Strategy,
MaxCandidatesTags = 10,
OnlyFollowFirstParent = false,
OnlyFollowFirstParent = options.OnlyFollowFirstParent,
ShowCommitOidAsFallback = options.UseCommitIdAsFallback,
};

10 changes: 10 additions & 0 deletions LibGit2Sharp/DescribeOptions.cs
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ public DescribeOptions()
{
Strategy = DescribeStrategy.Default;
MinimumCommitIdAbbreviatedSize = 7;
OnlyFollowFirstParent = false;
}

/// <summary>
@@ -54,5 +55,14 @@ public DescribeOptions()
/// </para>
/// </summary>
public bool AlwaysRenderLongFormat { get; set; }

/// <summary>
/// Follow only the first parent commit upon seeing a merge commit.
/// <para>
/// This is useful when you wish to not match tags on branches merged in
/// the history of the target commit.
/// </para>
/// </summary>
public bool OnlyFollowFirstParent { get; set; }
}
}