Skip to content
New issue

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

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

Already on GitHub? # to your account

Ignore version numbers in branch names that are not release branches. #1541

Merged
merged 13 commits into from
Feb 15, 2019
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using GitTools.Testing;
using GitTools.Testing;
using GitVersionCore.Tests;
using LibGit2Sharp;
using NUnit.Framework;
Expand All @@ -15,10 +15,10 @@ public void CanTakeVersionFromReleaseBranch()
const string TaggedVersion = "1.0.3";
fixture.Repository.MakeATaggedCommit(TaggedVersion);
fixture.Repository.MakeCommits(5);
fixture.Repository.CreateBranch("alpha-2.0.0");
Commands.Checkout(fixture.Repository, "alpha-2.0.0");
fixture.Repository.CreateBranch("release/beta-2.0.0");
Commands.Checkout(fixture.Repository, "release/beta-2.0.0");

fixture.AssertFullSemver("2.0.0-alpha.1+0");
fixture.AssertFullSemver("2.0.0-beta.1+0");
}
}

Expand Down Expand Up @@ -57,4 +57,4 @@ public void ShouldNotGetVersionFromFeatureBranchIfNotMerged()
version.SemVer.ShouldBe("1.0.0-alpha.1");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
namespace GitVersionCore.Tests.IntegrationTests
{
using System.Collections.Generic;
using System.Linq;

using GitTools.Testing;

using GitVersion;

using GitVersionCore.Tests;

using LibGit2Sharp;

using NUnit.Framework;

[TestFixture]
public class VersionInCurrentBranchNameScenarios : TestBase
{
[Test]
public void TakesVersionFromNameOfReleaseBranch()
{
using (var fixture = new BaseGitFlowRepositoryFixture("1.0.0"))
{
fixture.BranchTo("release/2.0.0");

fixture.AssertFullSemver("2.0.0-beta.1+0");
}
}

[Test]
public void DoesNotTakeVersionFromNameOfNonReleaseBranch()
{
using (var fixture = new BaseGitFlowRepositoryFixture("1.0.0"))
{
fixture.BranchTo("feature/upgrade-power-level-to-9000.0.1");

fixture.AssertFullSemver("1.1.0-upgrade-power-level-to-9000-0-1.1+1");
}
}

[Test]
public void TakesVersionFromNameOfBranchThatIsReleaseByConfig()
{
var config = new Config
{
Branches = new Dictionary<string, BranchConfig> { { "support", new BranchConfig { IsReleaseBranch = true } } }
};

using (var fixture = new BaseGitFlowRepositoryFixture("1.0.0"))
{
fixture.BranchTo("support/2.0.0");

fixture.AssertFullSemver(config, "2.0.0+1");
}
}

[Test]
public void TakesVersionFromNameOfRemoteReleaseBranchInOrigin()
{
using (var fixture = new RemoteRepositoryFixture())
{
fixture.BranchTo("release/2.0.0");
fixture.MakeACommit();
Commands.Fetch((Repository)fixture.LocalRepositoryFixture.Repository, fixture.LocalRepositoryFixture.Repository.Network.Remotes.First().Name, new string[0], new FetchOptions(), null);

fixture.LocalRepositoryFixture.Checkout("origin/release/2.0.0");

fixture.LocalRepositoryFixture.AssertFullSemver("2.0.0-beta.1+1");
}
}

[Test]
public void DoesNotTakeVersionFromNameOfRemoteReleaseBranchInCustomRemote()
{
using (var fixture = new RemoteRepositoryFixture())
{
fixture.LocalRepositoryFixture.Repository.Network.Remotes.Rename("origin", "upstream");
fixture.BranchTo("release/2.0.0");
fixture.MakeACommit();
Commands.Fetch((Repository)fixture.LocalRepositoryFixture.Repository, fixture.LocalRepositoryFixture.Repository.Network.Remotes.First().Name, new string[0], new FetchOptions(), null);

fixture.LocalRepositoryFixture.Checkout("upstream/release/2.0.0");

fixture.LocalRepositoryFixture.AssertFullSemver("0.1.0-beta.1+5");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
namespace GitVersionCore.Tests.IntegrationTests
{
using System.Collections.Generic;
using System.Linq;

using GitTools.Testing;

using GitVersion;

using GitVersionCore.Tests;

using LibGit2Sharp;

using NUnit.Framework;

[TestFixture]
public class VersionInMergedBranchNameScenarios : TestBase
{
[Test]
public void TakesVersionFromNameOfReleaseBranch()
{
using (var fixture = new BaseGitFlowRepositoryFixture("1.0.0"))
{
fixture.CreateAndMergeBranchIntoDevelop("release/2.0.0");

fixture.AssertFullSemver("2.1.0-alpha.2");
}
}

[Test]
public void DoesNotTakeVersionFromNameOfNonReleaseBranch()
{
using (var fixture = new BaseGitFlowRepositoryFixture("1.0.0"))
{
fixture.CreateAndMergeBranchIntoDevelop("pull-request/improved-by-upgrading-some-lib-to-4.5.6");
fixture.CreateAndMergeBranchIntoDevelop("hotfix/downgrade-some-lib-to-3.2.1-to-avoid-breaking-changes");

fixture.AssertFullSemver("1.1.0-alpha.5");
}
}

[Test]
public void TakesVersionFromNameOfBranchThatIsReleaseByConfig()
{
var config = new Config
{
Branches = new Dictionary<string, BranchConfig> { { "support", new BranchConfig { IsReleaseBranch = true } } }
};

using (var fixture = new BaseGitFlowRepositoryFixture("1.0.0"))
{
fixture.CreateAndMergeBranchIntoDevelop("support/2.0.0");

fixture.AssertFullSemver(config, "2.1.0-alpha.2");
}
}

[Test]
public void TakesVersionFromNameOfRemoteReleaseBranchInOrigin()
{
using (var fixture = new RemoteRepositoryFixture())
{
fixture.BranchTo("release/2.0.0");
fixture.MakeACommit();
Commands.Fetch((Repository)fixture.LocalRepositoryFixture.Repository, fixture.LocalRepositoryFixture.Repository.Network.Remotes.First().Name, new string[0], new FetchOptions(), null);

fixture.LocalRepositoryFixture.MergeNoFF("origin/release/2.0.0");

fixture.LocalRepositoryFixture.AssertFullSemver("2.0.0+0");
}
}

[Test]
public void DoesNotTakeVersionFromNameOfRemoteReleaseBranchInCustomRemote()
{
using (var fixture = new RemoteRepositoryFixture())
{
fixture.LocalRepositoryFixture.Repository.Network.Remotes.Rename("origin", "upstream");
fixture.BranchTo("release/2.0.0");
fixture.MakeACommit();
Commands.Fetch((Repository)fixture.LocalRepositoryFixture.Repository, fixture.LocalRepositoryFixture.Repository.Network.Remotes.First().Name, new string[0], new FetchOptions(), null);

fixture.LocalRepositoryFixture.MergeNoFF("upstream/release/2.0.0");

fixture.LocalRepositoryFixture.AssertFullSemver("0.1.0+6");
}
}
}

internal static class BaseGitFlowRepositoryFixtureExtensions
{
public static void CreateAndMergeBranchIntoDevelop(this BaseGitFlowRepositoryFixture fixture, string branchName)
{
fixture.BranchTo(branchName);
fixture.MakeACommit();
fixture.Checkout("develop");
fixture.MergeNoFF(branchName);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
namespace GitVersionCore.Tests.VersionCalculation.Strategies
namespace GitVersionCore.Tests.VersionCalculation.Strategies
{
using System.Collections.Generic;
using System.Linq;

using GitVersion;
using GitVersion.VersionCalculation.BaseVersionCalculators;
using LibGit2Sharp;
using NUnit.Framework;
Expand All @@ -19,7 +21,7 @@ public void ShouldNotAllowIncrementOfVersion()
{
Head = new MockBranch("master") { new MockCommit
{
MessageEx = "Merge branch 'hotfix-0.1.5'",
MessageEx = "Merge branch 'release-0.1.5'",
ParentsEx = GetParents(true)
} }
}).Build();
Expand All @@ -30,38 +32,22 @@ public void ShouldNotAllowIncrementOfVersion()
baseVersion.ShouldIncrement.ShouldBe(false);
}

[TestCase("Merge branch 'hotfix-0.1.5'", false, null)]
[TestCase("Merge branch 'develop' of github.com:Particular/NServiceBus into develop", true, null)]
[TestCase("Merge branch '4.0.3'", true, "4.0.3")] //TODO: possible make it a config option to support this
[TestCase("Merge branch 'release-10.10.50'", true, "10.10.50")]
[TestCase("Merge branch 's'", true, null)] // Must start with a number
[TestCase("Merge tag '10.10.50'", true, "10.10.50")]
[TestCase("Merge branch 'release-0.2.0'", true, "0.2.0")]
[TestCase("Merge branch 'Release-0.2.0'", true, "0.2.0")]
[TestCase("Merge branch 'Release/0.2.0'", true, "0.2.0")]
[TestCase("Merge branch 'hotfix-4.6.6' into support-4.6", true, "4.6.6")]
[TestCase("Merge branch 'hotfix-10.10.50'", true, "10.10.50")]
[TestCase("Merge branch 'Hotfix-10.10.50'", true, "10.10.50")]
[TestCase("Merge branch 'Hotfix/10.10.50'", true, "10.10.50")]
[TestCase("Merge branch 'hotfix-0.1.5'", true, "0.1.5")]
[TestCase("Merge branch 'hotfix-4.2.2' into support-4.2", true, "4.2.2")]
[TestCase("Merge branch 'somebranch' into release-3.0.0", true, null)]
[TestCase("Merge branch 'hotfix-0.1.5'\n\nRelates to: TicketId", true, "0.1.5")]
[TestCase("Merge branch 'alpha-0.1.5'", true, "0.1.5")]
[TestCase("Merge pull request #165 from Particular/release-1.0.0", true, "1.0.0")]
[TestCase("Merge pull request #95 from Particular/issue-94", false, null)]
[TestCase("Merge pull request #165 in Particular/release-1.0.0", true, "1.0.0")]
[TestCase("Merge pull request #95 in Particular/issue-94", true, null)]
[TestCase("Merge pull request #95 in Particular/issue-94", false, null)]
[TestCase("Merge pull request #64 from arledesma/feature-VS2013_3rd_party_test_framework_support", true, null)]
[TestCase("Merge pull request #500 in FOO/bar from Particular/release-1.0.0 to develop)", true, "1.0.0")]
[TestCase("Merge pull request #500 in FOO/bar from feature/new-service to develop)", true, null)]
[TestCase("Merge branch 'releases-0.2.0'", true, "0.2.0")]
[TestCase("Merge branch 'Releases-0.2.0'", true, "0.2.0")]
[TestCase("Merge branch 'Releases/0.2.0'", true, "0.2.0")]
[TestCase("Merge branch 'release-4.6.6' into support-4.6", true, "4.6.6")]
[TestCase("Merge branch 'release-10.10.50'", true, "10.10.50")]
[TestCase("Merge branch 'release-0.1.5'\n\nRelates to: TicketId", true, "0.1.5")]
[TestCase("Finish Release-0.12.0", true, "0.12.0")] //Support Syntevo SmartGit/Hg's Gitflow merge commit messages for finishing a 'Release' branch
[TestCase("Finish 0.14.1", true, "0.14.1")] //Support Syntevo SmartGit/Hg's Gitflow merge commit messages for finishing a 'Hotfix' branch
[TestCase("Merge branch 'Release-v0.2.0'", true, "0.2.0")]
[TestCase("Merge branch 'Release-v2.2'", true, "2.2.0")]
[TestCase("Merge remote-tracking branch 'origin/release/0.8.0' into develop/master", true, "0.8.0")]
public void AssertMergeMessage(string message, bool isMergeCommit, string expectedVersion)
[TestCase("Merge remote-tracking branch 'refs/remotes/origin/release/2.0.0'", true, "2.0.0")]
public void TakesVersionFromMergeOfReleaseBranch(string message, bool isMergeCommit, string expectedVersion)
{
var parents = GetParents(isMergeCommit);
AssertMergeMessage(message, expectedVersion, parents);
Expand All @@ -74,6 +60,56 @@ public void AssertMergeMessage(string message, bool isMergeCommit, string expect
AssertMergeMessage(message + "\n ", expectedVersion, parents);
}

[TestCase("Merge branch 'hotfix-0.1.5'", false)]
[TestCase("Merge branch 'develop' of github.com:Particular/NServiceBus into develop", true)]
[TestCase("Merge branch '4.0.3'", true)]
[TestCase("Merge branch 's'", true)]
[TestCase("Merge tag '10.10.50'", true)]
[TestCase("Merge branch 'hotfix-4.6.6' into support-4.6", true)]
[TestCase("Merge branch 'hotfix-10.10.50'", true)]
[TestCase("Merge branch 'Hotfix-10.10.50'", true)]
[TestCase("Merge branch 'Hotfix/10.10.50'", true)]
[TestCase("Merge branch 'hotfix-0.1.5'", true)]
[TestCase("Merge branch 'hotfix-4.2.2' into support-4.2", true)]
[TestCase("Merge branch 'somebranch' into release-3.0.0", true)]
[TestCase("Merge branch 'hotfix-0.1.5'\n\nRelates to: TicketId", true)]
[TestCase("Merge branch 'alpha-0.1.5'", true)]
[TestCase("Merge pull request #95 from Particular/issue-94", false)]
[TestCase("Merge pull request #95 in Particular/issue-94", true)]
[TestCase("Merge pull request #95 in Particular/issue-94", false)]
[TestCase("Merge pull request #64 from arledesma/feature-VS2013_3rd_party_test_framework_support", true)]
[TestCase("Merge pull request #500 in FOO/bar from Particular/release-1.0.0 to develop)", true)]
[TestCase("Merge pull request #500 in FOO/bar from feature/new-service to develop)", true)]
[TestCase("Finish 0.14.1", true)] // Don't support Syntevo SmartGit/Hg's Gitflow merge commit messages for finishing a 'Hotfix' branch
public void ShouldNotTakeVersionFromMergeOfNonReleaseBranch(string message, bool isMergeCommit)
{
var parents = GetParents(isMergeCommit);
AssertMergeMessage(message, null, parents);
AssertMergeMessage(message + " ", null, parents);
AssertMergeMessage(message + "\r ", null, parents);
AssertMergeMessage(message + "\r", null, parents);
AssertMergeMessage(message + "\r\n", null, parents);
AssertMergeMessage(message + "\r\n ", null, parents);
AssertMergeMessage(message + "\n", null, parents);
AssertMergeMessage(message + "\n ", null, parents);
}

[TestCase("Merge pull request #165 from Particular/release-1.0.0", true)]
[TestCase("Merge pull request #165 in Particular/release-1.0.0", true)]
[TestCase("Merge pull request #500 in FOO/bar from Particular/release-1.0.0 to develop)", true)]
public void ShouldNotTakeVersionFromMergeOfReleaseBranchWithRemoteOtherThanOrigin(string message, bool isMergeCommit)
{
var parents = GetParents(isMergeCommit);
AssertMergeMessage(message, null, parents);
AssertMergeMessage(message + " ", null, parents);
AssertMergeMessage(message + "\r ", null, parents);
AssertMergeMessage(message + "\r", null, parents);
AssertMergeMessage(message + "\r\n", null, parents);
AssertMergeMessage(message + "\r\n ", null, parents);
AssertMergeMessage(message + "\n", null, parents);
AssertMergeMessage(message + "\n ", null, parents);
}

[TestCase(@"Merge pull request #1 in FOO/bar from feature/ISSUE-1 to develop

* commit '38560a7eed06e8d3f3f1aaf091befcdf8bf50fea':
Expand All @@ -89,14 +125,26 @@ Another commit message
[TestCase(@"Merge branch 'master' of http://172.16.3.10:8082/r/asu_tk/p_sd")]
[TestCase(@"Merge branch 'master' of http://212.248.89.56:8082/r/asu_tk/p_sd")]
[TestCase(@"Merge branch 'DEMO' of http://10.10.10.121/gitlab/mtolland/orcid into DEMO")]
public void MergeMessagesThatIsNotRelatedToGitVersion(string commitMessage)
public void ShouldNotTakeVersionFromUnrelatedMerge(string commitMessage)
{
var parents = GetParents(true);

AssertMergeMessage(commitMessage, null, parents);
}

static void AssertMergeMessage(string message, string expectedVersion, List<Commit> parents)
[TestCase("Merge branch 'support/0.2.0'", "support", "0.2.0")]
[TestCase("Merge branch 'support/0.2.0'", null, null)]
[TestCase("Merge branch 'release/2.0.0'", null, "2.0.0")]
public void TakesVersionFromMergeOfConfiguredReleaseBranch(string message, string releaseBranch, string expectedVersion)
{
var config = new Config();
if (releaseBranch != null) config.Branches[releaseBranch] = new BranchConfig { IsReleaseBranch = true };
var parents = GetParents(true);

AssertMergeMessage(message, expectedVersion, parents, config);
}

static void AssertMergeMessage(string message, string expectedVersion, List<Commit> parents, Config config = null)
{
var commit = new MockCommit
{
Expand All @@ -105,6 +153,7 @@ static void AssertMergeMessage(string message, string expectedVersion, List<Comm
};

var context = new GitVersionContextBuilder()
.WithConfig(config ?? new Config())
.WithRepository(new MockRepository
{
Head = new MockBranch("master")
Expand Down Expand Up @@ -145,4 +194,4 @@ static List<Commit> GetParents(bool isMergeCommit)
};
}
}
}
}
Loading