Skip to content

Commit

Permalink
Integrate code review remarks of asbjornu.
Browse files Browse the repository at this point in the history
  • Loading branch information
HHobeck committed Apr 19, 2024
1 parent 72fa337 commit a2344cc
Show file tree
Hide file tree
Showing 18 changed files with 99 additions and 27 deletions.
3 changes: 1 addition & 2 deletions docs/input/docs/reference/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,7 @@ The details of the available options are as follows:

### workflow

The base template of the configuration to use. Possible values are: GitFlow/v1 or GitHubFlow/v1. Defaults to GitFlow/v1 if not set. To create a configuration from scratch without using a base template please specify an empty string.

The base template of the configuration to use. Possible values are `GitFlow/v1` or `GitHubFlow/v1`. Defaults to `GitFlow/v1` if not set. To create a configuration from scratch without using a base template, please specify an empty string.
### next-version

Allows you to bump the next version explicitly. Useful for bumping `main` or a
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersion.Configuration/Workflows/TrunkBased/v1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ branches:
increment: Patch
prevent-increment:
of-merged-branch: true
when-current-commit-tagged: trueS
when-current-commit-tagged: true
track-merge-target: false
regex: ^master$|^main$
source-branches: []
Expand Down
57 changes: 57 additions & 0 deletions src/GitVersion.Core.Tests/IntegrationTests/OtherScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1307,4 +1307,61 @@ public void EnsureVersionAfterMainIsMergedBackToDevelopIsCorrectForGitFlow(bool
// ✅ succeeds as expected
fixture.AssertFullSemver(semanticVersion, configuration);
}

/// <summary>
/// see https://github.com/GitTools/GitVersion/issues/2394
/// </summary>
[Test]
public void EnsureVersionSourceIsSetToTheRightTag()
{
// Arrange
var configuration = GitFlowConfigurationBuilder.New.Build();

// Act
using var fixture = new BaseGitFlowRepositoryFixture("0.1.0");

fixture.Checkout("main");
fixture.MergeNoFF("develop");
fixture.Checkout("develop");
fixture.MakeACommit("Feature commit 1");
fixture.BranchTo("release/0.2.0");
fixture.MakeACommit("Release commit 1");
fixture.Checkout("main");
fixture.MergeNoFF("release/0.2.0");
fixture.ApplyTag("0.2.0");
var tag = fixture.Repository.Head.Tip;
fixture.Checkout("develop");
fixture.MergeNoFF("main");
var version = fixture.GetVersion(configuration);

// Assert
version.VersionSourceSha.ShouldBe(tag.Sha);
}

/// <summary>
/// see https://github.com/GitTools/GitVersion/issues/3689
/// </summary>
[Test]
public void UnversionedHotfix()
{
var configuration = GitFlowConfigurationBuilder.New.Build();

using var fixture = new BaseGitFlowRepositoryFixture("1.2.0");

// create hotfix
Commands.Checkout(fixture.Repository, "main");
Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("hotfix/put-out-the-fire"));
fixture.Repository.MakeACommit();

fixture.AssertFullSemver("1.2.1-beta.1+1", configuration);
fixture.Repository.MakeACommit();
fixture.AssertFullSemver("1.2.1-beta.1+2", configuration);

// Merge hotfix branch to main
Commands.Checkout(fixture.Repository, "main");

fixture.Repository.MergeNoFF("hotfix/put-out-the-fire", Generate.SignatureNow());

fixture.AssertFullSemver("1.2.1-3", configuration);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ internal sealed class CommitOnNonTrunk : ITrunkBasedIncrementer
// A 58 minutes ago

public bool MatchPrecondition(TrunkBasedIteration iteration, TrunkBasedCommit commit, TrunkBasedContext context)
=> !commit.HasChildIteration && !commit.GetEffectiveConfiguration(context.Configuration).IsMainBranch
&& context.SemanticVersion is null;
=> !commit.HasChildIteration
&& !commit.GetEffectiveConfiguration(context.Configuration).IsMainBranch
&& context.SemanticVersion is null;

