Skip to content

Commit 7576b44

Browse files
Enrique Raso Barberoasbjornu
authored andcommitted
Detect if branchConfig is Mainline and has empty prerelease tag configured to update prerelease tag in semver
1 parent 544d4d1 commit 7576b44

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

src/GitVersion.Core/Extensions/StringExtensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,6 @@ public static bool IsEquivalentTo(this string self, string? other) =>
102102

103103
/// <inheritdoc cref="string.IsNullOrWhiteSpace"/>
104104
public static bool IsNullOrWhiteSpace([NotNullWhen(false)] this string? value) => string.IsNullOrWhiteSpace(value);
105+
106+
public static bool IsEmpty([NotNullWhen(false)] this string? value) => string.Empty.Equals(value);
105107
}

src/GitVersion.Core/PublicAPI.Shipped.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,6 +1325,7 @@ static GitVersion.Extensions.StringExtensions.IsHelp(this string! singleArgument
13251325
static GitVersion.Extensions.StringExtensions.IsInit(this string! singleArgument) -> bool
13261326
static GitVersion.Extensions.StringExtensions.IsNullOrEmpty(this string? value) -> bool
13271327
static GitVersion.Extensions.StringExtensions.IsNullOrWhiteSpace(this string? value) -> bool
1328+
static GitVersion.Extensions.StringExtensions.IsEmpty(this string? value) -> bool
13281329
static GitVersion.Extensions.StringExtensions.IsSwitch(this string? value, string! switchName) -> bool
13291330
static GitVersion.Extensions.StringExtensions.IsSwitchArgument(this string? value) -> bool
13301331
static GitVersion.Extensions.StringExtensions.IsTrue(this string? value) -> bool

src/GitVersion.Core/VersionCalculation/NextVersionCalculator.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,12 @@ public NextVersion FindVersion()
7676
var hasPreReleaseTag = semver.PreReleaseTag?.HasTag() == true;
7777
var tag = configuration.Value.Tag;
7878
var branchConfigHasPreReleaseTagConfigured = !tag.IsNullOrEmpty();
79-
var preReleaseTagDoesNotMatchConfiguration = hasPreReleaseTag && branchConfigHasPreReleaseTagConfigured && semver.PreReleaseTag?.Name != tag;
80-
if (semver.PreReleaseTag?.HasTag() != true && branchConfigHasPreReleaseTagConfigured || preReleaseTagDoesNotMatchConfiguration)
79+
var branchConfigIsMainlineAndHasEmptyPreReleaseTagConfigured = configuration.Value.IsMainline && tag.IsEmpty();
80+
var preReleaseTagDoesNotMatchConfiguration = hasPreReleaseTag
81+
&& (branchConfigHasPreReleaseTagConfigured || branchConfigIsMainlineAndHasEmptyPreReleaseTagConfigured)
82+
&& semver.PreReleaseTag?.Name != tag;
83+
var preReleaseTagOnlyInBranchConfig = !hasPreReleaseTag && branchConfigHasPreReleaseTagConfigured;
84+
if (preReleaseTagOnlyInBranchConfig || preReleaseTagDoesNotMatchConfiguration)
8185
{
8286
UpdatePreReleaseTag(configuration.Value, semver, baseVersion.BranchNameOverride);
8387
}
@@ -112,6 +116,12 @@ private void UpdatePreReleaseTag(EffectiveConfiguration configuration, SemanticV
112116
{
113117
var tagToUse = configuration.GetBranchSpecificTag(this.log, Context.CurrentBranch.Name.Friendly, branchNameOverride);
114118

119+
if (configuration.IsMainline && tagToUse.IsEmpty())
120+
{
121+
semanticVersion.PreReleaseTag = new SemanticVersionPreReleaseTag(tagToUse, null);
122+
return;
123+
}
124+
115125
long? number = null;
116126

117127
var lastTag = this.repositoryStore

0 commit comments

Comments
 (0)