Skip to content

Commit b5a6e03

Browse files
authored
Merge pull request #1166 from JakeGinnivan/feature/useBranchName-fix
Ensure calculated pre-release tag matches branch configuration
2 parents 015fb6e + 0c25956 commit b5a6e03

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

src/GitVersionCore.Tests/IntegrationTests/FeatureBranchScenarios.cs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,31 @@ public void ShouldBePossibleToMergeDevelopForALongRunningBranchWhereDevelopAndMa
175175
}
176176
}
177177

178+
[Test]
179+
public void CanUseBranchNameOffAReleaseBranch()
180+
{
181+
var config = new Config
182+
{
183+
Branches =
184+
{
185+
{ "release", new BranchConfig { Tag = "build" } },
186+
{ "feature", new BranchConfig { Tag = "useBranchName" } }
187+
}
188+
};
189+
190+
using (var fixture = new EmptyRepositoryFixture())
191+
{
192+
fixture.MakeACommit();
193+
fixture.BranchTo("release/0.3.0");
194+
fixture.MakeATaggedCommit("v0.3.0-build.1");
195+
fixture.MakeACommit();
196+
fixture.BranchTo("feature/PROJ-1");
197+
fixture.MakeACommit();
198+
199+
fixture.AssertFullSemver(config, "0.3.0-PROJ-1.1+2");
200+
}
201+
}
202+
178203
[TestCase("alpha", "JIRA-123", "alpha")]
179204
[TestCase("useBranchName", "JIRA-123", "JIRA-123")]
180205
[TestCase("alpha.{BranchName}", "JIRA-123", "alpha.JIRA-123")]
@@ -191,12 +216,12 @@ public void ShouldUseConfiguredTag(string tag, string featureName, string preRel
191216
using (var fixture = new EmptyRepositoryFixture())
192217
{
193218
fixture.Repository.MakeATaggedCommit("1.0.0");
194-
var featureBranchName = string.Format("feature/{0}", featureName);
219+
var featureBranchName = $"feature/{featureName}";
195220
fixture.Repository.CreateBranch(featureBranchName);
196221
Commands.Checkout(fixture.Repository, featureBranchName);
197222
fixture.Repository.MakeCommits(5);
198223

199-
var expectedFullSemVer = string.Format("1.0.1-{0}.1+5", preReleaseTagName);
224+
var expectedFullSemVer = $"1.0.1-{preReleaseTagName}.1+5";
200225
fixture.AssertFullSemver(config, expectedFullSemVer);
201226
}
202227
}

src/GitVersionCore.Tests/IntegrationTests/OtherBranchScenarios.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void ShouldNotGetVersionFromFeatureBranchIfNotMerged()
5454
fixture.Repository.MakeACommit();
5555

5656
var version = fixture.GetVersion();
57-
version.SemVer.ShouldBe("1.0.0-unstable.1");
57+
version.SemVer.ShouldBe("1.0.0-alpha.1");
5858
}
5959
}
6060
}

src/GitVersionCore/VersionCalculation/NextVersionCalculator.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ public SemanticVersion FindVersion(GitVersionContext context)
5252
semver.BuildMetaData = metaDataCalculator.Create(baseVersion.BaseVersionSource, context);
5353
}
5454

55-
if (!semver.PreReleaseTag.HasTag() && !string.IsNullOrEmpty(context.Configuration.Tag))
55+
var hasPreReleaseTag = semver.PreReleaseTag.HasTag();
56+
var branchConfigHasPreReleaseTagConfigured = !string.IsNullOrEmpty(context.Configuration.Tag);
57+
var preReleaseTagDoesNotMatchConfiguration = hasPreReleaseTag && branchConfigHasPreReleaseTagConfigured && semver.PreReleaseTag.Name != context.Configuration.Tag;
58+
if (!semver.PreReleaseTag.HasTag() && branchConfigHasPreReleaseTagConfigured || preReleaseTagDoesNotMatchConfiguration)
5659
{
5760
UpdatePreReleaseTag(context, semver, baseVersion.BranchNameOverride);
5861
}

src/GitVersionExe/SpecifiedArgumentRunner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static void Run(Arguments arguments, IFileSystem fileSystem)
4949
string part;
5050
if (!variables.TryGetValue(arguments.ShowVariable, out part))
5151
{
52-
throw new WarningException(string.Format("'{0}' variable does not exist", arguments.ShowVariable));
52+
throw new WarningException($"'{arguments.ShowVariable}' variable does not exist");
5353
}
5454
Console.WriteLine(part);
5555
break;

0 commit comments

Comments
 (0)