Skip to content

Commit 425d446

Browse files
Enrique Raso BarberoEnrique Raso Barbero
authored andcommitted
Detect if branchConfig is Mainline and has empty prerelease tag configured to update prerelease tag in semver
1 parent 3e5d1e7 commit 425d446

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
@@ -80,8 +80,12 @@ public NextVersion FindVersion()
8080
var hasPreReleaseTag = semver.PreReleaseTag?.HasTag() == true;
8181
var tag = configuration.Value.Tag;
8282
var branchConfigHasPreReleaseTagConfigured = !tag.IsNullOrEmpty();
83-
var preReleaseTagDoesNotMatchConfiguration = hasPreReleaseTag && branchConfigHasPreReleaseTagConfigured && semver.PreReleaseTag?.Name != tag;
84-
if (semver.PreReleaseTag?.HasTag() != true && branchConfigHasPreReleaseTagConfigured || preReleaseTagDoesNotMatchConfiguration)
83+
var branchConfigIsMainlineAndHasEmptyPreReleaseTagConfigured = configuration.Value.IsMainline && tag.IsEmpty();
84+
var preReleaseTagDoesNotMatchConfiguration = hasPreReleaseTag
85+
&& (branchConfigHasPreReleaseTagConfigured || branchConfigIsMainlineAndHasEmptyPreReleaseTagConfigured)
86+
&& semver.PreReleaseTag?.Name != tag;
87+
var preReleaseTagOnlyInBranchConfig = !hasPreReleaseTag && branchConfigHasPreReleaseTagConfigured;
88+
if (preReleaseTagOnlyInBranchConfig || preReleaseTagDoesNotMatchConfiguration)
8589
{
8690
UpdatePreReleaseTag(configuration.Value, semver, baseVersion.BranchNameOverride);
8791
}
@@ -116,6 +120,12 @@ private void UpdatePreReleaseTag(EffectiveConfiguration configuration, SemanticV
116120
{
117121
var tagToUse = configuration.GetBranchSpecificTag(this.log, Context.CurrentBranch.Name.Friendly, branchNameOverride);
118122

123+
if (configuration.IsMainline && tagToUse.IsEmpty())
124+
{
125+
semanticVersion.PreReleaseTag = new SemanticVersionPreReleaseTag(tagToUse, null);
126+
return;
127+
}
128+
119129
long? number = null;
120130

121131
var lastTag = this.repositoryStore

0 commit comments

Comments
 (0)