Skip to content

Ensure calculated pre-release tag matches branch configuration #1166

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
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
Expand Up @@ -175,6 +175,31 @@ public void ShouldBePossibleToMergeDevelopForALongRunningBranchWhereDevelopAndMa
}
}

[Test]
public void CanUseBranchNameOffAReleaseBranch()
{
var config = new Config
{
Branches =
{
{ "release", new BranchConfig { Tag = "build" } },
{ "feature", new BranchConfig { Tag = "useBranchName" } }
}
};

using (var fixture = new EmptyRepositoryFixture())
{
fixture.MakeACommit();
fixture.BranchTo("release/0.3.0");
fixture.MakeATaggedCommit("v0.3.0-build.1");
fixture.MakeACommit();
fixture.BranchTo("feature/PROJ-1");
fixture.MakeACommit();

fixture.AssertFullSemver(config, "0.3.0-PROJ-1.1+2");
}
}

[TestCase("alpha", "JIRA-123", "alpha")]
[TestCase("useBranchName", "JIRA-123", "JIRA-123")]
[TestCase("alpha.{BranchName}", "JIRA-123", "alpha.JIRA-123")]
Expand All @@ -191,12 +216,12 @@ public void ShouldUseConfiguredTag(string tag, string featureName, string preRel
using (var fixture = new EmptyRepositoryFixture())
{
fixture.Repository.MakeATaggedCommit("1.0.0");
var featureBranchName = string.Format("feature/{0}", featureName);
var featureBranchName = $"feature/{featureName}";
fixture.Repository.CreateBranch(featureBranchName);
Commands.Checkout(fixture.Repository, featureBranchName);
fixture.Repository.MakeCommits(5);

var expectedFullSemVer = string.Format("1.0.1-{0}.1+5", preReleaseTagName);
var expectedFullSemVer = $"1.0.1-{preReleaseTagName}.1+5";
fixture.AssertFullSemver(config, expectedFullSemVer);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void ShouldNotGetVersionFromFeatureBranchIfNotMerged()
fixture.Repository.MakeACommit();

var version = fixture.GetVersion();
version.SemVer.ShouldBe("1.0.0-unstable.1");
version.SemVer.ShouldBe("1.0.0-alpha.1");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using GitTools;
using GitTools.Testing;
using GitTools.Testing;
using GitVersion;
using GitVersionCore.Tests;
using LibGit2Sharp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ public SemanticVersion FindVersion(GitVersionContext context)
semver.BuildMetaData = metaDataCalculator.Create(baseVersion.BaseVersionSource, context);
}

if (!semver.PreReleaseTag.HasTag() && !string.IsNullOrEmpty(context.Configuration.Tag))
var hasPreReleaseTag = semver.PreReleaseTag.HasTag();
var branchConfigHasPreReleaseTagConfigured = !string.IsNullOrEmpty(context.Configuration.Tag);
var preReleaseTagDoesNotMatchConfiguration = hasPreReleaseTag && branchConfigHasPreReleaseTagConfigured && semver.PreReleaseTag.Name != context.Configuration.Tag;
if (!semver.PreReleaseTag.HasTag() && branchConfigHasPreReleaseTagConfigured || preReleaseTagDoesNotMatchConfiguration)
{
UpdatePreReleaseTag(context, semver, baseVersion.BranchNameOverride);
}
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersionExe/SpecifiedArgumentRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static void Run(Arguments arguments, IFileSystem fileSystem)
string part;
if (!variables.TryGetValue(arguments.ShowVariable, out part))
{
throw new WarningException(string.Format("'{0}' variable does not exist", arguments.ShowVariable));
throw new WarningException($"'{arguments.ShowVariable}' variable does not exist");
}
Console.WriteLine(part);
break;
Expand Down