Skip to content

Commit d4920b2

Browse files
authored
Merge pull request #2649 from carlwoodhouse/issue-2201
use tag branch name even when the branch has no namespace fixes #2201
2 parents 2612a47 + 6aae711 commit d4920b2

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/GitVersion.Core.Tests/IntegrationTests/OtherBranchScenarios.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using GitTools.Testing;
22
using GitVersion.Core.Tests.Helpers;
3+
using GitVersion.Model.Configuration;
34
using LibGit2Sharp;
45
using NUnit.Framework;
56
using Shouldly;
7+
using System.Collections.Generic;
68

79
namespace GitVersion.Core.Tests.IntegrationTests
810
{
@@ -53,5 +55,37 @@ public void ShouldNotGetVersionFromFeatureBranchIfNotMerged()
5355
var version = fixture.GetVersion();
5456
version.SemVer.ShouldBe("1.0.0-alpha.1");
5557
}
58+
59+
[TestCase("alpha", "JIRA-123", "alpha")]
60+
[TestCase("useBranchName", "JIRA-123", "JIRA-123")]
61+
[TestCase("alpha.{BranchName}", "JIRA-123", "alpha.JIRA-123")]
62+
public void TagIsBranchNameForBranchesWithoutPrefixedBranchName(string tag, string branchName, string preReleaseTagName)
63+
{
64+
var config = new Config
65+
{
66+
Branches =
67+
{
68+
{
69+
"other",
70+
new BranchConfig
71+
{
72+
Increment = IncrementStrategy.Patch,
73+
Regex = ".*",
74+
SourceBranches = new HashSet<string>(),
75+
Tag = tag
76+
}
77+
}
78+
}
79+
};
80+
81+
using var fixture = new EmptyRepositoryFixture();
82+
fixture.Repository.MakeATaggedCommit("1.0.0");
83+
fixture.Repository.CreateBranch(branchName);
84+
Commands.Checkout(fixture.Repository, branchName);
85+
fixture.Repository.MakeCommits(5);
86+
87+
var expectedFullSemVer = $"1.0.1-{preReleaseTagName}.1+5";
88+
fixture.AssertFullSemver(expectedFullSemVer, config);
89+
}
5690
}
5791
}

src/GitVersion.Core/Configuration/ConfigExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ public static string GetBranchSpecificTag(this EffectiveConfiguration configurat
131131
var branchName = branchNameOverride ?? branchFriendlyName;
132132
if (!string.IsNullOrWhiteSpace(configuration.BranchPrefixToTrim))
133133
{
134-
branchName = branchName.RegexReplace(configuration.BranchPrefixToTrim, string.Empty, RegexOptions.IgnoreCase);
134+
var branchNameTrimmed = branchName.RegexReplace(configuration.BranchPrefixToTrim, string.Empty, RegexOptions.IgnoreCase);
135+
branchName = string.IsNullOrEmpty(branchNameTrimmed) ? branchName : branchNameTrimmed;
135136
}
136137
branchName = branchName.RegexReplace("[^a-zA-Z0-9-]", "-");
137138

0 commit comments

Comments
 (0)