Skip to content

Commit

Permalink
Merge pull request #1190 from ninjeff/ninjeff/describe-offp
Browse files Browse the repository at this point in the history
Support only_follow_first_parent
  • Loading branch information
nulltoken committed Sep 21, 2015
2 parents 8688f10 + 758f428 commit bd4e4c9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
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
{
Expand Down Expand Up @@ -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
Expand Up @@ -644,7 +644,7 @@ public static ConfigurationSafeHandle git_config_snapshot(ConfigurationSafeHandl
Version = 1,
DescribeStrategy = options.Strategy,
MaxCandidatesTags = 10,
OnlyFollowFirstParent = false,
OnlyFollowFirstParent = options.OnlyFollowFirstParent,
ShowCommitOidAsFallback = options.UseCommitIdAsFallback,
};

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

/// <summary>
Expand Down Expand Up @@ -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; }
}
}

0 comments on commit bd4e4c9

Please sign in to comment.