Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introducing a new branch related property with name track-merge-message #3392

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions BREAKING_CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* When overriding the configuration with e.g. GitVersion.yaml the software distinguishes between properties who are not existent and properties who are `null`. This is especially important if the user wants to define branch related configuration which are marked with `increment` strategy `Inherit`.
* Following root configuration properties have been removed:
* continuous-delivery-fallback-tag
* A new branch related property with name `track-merge-message` has been introduced. Consider we have a `main` branch and a `release/1.0.0` branch and merge changes from `release/1.0.0` to the main branch. In this scenario the merge message will be interpreted as a next version `1.0.0` when `track-merge-message` is set to `true` otherwise `0.0.1`.

## v5.0.0

Expand Down
8 changes: 8 additions & 0 deletions docs/input/docs/reference/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ label: '{BranchName}'
increment: Inherit
prevent-increment-of-merged-branch-version: false
track-merge-target: false
track-merge-message: true
commit-message-incrementing: Enabled
regex: ''
tracks-release-branches: false
Expand Down Expand Up @@ -602,6 +603,13 @@ Strategy which will look for tagged merge commits directly off the current
branch. For example `develop` → `release/1.0.0` → merge into `main` and tag
`1.0.0`. The tag is _not_ on develop, but develop should be version `1.0.0` now.

### track-merge-message

