Skip to content
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
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