public IEnumerable<IBaseVersionIncrement> GetIncrements(
TrunkBasedIteration iteration, TrunkBasedCommit commit, TrunkBasedContext context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ namespace GitVersion.VersionCalculation.TrunkBased.NonTrunk;
internal abstract class CommitOnNonTrunkBranchedBase : ITrunkBasedIncrementer
{
public virtual bool MatchPrecondition(TrunkBasedIteration iteration, TrunkBasedCommit commit, TrunkBasedContext context)
=> !commit.GetEffectiveConfiguration(context.Configuration).IsMainBranch && commit.BranchName != iteration.BranchName && commit.Successor is null;
=> !commit.GetEffectiveConfiguration(context.Configuration).IsMainBranch
&& commit.BranchName != iteration.BranchName
&& commit.Successor is null;

public virtual IEnumerable<IBaseVersionIncrement> GetIncrements(
TrunkBasedIteration iteration, TrunkBasedCommit commit, TrunkBasedContext context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ internal sealed class CommitOnNonTrunkBranchedToNonTrunk : CommitOnNonTrunkBranc
// A 58 minutes ago <<--

public override bool MatchPrecondition(TrunkBasedIteration iteration, TrunkBasedCommit commit, TrunkBasedContext context)
=> base.MatchPrecondition(iteration, commit, context) && !(iteration.Configuration.IsMainBranch == true);
=> base.MatchPrecondition(iteration, commit, context)
&& !iteration.GetEffectiveConfiguration(context.Configuration).IsMainBranch;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ internal sealed class CommitOnNonTrunkBranchedToTrunk : CommitOnNonTrunkBranched
// A 58 minutes ago <<--

public override bool MatchPrecondition(TrunkBasedIteration iteration, TrunkBasedCommit commit, TrunkBasedContext context)
=> base.MatchPrecondition(iteration, commit, context) && iteration.Configuration.IsMainBranch == true;
=> base.MatchPrecondition(iteration, commit, context)
&& iteration.GetEffectiveConfiguration(context.Configuration).IsMainBranch;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ namespace GitVersion.VersionCalculation.TrunkBased.NonTrunk;
internal abstract class CommitOnNonTrunkWithPreReleaseTagBase : ITrunkBasedIncrementer
{
public virtual bool MatchPrecondition(TrunkBasedIteration iteration, TrunkBasedCommit commit, TrunkBasedContext context)
=> !commit.HasChildIteration && !commit.GetEffectiveConfiguration(context.Configuration).IsMainBranch
=> !commit.HasChildIteration
&& !commit.GetEffectiveConfiguration(context.Configuration).IsMainBranch
&& context.SemanticVersion?.IsPreRelease == true;

public virtual IEnumerable<IBaseVersionIncrement> GetIncrements(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ namespace GitVersion.VersionCalculation.TrunkBased.NonTrunk;
internal abstract class CommitOnNonTrunkWithStableTagBase : ITrunkBasedIncrementer
{
public virtual bool MatchPrecondition(TrunkBasedIteration iteration, TrunkBasedCommit commit, TrunkBasedContext context)
=> !commit.GetEffectiveConfiguration(context.Configuration).IsMainBranch && !commit.HasChildIteration
&& context.SemanticVersion?.IsPreRelease == false;
=> !commit.GetEffectiveConfiguration(context.Configuration).IsMainBranch
&& !commit.HasChildIteration
&& context.SemanticVersion?.IsPreRelease == false;

public virtual IEnumerable<IBaseVersionIncrement> GetIncrements(
TrunkBasedIteration iteration, TrunkBasedCommit commit, TrunkBasedContext context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ internal sealed class FirstCommitOnRelease : ITrunkBasedIncrementer
// A 58 minutes ago (main)

public bool MatchPrecondition(TrunkBasedIteration iteration, TrunkBasedCommit commit, TrunkBasedContext context)
=> !commit.HasChildIteration && !commit.GetEffectiveConfiguration(context.Configuration).IsMainBranch
&& commit.GetEffectiveConfiguration(context.Configuration).IsReleaseBranch
&& context.SemanticVersion is null && (commit.Predecessor is null
|| commit.Predecessor?.BranchName != commit.BranchName);
=> !commit.HasChildIteration
&& !commit.GetEffectiveConfiguration(context.Configuration).IsMainBranch
&& commit.GetEffectiveConfiguration(context.Configuration).IsReleaseBranch
&& context.SemanticVersion is null
&& (commit.Predecessor is null
|| commit.Predecessor?.BranchName != commit.BranchName);

public IEnumerable<IBaseVersionIncrement> GetIncrements(
TrunkBasedIteration iteration, TrunkBasedCommit commit, TrunkBasedContext context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ namespace GitVersion.VersionCalculation.TrunkBased.NonTrunk;
internal abstract class MergeCommitOnNonTrunkBase : ITrunkBasedIncrementer
{
public virtual bool MatchPrecondition(TrunkBasedIteration iteration, TrunkBasedCommit commit, TrunkBasedContext context)
=> commit.HasChildIteration && !commit.GetEffectiveConfiguration(context.Configuration).IsMainBranch
&& context.SemanticVersion is null;
=> commit.HasChildIteration
&& !commit.GetEffectiveConfiguration(context.Configuration).IsMainBranch
&& context.SemanticVersion is null;

public virtual IEnumerable<IBaseVersionIncrement> GetIncrements(
TrunkBasedIteration iteration, TrunkBasedCommit commit, TrunkBasedContext context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public virtual IEnumerable<IBaseVersionIncrement> GetIncrements(
context.BaseVersionSource = commit.Value;

var effectiveConfiguration = iteration.GetEffectiveConfiguration(context.Configuration);
if (iteration.Configuration.IsReleaseBranch == true
if (iteration.GetEffectiveConfiguration(context.Configuration).IsReleaseBranch
&& iteration.BranchName.TryGetSemanticVersion(out var element, effectiveConfiguration))
{
context.AlternativeSemanticVersions.Add(element.Value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ internal sealed class CommitOnTrunkBranchedToNonTrunk : CommitOnTrunkBranchedBas
// A 58 minutes ago <<--

public override bool MatchPrecondition(TrunkBasedIteration iteration, TrunkBasedCommit commit, TrunkBasedContext context)
=> base.MatchPrecondition(iteration, commit, context) && !(iteration.Configuration.IsMainBranch == true);
=> base.MatchPrecondition(iteration, commit, context)
&& !iteration.GetEffectiveConfiguration(context.Configuration).IsMainBranch;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ internal sealed class CommitOnTrunkBranchedToTrunk : CommitOnTrunkBranchedBase
// A 58 minutes ago <<--

public override bool MatchPrecondition(TrunkBasedIteration iteration, TrunkBasedCommit commit, TrunkBasedContext context)
=> base.MatchPrecondition(iteration, commit, context) && iteration.Configuration.IsMainBranch == true;
=> base.MatchPrecondition(iteration, commit, context)
&& iteration.GetEffectiveConfiguration(context.Configuration).IsMainBranch;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public override IEnumerable<IBaseVersionIncrement> GetIncrements(
yield return item;
}

if (iteration.Configuration.IsMainBranch == true)
if (iteration.GetEffectiveConfiguration(context.Configuration).IsMainBranch)
{
context.Increment = commit.GetIncrementForcedByBranch(context.Configuration);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public override IEnumerable<IBaseVersionIncrement> GetIncrements(
yield return item;
}

if (iteration.Configuration.IsMainBranch == true)
if (iteration.GetEffectiveConfiguration(context.Configuration).IsMainBranch)
{
context.ForceIncrement = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ internal record TrunkBasedIteration

public EffectiveConfiguration GetEffectiveConfiguration(IGitVersionConfiguration configuration)
{
if (effectiveConfiguration is not null) return effectiveConfiguration;
if (this.effectiveConfiguration is not null)
{
return this.effectiveConfiguration;
}

IBranchConfiguration branchConfiguration = Configuration;

Expand All @@ -28,7 +31,7 @@ public EffectiveConfiguration GetEffectiveConfiguration(IGitVersionConfiguration
branchConfiguration = branchConfiguration.Inherit(parentConfiguration);
}

return effectiveConfiguration = new EffectiveConfiguration(configuration, branchConfiguration);
return this.effectiveConfiguration = new EffectiveConfiguration(configuration, branchConfiguration);
}

public TrunkBasedIteration? ParentIteration { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ private IEnumerable<BaseVersion> GetBaseVersionsInternal(EffectiveBranchConfigur

var label = configuration.Value.GetBranchSpecificLabel(Context.CurrentBranch.Name, null);
var maxTaggedSemanticVersion = taggedSemanticVersions
.Where(element => !element.Value.IsMatchForBranchSpecificLabel(label)).Max();
.Where(element => !element.Value.IsMatchForBranchSpecificLabel(label))
.Max();

foreach (var semanticVersionWithTag
in taggedSemanticVersions.Where(element => element.Value.IsMatchForBranchSpecificLabel(label)))
var semanticVersionsWithTag = taggedSemanticVersions.Where(element => element.Value.IsMatchForBranchSpecificLabel(label));
foreach (var semanticVersionWithTag in semanticVersionsWithTag)
{
var baseVersionSource = semanticVersionWithTag.Tag.Commit;
var increment = incrementStrategyFinder.DetermineIncrementedField(
Expand Down

0 comments on commit a2344cc

Please sign in to comment.