Description
Discussed in #2818
Originally posted by anderson-dev August 19, 2021
I'm using mainline versioning mode where my feature branches increment by minor. In my scenario below, pull request version reflects the current version of master rather than the feature branch that the pull request is based on:
master
0.1.0
master -> feature/foo
commit
0.2.0-foo.1
feature/foo -> pull/8/merge
0.1.1-PullRequest00008.1
pull/8/merge -> master
0.2.0 (as expected)
I've tried changing the increment mode for pullrequests in my gitversion.yml branch config but it just changes the increment based on master. How would I tell it to simply take its version from the calculated version of the feature branch for which the pull request was created?
Find an integration test below, XenoLibPackages#CanCalculatePullRequestChanges, that reproduces my issue. I tried 'track-merge-target: true' with no dice.
using GitTools.Testing;
using GitVersion.Core.Tests.Helpers;
using GitVersion.Model.Configuration;
using GitVersion.VersionCalculation;
using LibGit2Sharp;
using NUnit.Framework;
using System.Collections.Generic;
namespace GitVersion.Core.Tests.IntegrationTests
{
public class XenoLibPackages : TestBase
{
private readonly Config config = new Config
{
VersioningMode = VersioningMode.Mainline,
Branches = new Dictionary<string, BranchConfig>
{
{
"feature", new BranchConfig
{
Increment = IncrementStrategy.Minor
}
},
{
"pull-request", new BranchConfig
{
Regex = @"^(pull|pull\-requests|pr)[/-]",
Increment = IncrementStrategy.None,
TrackMergeTarget = true
}
}
}
};
[Test]
public void IncrementFeatureByMinor()
{
using var fixture = new EmptyRepositoryFixture();
fixture.MakeATaggedCommit("0.1.0");
// feature workflow
fixture.BranchTo("feature/foo", "foo");
fixture.MakeACommit();
fixture.AssertFullSemver("0.2.0-foo.1", config);
fixture.MakeACommit();
fixture.AssertFullSemver("0.2.0-foo.2", config);
fixture.Checkout(MainBranch);
fixture.MergeNoFF("feature/foo");
fixture.AssertFullSemver("0.2.0", config);
}
[Test]
public void CanCalculatePullRequestChanges()
{
using var fixture = new EmptyRepositoryFixture();
fixture.Repository.MakeATaggedCommit("0.1.0");
Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("feature/foo"));
fixture.Repository.MakeACommit();
fixture.AssertFullSemver("0.2.0-foo.1", config);
fixture.Repository.CreatePullRequestRef("feature/foo", MainBranch, normalise: true);
fixture.Repository.DumpGraph();
fixture.AssertFullSemver("0.2.0-PullRequest0002.2");
}
}
}