Skip to content

Commit

Permalink
Detect if branchConfig is Mainline and has empty prerelease tag confi…
Browse files Browse the repository at this point in the history
…gured to update prerelease tag in semver
  • Loading branch information
Enrique Raso Barbero authored and asbjornu committed Jan 20, 2023
1 parent 544d4d1 commit 7576b44
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/GitVersion.Core/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,6 @@ public static bool IsEquivalentTo(this string self, string? other) =>

/// <inheritdoc cref="string.IsNullOrWhiteSpace"/>
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);
}
1 change: 1 addition & 0 deletions src/GitVersion.Core/PublicAPI.Shipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions src/GitVersion.Core/VersionCalculation/NextVersionCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7576b44

Please sign in to comment.