diff --git a/src/GitVersion.Core/Extensions/StringExtensions.cs b/src/GitVersion.Core/Extensions/StringExtensions.cs index 5843ee7e81..a8a19a7a4e 100644 --- a/src/GitVersion.Core/Extensions/StringExtensions.cs +++ b/src/GitVersion.Core/Extensions/StringExtensions.cs @@ -102,4 +102,6 @@ public static bool IsEquivalentTo(this string self, string? other) => /// public static bool IsNullOrWhiteSpace([NotNullWhen(false)] this string? value) => string.IsNullOrWhiteSpace(value); + + public static bool IsEmpty([NotNullWhen(false)] this string? value) => string.Empty.Equals(value); } diff --git a/src/GitVersion.Core/PublicAPI.Shipped.txt b/src/GitVersion.Core/PublicAPI.Shipped.txt index bd3d85d7a2..0c9b73897a 100644 --- a/src/GitVersion.Core/PublicAPI.Shipped.txt +++ b/src/GitVersion.Core/PublicAPI.Shipped.txt @@ -1325,6 +1325,7 @@ static GitVersion.Extensions.StringExtensions.IsHelp(this string! singleArgument static GitVersion.Extensions.StringExtensions.IsInit(this string! singleArgument) -> bool static GitVersion.Extensions.StringExtensions.IsNullOrEmpty(this string? value) -> bool static GitVersion.Extensions.StringExtensions.IsNullOrWhiteSpace(this string? value) -> bool +static GitVersion.Extensions.StringExtensions.IsEmpty(this string? value) -> bool static GitVersion.Extensions.StringExtensions.IsSwitch(this string? value, string! switchName) -> bool static GitVersion.Extensions.StringExtensions.IsSwitchArgument(this string? value) -> bool static GitVersion.Extensions.StringExtensions.IsTrue(this string? value) -> bool diff --git a/src/GitVersion.Core/VersionCalculation/NextVersionCalculator.cs b/src/GitVersion.Core/VersionCalculation/NextVersionCalculator.cs index 5aa62d2572..32320acc8d 100644 --- a/src/GitVersion.Core/VersionCalculation/NextVersionCalculator.cs +++ b/src/GitVersion.Core/VersionCalculation/NextVersionCalculator.cs @@ -76,8 +76,12 @@ public NextVersion FindVersion() var hasPreReleaseTag = semver.PreReleaseTag?.HasTag() == true; var tag = configuration.Value.Tag; var branchConfigHasPreReleaseTagConfigured = !tag.IsNullOrEmpty(); - var preReleaseTagDoesNotMatchConfiguration = hasPreReleaseTag && branchConfigHasPreReleaseTagConfigured && semver.PreReleaseTag?.Name != tag; - if (semver.PreReleaseTag?.HasTag() != true && branchConfigHasPreReleaseTagConfigured || preReleaseTagDoesNotMatchConfiguration) + var branchConfigIsMainlineAndHasEmptyPreReleaseTagConfigured = configuration.Value.IsMainline && tag.IsEmpty(); + var preReleaseTagDoesNotMatchConfiguration = hasPreReleaseTag + && (branchConfigHasPreReleaseTagConfigured || branchConfigIsMainlineAndHasEmptyPreReleaseTagConfigured) + && semver.PreReleaseTag?.Name != tag; + var preReleaseTagOnlyInBranchConfig = !hasPreReleaseTag && branchConfigHasPreReleaseTagConfigured; + if (preReleaseTagOnlyInBranchConfig || preReleaseTagDoesNotMatchConfiguration) { UpdatePreReleaseTag(configuration.Value, semver, baseVersion.BranchNameOverride); } @@ -112,6 +116,12 @@ private void UpdatePreReleaseTag(EffectiveConfiguration configuration, SemanticV { var tagToUse = configuration.GetBranchSpecificTag(this.log, Context.CurrentBranch.Name.Friendly, branchNameOverride); + if (configuration.IsMainline && tagToUse.IsEmpty()) + { + semanticVersion.PreReleaseTag = new SemanticVersionPreReleaseTag(tagToUse, null); + return; + } + long? number = null; var lastTag = this.repositoryStore