Skip to content

Attempt to fix merge message issue #1495

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

Closed
Closed
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
7 changes: 6 additions & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ build-metadata-padding: 4
commits-since-version-source-padding: 4
commit-message-incrementing: Enabled
commit-date-format: 'yyyy-MM-dd'
use-merge-message-version: true
ignore:
sha: []
commits-before: yyyy-MM-ddTHH:mm:ss
Expand Down Expand Up @@ -179,6 +180,10 @@ Date and time in the format `yyyy-MM-ddTHH:mm:ss` (eg `commits-before:
2015-10-23T12:23:15`) to setup an exclusion range. Effectively any commit before
`commits-before` will be ignored.

#### use-merge-message-version
This configuration can be used to disable merge message version detection, where the version
is infered from the commit message.

## Branch configuration
Then we have branch specific configuration, which looks something like this:

Expand Down Expand Up @@ -286,7 +291,7 @@ By looking at this graph, you cannot tell which of these scenarios happened:

2. release/1.0.0 branches off feature/foo
- Branch feature/foo from master
- Branch release/1.0.0 from feature/foo
- Branch release/1.0.0 from feature/foo
- Add a commit to both release/1.0.0 and feature/foo
- feature/foo is the base for release/1.0.0

Expand Down
4 changes: 2 additions & 2 deletions src/GitVersionCore.Tests/CommitDateTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -28,7 +28,7 @@ public void CommitDateFormatTest(string format, string expectedOutcome)
},
new EffectiveConfiguration(
AssemblyVersioningScheme.MajorMinorPatch, AssemblyFileVersioningScheme.MajorMinorPatch, "", "", "", VersioningMode.ContinuousDelivery, "", "", "", IncrementStrategy.Inherit,
"", true, "", "", false, "", "", "", "", CommitMessageIncrementMode.Enabled, 4, 4, 4, Enumerable.Empty<IVersionFilter>(), false, true, format)
"", true, "", "", false, "", "", "", "", CommitMessageIncrementMode.Enabled, 4, 4, 4, Enumerable.Empty<IVersionFilter>(), false, true, format, true)
);

Assert.That(formatValues.CommitDate, Is.EqualTo(expectedOutcome));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ legacy-semver-padding: 4
build-metadata-padding: 4
commits-since-version-source-padding: 4
commit-message-incrementing: Enabled
use-merge-message-version: true
branches:
develop:
mode: ContinuousDeployment
Expand Down
7 changes: 4 additions & 3 deletions src/GitVersionCore.Tests/TestEffectiveConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,16 @@ public TestEffectiveConfiguration(
IEnumerable<IVersionFilter> versionFilters = null,
bool tracksReleaseBranches = false,
bool isRelease = false,
string commitDateFormat = "yyyy-MM-dd") :
string commitDateFormat = "yyyy-MM-dd",
bool useMergeMessageVersion = true) :
base(assemblyVersioningScheme, assemblyFileVersioningScheme, assemblyInformationalFormat, assemblyVersioningFormat, assemblyFileVersioningFormat, versioningMode, gitTagPrefix, tag, nextVersion, IncrementStrategy.Patch,
branchPrefixToTrim, preventIncrementForMergedBranchVersion, tagNumberPattern, continuousDeploymentFallbackTag,
trackMergeTarget,
majorMessage, minorMessage, patchMessage, noBumpMessage,
commitMessageMode, legacySemVerPadding, buildMetaDataPadding, commitsSinceVersionSourcePadding,
versionFilters ?? Enumerable.Empty<IVersionFilter>(),
tracksReleaseBranches, isRelease, commitDateFormat)
tracksReleaseBranches, isRelease, commitDateFormat, useMergeMessageVersion)
{
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
namespace GitVersionCore.Tests.VersionCalculation.Strategies
namespace GitVersionCore.Tests.VersionCalculation.Strategies
{
using System.Collections.Generic;
using System.Linq;
using GitVersion;
using GitVersion.VersionCalculation.BaseVersionCalculators;
using LibGit2Sharp;
using NUnit.Framework;
Expand All @@ -15,14 +16,16 @@ public void ShouldNotAllowIncrementOfVersion()
{
// When a branch is merged in you want to start building stable packages of that version
// So we shouldn't bump the version
var context = new GitVersionContextBuilder().WithRepository(new MockRepository
{
Head = new MockBranch("master") { new MockCommit
var context = new GitVersionContextBuilder()
.WithRepository(new MockRepository
{
Head = new MockBranch("master") { new MockCommit
{
MessageEx = "Merge branch 'hotfix-0.1.5'",
ParentsEx = GetParents(true)
} }
}).Build();
}).Build();

var sut = new MergeMessageBaseVersionStrategy();

var baseVersion = sut.GetVersions(context).Single();
Expand Down Expand Up @@ -94,7 +97,7 @@ public void MergeMessagesThatIsNotRelatedToGitVersion(string commitMessage)
var parents = GetParents(true);

AssertMergeMessage(commitMessage, null, parents);
}
}

static void AssertMergeMessage(string message, string expectedVersion, List<Commit> parents)
{
Expand All @@ -105,6 +108,10 @@ static void AssertMergeMessage(string message, string expectedVersion, List<Comm
};

var context = new GitVersionContextBuilder()
.WithConfig(new Config()
{
UseMergeMessageVersion = true
})
.WithRepository(new MockRepository
{
Head = new MockBranch("master")
Expand Down Expand Up @@ -145,4 +152,4 @@ static List<Commit> GetParents(bool isMergeCommit)
};
}
}
}
}
2 changes: 1 addition & 1 deletion src/GitVersionCore/Configuration/BranchConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace GitVersion
namespace GitVersion
{
using System.Collections.Generic;
using YamlDotNet.Serialization;
Expand Down
7 changes: 5 additions & 2 deletions src/GitVersionCore/Configuration/Config.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace GitVersion
namespace GitVersion
{
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -79,6 +79,9 @@ public string NextVersion
[YamlMember(Alias = "commit-message-incrementing")]
public CommitMessageIncrementMode? CommitMessageIncrementing { get; set; }

[YamlMember(Alias = "use-merge-message-version")]
public bool? UseMergeMessageVersion { get; set; }

[YamlMember(Alias = "branches")]
public Dictionary<string, BranchConfig> Branches
{
Expand Down Expand Up @@ -145,4 +148,4 @@ T MergeObjects<T>(T target, T source)
[YamlMember(Alias = "commit-date-format")]
public string CommitDateFormat { get; set; }
}
}
}
1 change: 1 addition & 0 deletions src/GitVersionCore/Configuration/ConfigurationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public static void ApplyDefaultsTo(Config config)
config.BuildMetaDataPadding = config.BuildMetaDataPadding ?? 4;
config.CommitsSinceVersionSourcePadding = config.CommitsSinceVersionSourcePadding ?? 4;
config.CommitDateFormat = config.CommitDateFormat ?? "yyyy-MM-dd";
config.UseMergeMessageVersion = config.UseMergeMessageVersion ?? true;