This property is a branch related property and gives the user the possibility to control the behavior of whether the merge
commit message will be interpreted as a next version or not. Consider we have a main branch and a `release/1.0.0` branch and
merge changes from `release/1.0.0` to the `main` branch. If `track-merge-message is set to `true` then the next version will
HHobeck marked this conversation as resolved.
Show resolved Hide resolved
be `1.0.0` otherwise `0.0.1`.

### tracks-release-branches

Indicates this branch config represents develop in GitFlow.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ label: '{BranchName}'
increment: Inherit
prevent-increment-of-merged-branch-version: false
track-merge-target: false
track-merge-message: true
commit-message-incrementing: Enabled
regex: ''
tracks-release-branches: false
Expand Down
35 changes: 35 additions & 0 deletions src/GitVersion.Core.Tests/IntegrationTests/MainScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -371,4 +371,39 @@ public void PreventDecrementationOfVersionsOnTheDevelopmentBranch()
// ✅ succeeds as expected
fixture.AssertFullSemver("1.1.0-alpha.3", configurationBuilder.Build());
}

[TestCase(true, "1.1.0+0")]
[TestCase(false, "1.0.1+4")]
public void TrackMergeMessageShouldBeConsideredOnTheMainBranch(bool trackMergeMessage, string expectedSemanticVersion)
{
using EmptyRepositoryFixture fixture = new("main");

var configuration = GitFlowConfigurationBuilder.New
.WithBranch("main", branchBuilder => branchBuilder.WithTrackMergeMessage(trackMergeMessage))
.Build();

fixture.MakeATaggedCommit("1.0.0");
fixture.BranchTo("release/1.1.0");
fixture.MakeACommit();
fixture.MakeACommit();

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

fixture.Checkout("main");
fixture.MakeACommit();

// ✅ succeeds as expected
fixture.AssertFullSemver("1.0.1+1", configuration);

fixture.MergeNoFF("release/1.1.0");

// ✅ succeeds as expected
fixture.AssertFullSemver(expectedSemanticVersion, configuration);

fixture.Remove("release/1.0.0");

// ✅ succeeds as expected
fixture.AssertFullSemver(expectedSemanticVersion, configuration);
}
}
5 changes: 5 additions & 0 deletions src/GitVersion.Core/Configuration/BranchConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public BranchConfiguration(BranchConfiguration branchConfiguration)
PreventIncrementOfMergedBranchVersion = branchConfiguration.PreventIncrementOfMergedBranchVersion;
LabelNumberPattern = branchConfiguration.LabelNumberPattern;
TrackMergeTarget = branchConfiguration.TrackMergeTarget;
TrackMergeMessage = branchConfiguration.TrackMergeMessage;
CommitMessageIncrementing = branchConfiguration.CommitMessageIncrementing;
TracksReleaseBranches = branchConfiguration.TracksReleaseBranches;
Regex = branchConfiguration.Regex;
Expand Down Expand Up @@ -49,6 +50,9 @@ public BranchConfiguration(BranchConfiguration branchConfiguration)
[YamlMember(Alias = "track-merge-target")]
public bool? TrackMergeTarget { get; set; }

[YamlMember(Alias = "track-merge-message")]
public bool? TrackMergeMessage { get; set; }

[YamlMember(Alias = "commit-message-incrementing")]
public CommitMessageIncrementMode? CommitMessageIncrementing { get; set; }

Expand Down Expand Up @@ -92,6 +96,7 @@ public BranchConfiguration Inherit(BranchConfiguration? parentConfig)
result.PreventIncrementOfMergedBranchVersion ??= parentConfig.PreventIncrementOfMergedBranchVersion;
result.LabelNumberPattern ??= parentConfig.LabelNumberPattern;
result.TrackMergeTarget ??= parentConfig.TrackMergeTarget;
result.TrackMergeMessage ??= parentConfig.TrackMergeMessage;
result.CommitMessageIncrementing ??= parentConfig.CommitMessageIncrementing;
result.Regex ??= parentConfig.Regex;
result.SourceBranches ??= parentConfig.SourceBranches;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class BranchConfigurationBuilder
private bool? preventIncrementOfMergedBranchVersion;
private string? labelNumberPattern;
private bool? trackMergeTarget;
private bool? trackMergeMessage;
private CommitMessageIncrementMode? commitMessageIncrementing;
private string? regex;
private HashSet<string>? sourceBranches;
Expand Down Expand Up @@ -68,6 +69,12 @@ public virtual BranchConfigurationBuilder WithTrackMergeTarget(bool? value)
return this;
}

public virtual BranchConfigurationBuilder WithTrackMergeMessage(bool? value)
{
this.trackMergeMessage = value;
return this;
}

public virtual BranchConfigurationBuilder WithCommitMessageIncrementing(CommitMessageIncrementMode? value)
{
this.commitMessageIncrementing = value;
Expand Down Expand Up @@ -137,6 +144,7 @@ public virtual BranchConfigurationBuilder WithConfiguration(BranchConfiguration
WithPreventIncrementOfMergedBranchVersion(value.PreventIncrementOfMergedBranchVersion);
WithLabelNumberPattern(value.LabelNumberPattern);
WithTrackMergeTarget(value.TrackMergeTarget);
WithTrackMergeMessage(value.TrackMergeMessage);
WithCommitMessageIncrementing(value.CommitMessageIncrementing);
WithRegex(value.Regex);
WithTracksReleaseBranches(value.TracksReleaseBranches);
Expand All @@ -159,6 +167,7 @@ public BranchConfiguration Build()
Regex = regex,
TracksReleaseBranches = tracksReleaseBranches,
TrackMergeTarget = trackMergeTarget,
TrackMergeMessage = trackMergeMessage,
CommitMessageIncrementing = commitMessageIncrementing,
IsMainline = isMainline,
IsReleaseBranch = isReleaseBranch,
Expand Down
9 changes: 9 additions & 0 deletions src/GitVersion.Core/Configuration/ConfigurationBuilderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ internal abstract class ConfigurationBuilderBase<TConfigurationBuilder>
private bool? preventIncrementOfMergedBranchVersion;
private string? labelNumberPattern;
private bool? trackMergeTarget;
private bool? trackMergeMessage;
private CommitMessageIncrementMode? commitMessageIncrementing;
private string? regex;
private HashSet<string>? sourceBranches;
Expand Down Expand Up @@ -207,6 +208,12 @@ public virtual TConfigurationBuilder WithTrackMergeTarget(bool? value)
return (TConfigurationBuilder)this;
}

public virtual TConfigurationBuilder WithTrackMergeMessage(bool? value)
{
this.trackMergeMessage = value;
return (TConfigurationBuilder)this;
}

public virtual TConfigurationBuilder WithCommitMessageIncrementing(CommitMessageIncrementMode? value)
{
this.commitMessageIncrementing = value;
Expand Down Expand Up @@ -296,6 +303,7 @@ public virtual TConfigurationBuilder WithConfiguration(GitVersionConfiguration v
WithPreventIncrementOfMergedBranchVersion(value.PreventIncrementOfMergedBranchVersion);
WithLabelNumberPattern(value.LabelNumberPattern);
WithTrackMergeTarget(value.TrackMergeTarget);
WithTrackMergeMessage(value.TrackMergeMessage);
WithCommitMessageIncrementing(value.CommitMessageIncrementing);
WithRegex(value.Regex);
WithTracksReleaseBranches(value.TracksReleaseBranches);
Expand Down Expand Up @@ -343,6 +351,7 @@ public virtual GitVersionConfiguration Build()
Regex = this.regex,
TracksReleaseBranches = this.tracksReleaseBranches,
TrackMergeTarget = this.trackMergeTarget,
TrackMergeMessage = this.trackMergeMessage,
CommitMessageIncrementing = this.commitMessageIncrementing,
IsMainline = this.isMainline,
IsReleaseBranch = this.isReleaseBranch,
Expand Down
25 changes: 1 addition & 24 deletions src/GitVersion.Core/Configuration/ConfigurationExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Text.RegularExpressions;
using GitVersion.Extensions;
using GitVersion.Logging;
using GitVersion.VersionCalculation;

namespace GitVersion.Configuration;

Expand Down Expand Up @@ -56,32 +55,10 @@ private static IEnumerable<BranchConfiguration> GetBranchConfigurations(GitVersi
public static BranchConfiguration GetFallbackBranchConfiguration(this GitVersionConfiguration configuration)
{
BranchConfiguration result = new(configuration);
result.Name ??= "fallback";
result.Regex ??= "";
result.Label ??= "{BranchName}";
result.VersioningMode ??= VersioningMode.ContinuousDelivery;
result.PreventIncrementOfMergedBranchVersion ??= false;
result.TrackMergeTarget ??= false;
result.TracksReleaseBranches ??= false;
result.IsReleaseBranch ??= false;
result.IsMainline ??= false;
result.CommitMessageIncrementing ??= CommitMessageIncrementMode.Enabled;
if (result.Increment == IncrementStrategy.Inherit)
{
result.Increment = IncrementStrategy.None;
}
if (result.Increment == IncrementStrategy.Inherit) result.Increment = IncrementStrategy.None;
return result;
}

private static BranchConfiguration? ForBranch(GitVersionConfiguration configuration, string branchName)
{
var matches = configuration.Branches
.Where(b => b.Value.Regex != null && Regex.IsMatch(branchName, b.Value.Regex, RegexOptions.IgnoreCase))
.ToArray();

return matches.Select(kvp => kvp.Value).FirstOrDefault();
}

public static bool IsReleaseBranch(this GitVersionConfiguration configuration, string branchName) => configuration.GetBranchConfiguration(branchName).IsReleaseBranch ?? false;

public static string GetBranchSpecificTag(this EffectiveConfiguration configuration, ILog log, string? branchFriendlyName, string? branchNameOverride)
Expand Down
3 changes: 3 additions & 0 deletions src/GitVersion.Core/Configuration/EffectiveConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public EffectiveConfiguration(GitVersionConfiguration configuration, BranchConfi
PreventIncrementOfMergedBranchVersion = currentBranchConfig.PreventIncrementOfMergedBranchVersion ?? false;
LabelNumberPattern = currentBranchConfig.LabelNumberPattern;
TrackMergeTarget = currentBranchConfig.TrackMergeTarget ?? false;
TrackMergeMessage = currentBranchConfig.TrackMergeMessage ?? true;
MajorVersionBumpMessage = configuration.MajorVersionBumpMessage;
MinorVersionBumpMessage = configuration.MinorVersionBumpMessage;
PatchVersionBumpMessage = configuration.PatchVersionBumpMessage;
Expand Down Expand Up @@ -155,6 +156,8 @@ protected EffectiveConfiguration(AssemblyVersioningScheme assemblyVersioningSche

public bool TrackMergeTarget { get; }

public bool TrackMergeMessage { get; }

public string? MajorVersionBumpMessage { get; }

public string? MinorVersionBumpMessage { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ private GitFlowConfigurationBuilder()
CommitMessageIncrementing = CommitMessageIncrementMode.Enabled,
PreventIncrementOfMergedBranchVersion = false,
TrackMergeTarget = false,
TrackMergeMessage = true,
TracksReleaseBranches = false,
IsReleaseBranch = false,
IsMainline = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ private GitHubFlowConfigurationBuilder()
CommitMessageIncrementing = CommitMessageIncrementMode.Enabled,
PreventIncrementOfMergedBranchVersion = false,
TrackMergeTarget = false,
TrackMergeMessage = true,
TracksReleaseBranches = false,
IsReleaseBranch = false,
IsMainline = false
Expand Down
4 changes: 4 additions & 0 deletions src/GitVersion.Core/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ GitVersion.Configuration.BranchConfiguration.Regex.get -> string?
GitVersion.Configuration.BranchConfiguration.Regex.set -> void
GitVersion.Configuration.BranchConfiguration.SourceBranches.get -> System.Collections.Generic.HashSet<string!>?
GitVersion.Configuration.BranchConfiguration.SourceBranches.set -> void
GitVersion.Configuration.BranchConfiguration.TrackMergeMessage.get -> bool?
GitVersion.Configuration.BranchConfiguration.TrackMergeMessage.set -> void
GitVersion.Configuration.BranchConfiguration.TrackMergeTarget.get -> bool?
GitVersion.Configuration.BranchConfiguration.TrackMergeTarget.set -> void
GitVersion.Configuration.BranchConfiguration.TracksReleaseBranches.get -> bool?
Expand Down Expand Up @@ -168,6 +170,7 @@ GitVersion.Configuration.EffectiveConfiguration.PreReleaseWeight.get -> int
GitVersion.Configuration.EffectiveConfiguration.PreventIncrementOfMergedBranchVersion.get -> bool
GitVersion.Configuration.EffectiveConfiguration.SemanticVersionFormat.get -> GitVersion.SemanticVersionFormat
GitVersion.Configuration.EffectiveConfiguration.SemanticVersionFormat.set -> void
GitVersion.Configuration.EffectiveConfiguration.TrackMergeMessage.get -> bool
GitVersion.Configuration.EffectiveConfiguration.TrackMergeTarget.get -> bool
GitVersion.Configuration.EffectiveConfiguration.TracksReleaseBranches.get -> bool
GitVersion.Configuration.EffectiveConfiguration.UpdateBuildNumber.get -> bool
Expand Down Expand Up @@ -1245,6 +1248,7 @@ virtual GitVersion.Configuration.BranchConfigurationBuilder.WithPreventIncrement
virtual GitVersion.Configuration.BranchConfigurationBuilder.WithRegex(string? value) -> GitVersion.Configuration.BranchConfigurationBuilder!
virtual GitVersion.Configuration.BranchConfigurationBuilder.WithSourceBranches(System.Collections.Generic.IEnumerable<string!>? values) -> GitVersion.Configuration.BranchConfigurationBuilder!
virtual GitVersion.Configuration.BranchConfigurationBuilder.WithSourceBranches(params string![]? values) -> GitVersion.Configuration.BranchConfigurationBuilder!
virtual GitVersion.Configuration.BranchConfigurationBuilder.WithTrackMergeMessage(bool? value) -> GitVersion.Configuration.BranchConfigurationBuilder!
virtual GitVersion.Configuration.BranchConfigurationBuilder.WithTrackMergeTarget(bool? value) -> GitVersion.Configuration.BranchConfigurationBuilder!
virtual GitVersion.Configuration.BranchConfigurationBuilder.WithTracksReleaseBranches(bool? value) -> GitVersion.Configuration.BranchConfigurationBuilder!
virtual GitVersion.Configuration.BranchConfigurationBuilder.WithVersioningMode(GitVersion.VersionCalculation.VersioningMode? value) -> GitVersion.Configuration.BranchConfigurationBuilder!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public MergeMessageVersionStrategy(ILog log, Lazy<GitVersionContext> versionCont

public override IEnumerable<BaseVersion> GetBaseVersions(EffectiveBranchConfiguration configuration)
{
if (Context.CurrentBranch.Commits == null || Context.CurrentCommit == null)
if (Context.CurrentBranch.Commits == null || Context.CurrentCommit == null || !configuration.Value.TrackMergeMessage)
return Enumerable.Empty<BaseVersion>();

var commitsPriorToThan = Context.CurrentBranch.Commits.GetCommitsPriorTo(Context.CurrentCommit.When);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ private IEnumerable<EffectiveBranchConfiguration> GetEffectiveConfigurationsRecu
// Because the actual branch is marked with the inherit increment strategy we need to either skip the iteration or go further
// while inheriting from the fallback branch configuration. This behavior is configurable via the increment settings of the configuration.
var fallbackBranchConfiguration = configuration.GetFallbackBranchConfiguration();
var skipTraversingOfOrphanedBranches = fallbackBranchConfiguration.Increment == null
|| fallbackBranchConfiguration.Increment == IncrementStrategy.Inherit;
var skipTraversingOfOrphanedBranches = fallbackBranchConfiguration.Increment == null;
this.log.Info(
$"An orphaned branch '{branch}' has been detected and will be skipped={skipTraversingOfOrphanedBranches}."
);
Expand Down
2 changes: 2 additions & 0 deletions src/GitVersion.Testing/Fixtures/RepositoryFixtureBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ protected virtual void Dispose(bool disposing)

public void Checkout(string branch) => Commands.Checkout(Repository, branch);

public void Remove(string branch) => Repository.Branches.Remove(branch);

public static void Init(string path, string branchName) => GitTestExtensions.ExecuteGitCmd($"init {path} -b {branchName}");

public void MakeATaggedCommit(string tag)
Expand Down