Skip to content

Commit

Permalink
Merge pull request #2649 from carlwoodhouse/issue-2201
Browse files Browse the repository at this point in the history
use tag branch name even when the branch has no namespace fixes #2201
  • Loading branch information
asbjornu authored Apr 9, 2021
2 parents 2612a47 + 6aae711 commit d4920b2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
34 changes: 34 additions & 0 deletions src/GitVersion.Core.Tests/IntegrationTests/OtherBranchScenarios.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using GitTools.Testing;
using GitVersion.Core.Tests.Helpers;
using GitVersion.Model.Configuration;
using LibGit2Sharp;
using NUnit.Framework;
using Shouldly;
using System.Collections.Generic;

namespace GitVersion.Core.Tests.IntegrationTests
{
Expand Down Expand Up @@ -53,5 +55,37 @@ public void ShouldNotGetVersionFromFeatureBranchIfNotMerged()
var version = fixture.GetVersion();
version.SemVer.ShouldBe("1.0.0-alpha.1");
}

[TestCase("alpha", "JIRA-123", "alpha")]
[TestCase("useBranchName", "JIRA-123", "JIRA-123")]
[TestCase("alpha.{BranchName}", "JIRA-123", "alpha.JIRA-123")]
public void TagIsBranchNameForBranchesWithoutPrefixedBranchName(string tag, string branchName, string preReleaseTagName)
{
var config = new Config
{
Branches =
{
{
"other",
new BranchConfig
{
Increment = IncrementStrategy.Patch,
Regex = ".*",
SourceBranches = new HashSet<string>(),
Tag = tag
}
}
}
};

using var fixture = new EmptyRepositoryFixture();
fixture.Repository.MakeATaggedCommit("1.0.0");
fixture.Repository.CreateBranch(branchName);
Commands.Checkout(fixture.Repository, branchName);
fixture.Repository.MakeCommits(5);

var expectedFullSemVer = $"1.0.1-{preReleaseTagName}.1+5";
fixture.AssertFullSemver(expectedFullSemVer, config);
}
}
}
3 changes: 2 additions & 1 deletion src/GitVersion.Core/Configuration/ConfigExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ public static string GetBranchSpecificTag(this EffectiveConfiguration configurat
var branchName = branchNameOverride ?? branchFriendlyName;
if (!string.IsNullOrWhiteSpace(configuration.BranchPrefixToTrim))
{
branchName = branchName.RegexReplace(configuration.BranchPrefixToTrim, string.Empty, RegexOptions.IgnoreCase);
var branchNameTrimmed = branchName.RegexReplace(configuration.BranchPrefixToTrim, string.Empty, RegexOptions.IgnoreCase);
branchName = string.IsNullOrEmpty(branchNameTrimmed) ? branchName : branchNameTrimmed;
}
branchName = branchName.RegexReplace("[^a-zA-Z0-9-]", "-");

Expand Down

0 comments on commit d4920b2

Please sign in to comment.