var configBranches = config.Branches.ToList();

Expand Down
9 changes: 6 additions & 3 deletions src/GitVersionCore/EffectiveConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using GitVersion.VersionFilters;

namespace GitVersion
Expand Down Expand Up @@ -32,7 +32,8 @@ public EffectiveConfiguration(
IEnumerable<IVersionFilter> versionFilters,
bool tracksReleaseBranches,
bool isCurrentBranchRelease,
string commitDateFormat)
string commitDateFormat,
bool useMergeMessageVersion)
{
AssemblyVersioningScheme = assemblyVersioningScheme;
AssemblyFileVersioningScheme = assemblyFileVersioningScheme;
Expand Down Expand Up @@ -61,6 +62,7 @@ public EffectiveConfiguration(
TracksReleaseBranches = tracksReleaseBranches;
IsCurrentBranchRelease = isCurrentBranchRelease;
CommitDateFormat = commitDateFormat;
UseMergeMessageVersion = useMergeMessageVersion;
}

public bool TracksReleaseBranches { get; private set; }
Expand Down Expand Up @@ -115,5 +117,6 @@ public EffectiveConfiguration(
public IEnumerable<IVersionFilter> VersionFilters { get; private set; }

public string CommitDateFormat { get; private set; }
public bool UseMergeMessageVersion { get; private set; }
}
}
}
8 changes: 6 additions & 2 deletions src/GitVersionCore/GitVersionContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace GitVersion
namespace GitVersion
{
using LibGit2Sharp;
using System;
Expand Down Expand Up @@ -110,6 +110,8 @@ void CalculateEffectiveConfiguration()
throw new Exception("Configuration value for 'BuildMetaDataPadding' has no value. (this should not happen, please report an issue)");
if (!FullConfiguration.CommitsSinceVersionSourcePadding.HasValue)
throw new Exception("Configuration value for 'CommitsSinceVersionSourcePadding' has no value. (this should not happen, please report an issue)");
if (!FullConfiguration.UseMergeMessageVersion.HasValue)
throw new Exception("Configuration value for 'UseMergeMessageVersion' has no value. (this should not happen, please report an issue)");

var versioningMode = currentBranchConfig.VersioningMode.Value;
var tag = currentBranchConfig.Tag;
Expand All @@ -132,6 +134,7 @@ void CalculateEffectiveConfiguration()
var commitDateFormat = FullConfiguration.CommitDateFormat;

var commitMessageVersionBump = currentBranchConfig.CommitMessageIncrementing ?? FullConfiguration.CommitMessageIncrementing.Value;
var useMergeMessageVersion = FullConfiguration.UseMergeMessageVersion.Value;

Configuration = new EffectiveConfiguration(
assemblyVersioningScheme, assemblyFileVersioningScheme, assemblyInformationalFormat, assemblyVersioningFormat, assemblyFileVersioningFormat, versioningMode, gitTagPrefix,
Expand All @@ -148,7 +151,8 @@ void CalculateEffectiveConfiguration()
FullConfiguration.Ignore.ToFilters(),
currentBranchConfig.TracksReleaseBranches.Value,
currentBranchConfig.IsReleaseBranch.Value,
commitDateFormat);
commitDateFormat,
useMergeMessageVersion);
}

