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
39 changes: 39 additions & 0 deletions src/GitVersion.Core.Tests/IntegrationTests/OtherScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -988,4 +988,43 @@ public void IncreaseVersionWithBumpMessageWhenCommitMessageIncrementIsEnabledAnd
// ✅ succeeds as expected
fixture.AssertFullSemver("2.0.0-pre.1", configuration);
}

[Test]
public void ShouldProvideTheCorrectVersionEvenIfPreReleaseLabelExistsInTheGitTagMain()
{
var configuration = GitFlowConfigurationBuilder.New
.WithNextVersion("5.0")
.WithSemanticVersionFormat(SemanticVersionFormat.Loose)
.WithBranch("main", _ => _
.WithLabel("beta")
.WithIncrement(IncrementStrategy.Patch)
.WithVersioningMode(VersioningMode.ContinuousDeployment)
).Build();

using EmptyRepositoryFixture fixture = new("main");
fixture.MakeACommit();

// ✅ succeeds as expected
fixture.AssertFullSemver("5.0.0-beta.1", configuration);

fixture.MakeACommit();

// ✅ succeeds as expected
fixture.AssertFullSemver("5.0.0-beta.2", configuration);

fixture.ApplyTag("5.0.0-beta.3");

// ✅ succeeds as expected
fixture.AssertFullSemver("5.0.0-beta.3", configuration);

fixture.MakeATaggedCommit("5.0.0-rc.1");

// ✅ succeeds as expected
fixture.AssertFullSemver("5.0.0-beta.4", configuration);

fixture.MakeACommit();

// ✅ succeeds as expected
fixture.AssertFullSemver("5.0.0-beta.5", configuration);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ public void ProvidesVariablesInContinuousDeploymentModeForStableWhenCurrentCommi

var configuration = new TestEffectiveConfiguration(versioningMode: VersioningMode.ContinuousDeployment);

var vars = this.variableProvider.GetVariablesFor(semVer, configuration, SemanticVersion.Empty);
var variables = this.variableProvider.GetVariablesFor(semVer, configuration, SemanticVersion.Empty);

vars.ToString().ShouldMatchApproved(c => c.SubFolder("Approved"));
variables.ToString().ShouldMatchApproved(c => c.SubFolder("Approved"));
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,7 @@ private NextVersion Calculate(IBranch branch, IGitVersionConfiguration configura
using (log.IndentLog("Calculating the base versions"))
{
var nextVersions = GetNextVersions(branch, configuration).ToArray();
var maxVersion = nextVersions.Max();

maxVersion.NotNull();
var maxVersion = nextVersions.Max()!;

var matchingVersionsOnceIncremented = nextVersions
.Where(v => v.BaseVersion.BaseVersionSource != null && v.IncrementedVersion == maxVersion.IncrementedVersion)
Expand Down
25 changes: 11 additions & 14 deletions src/GitVersion.Core/VersionCalculation/VariableProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,19 @@ public class VariableProvider : IVariableProvider
public VersionVariables GetVariablesFor(
SemanticVersion semanticVersion, EffectiveConfiguration configuration, SemanticVersion? currentCommitTaggedVersion)
{
semanticVersion.NotNull();
configuration.NotNull();

var preReleaseTagName = semanticVersion.PreReleaseTag.Name;
var isContinuousDeploymentMode = configuration.VersioningMode == VersioningMode.ContinuousDeployment;

var label = configuration.GetBranchSpecificLabel(semanticVersion.BuildMetaData.Branch, null);
var isCommitTagged = currentCommitTaggedVersion is not null && currentCommitTaggedVersion.IsMatchForBranchSpecificLabel(label);

var isContinuousDeploymentMode = configuration.VersioningMode == VersioningMode.ContinuousDeployment
&& currentCommitTaggedVersion is null;
if (isContinuousDeploymentMode)
// Continuous Deployment always requires a pre-release tag unless the commit is tagged
if (isContinuousDeploymentMode && !isCommitTagged && !semanticVersion.PreReleaseTag.HasTag() && preReleaseTagName.IsNullOrEmpty())
{
semanticVersion = new SemanticVersion(semanticVersion);
// Continuous Deployment always requires a pre-release tag unless the commit is tagged
if (!semanticVersion.PreReleaseTag.HasTag())
{
preReleaseTagName = configuration.GetBranchSpecificLabel(semanticVersion.BuildMetaData.Branch, null);
if (preReleaseTagName.IsNullOrEmpty())
{
preReleaseTagName = configuration.Label ?? string.Empty;
}
}
preReleaseTagName = label ?? string.Empty;
}

// Evaluate tag number pattern and append to prerelease tag, preserving build metadata
Expand All @@ -45,7 +42,7 @@ public VersionVariables GetVariablesFor(
}
}

if (isContinuousDeploymentMode || appendTagNumberPattern || configuration.VersioningMode == VersioningMode.Mainline)
if ((!isCommitTagged && isContinuousDeploymentMode) || appendTagNumberPattern || configuration.VersioningMode == VersioningMode.Mainline)
{
semanticVersion = PromoteNumberOfCommitsToTagNumber(semanticVersion, preReleaseTagName);
}
Expand Down