Skip to content
Closed
11 changes: 11 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ 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
regex: 'ignoreMatch'
```

And the description of the available options are:
Expand Down Expand Up @@ -153,6 +156,10 @@ details on the syntax. Default set to `Enabled`; set to `Disabled` to disable.
### commit-date-format
Sets the format which will be used to format the `CommitDate` output variable.

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

### ignore
The header for ignore configuration.

Expand All @@ -179,6 +186,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.

#### regex
The regex to match commit messages that will be ignored. Useful to exclude for example
pull request from an automatic nuget updater.

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

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)
{
}
}
}
}
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
8 changes: 6 additions & 2 deletions src/GitVersionCore/Configuration/IgnoreConfig.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 All @@ -19,10 +19,14 @@ public IgnoreConfig()
[YamlMember(Alias = "sha")]
public IEnumerable<string> SHAs { get; set; }

[YamlMember(Alias = "regex")]
public string Regex { get; set; }

public virtual IEnumerable<IVersionFilter> ToFilters()
{
if (SHAs.Any()) yield return new ShaVersionFilter(SHAs);
if (Before.HasValue) yield return new MinDateVersionFilter(Before.Value);
if (!string.IsNullOrWhiteSpace(Regex)) yield return new MessageFilter(Regex);
}
}
}
}
12 changes: 8 additions & 4 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,7 +62,8 @@ public EffectiveConfiguration(
TracksReleaseBranches = tracksReleaseBranches;
IsCurrentBranchRelease = isCurrentBranchRelease;
CommitDateFormat = commitDateFormat;
}
UseMergeMessageVersion = useMergeMessageVersion;
}

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

public string CommitDateFormat { get; private set; }

public bool UseMergeMessageVersion { get; private set; }
}
}
}
9 changes: 6 additions & 3 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 @@ -130,7 +132,7 @@ void CalculateEffectiveConfiguration()
var patchMessage = FullConfiguration.PatchVersionBumpMessage;
var noBumpMessage = FullConfiguration.NoBumpMessage;
var commitDateFormat = FullConfiguration.CommitDateFormat;

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

Configuration = new EffectiveConfiguration(
Expand All @@ -148,7 +150,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.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;
}
}
}
}
35 changes: 35 additions & 0 deletions src/GitVersionCore/VersionFilters/MessageFilter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using GitVersion.VersionCalculation.BaseVersionCalculators;

namespace GitVersion.VersionFilters
{
public class MessageFilter : IVersionFilter
{
private readonly Regex regex;

public MessageFilter(string regex)
{
if (regex == null) throw new ArgumentNullException(nameof(regex));
this.regex = new Regex(regex); ;
}

public bool Exclude(BaseVersion version, out string reason)
{
if (version == null) throw new ArgumentNullException(nameof(version));

reason = null;

if (version.BaseVersionSource != null &&
regex.Match(version.BaseVersionSource.Message).Success)
{
reason = $"Message {version.BaseVersionSource.Message} was ignored due to commit having been excluded by configuration";
return true;
}

return false;
}
}
}
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)

{
}
}
}
}
2 changes: 1 addition & 1 deletion src/GitVersionExe/GitVersionExe.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand Down
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)
{
}
}
}
}