private static Branch GetTargetBranch(IRepository repository, string targetBranch)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace GitVersion.VersionCalculation
namespace GitVersion.VersionCalculation
{
using System;
using System.Linq;
Expand Down Expand Up @@ -93,4 +93,4 @@ public static SemanticVersion MaybeIncrement(GitVersionContext context, BaseVers
return version.SemanticVersion;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace GitVersion.VersionCalculation.BaseVersionCalculators
namespace GitVersion.VersionCalculation.BaseVersionCalculators
{
using System.Collections.Generic;
using System.Linq;
Expand All @@ -13,6 +13,11 @@ public class MergeMessageBaseVersionStrategy : BaseVersionStrategy
{
public override IEnumerable<BaseVersion> GetVersions(GitVersionContext context)
{
if (!context.Configuration.UseMergeMessageVersion)
{
return Enumerable.Empty<BaseVersion>();
}

var commitsPriorToThan = context.CurrentBranch
.CommitsPriorToThan(context.CurrentCommit.When());
var baseVersions = commitsPriorToThan
Expand Down Expand Up @@ -49,4 +54,4 @@ static SemanticVersion Inner(Commit mergeCommit, GitVersionContext context)
return mergeMessage.Version;
}
}
}
}
7 changes: 4 additions & 3 deletions src/GitVersionExe.Tests/TestEffectiveConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,17 @@ public TestEffectiveConfiguration(
IEnumerable<IVersionFilter> versionFilters = null,
bool tracksReleaseBranches = false,
bool isRelease = false,
string commitDateFormat = "yyyy-MM-dd") :
string commitDateFormat = "yyyy-MM-dd",
bool useMergeMessageVersion = true) :
base(assemblyVersioningScheme, assemblyFileVersioningScheme, assemblyInformationalFormat, assemblyVersioningFormat, assemblyFileVersioningFormat, versioningMode, gitTagPrefix, tag, nextVersion, IncrementStrategy.Patch,
branchPrefixToTrim, preventIncrementForMergedBranchVersion, tagNumberPattern, continuousDeploymentFallbackTag,
trackMergeTarget,
majorMessage, minorMessage, patchMessage, noBumpMessage,
commitMessageMode, legacySemVerPadding, buildMetaDataPadding, commitsSinceVersionSourcePadding,
versionFilters ?? Enumerable.Empty<IVersionFilter>(),
tracksReleaseBranches, isRelease, commitDateFormat)
tracksReleaseBranches, isRelease, commitDateFormat, useMergeMessageVersion)

{
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,16 @@ public TestEffectiveConfiguration(
IEnumerable<IVersionFilter> versionFilters = null,
bool tracksReleaseBranches = false,
bool isRelease = false,
string commitDateFormat = "yyyy-MM-dd") :
string commitDateFormat = "yyyy-MM-dd",
bool useMergeMessageVersion = true) :
base(assemblyVersioningScheme, assemblyFileVersioningScheme, assemblyInformationalFormat, assemblyVersioningFormat, assemblyFileVersioningFormat, versioningMode, gitTagPrefix, tag, nextVersion, IncrementStrategy.Patch,
branchPrefixToTrim, preventIncrementForMergedBranchVersion, tagNumberPattern, continuousDeploymentFallbackTag,
trackMergeTarget,
majorMessage, minorMessage, patchMessage, noBumpMessage,
commitMessageMode, legacySemVerPadding, buildMetaDataPadding, commitsSinceVersionSourcePadding,
versionFilters ?? Enumerable.Empty<IVersionFilter>(),
tracksReleaseBranches, isRelease, commitDateFormat)
tracksReleaseBranches, isRelease, commitDateFormat, useMergeMessageVersion)
{
}
}
}
}