Skip to content

Commit de023ba

Browse files
authored
Merge branch 'master' into feature/WiXDefines
2 parents add68f8 + 6c0f765 commit de023ba

File tree

11 files changed

+210
-139
lines changed

11 files changed

+210
-139
lines changed

docs/configuration.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ commit-date-format: 'yyyy-MM-dd'
4848
ignore:
4949
sha: []
5050
commits-before: yyyy-MM-ddTHH:mm:ss
51+
merge-message-formats: {}
5152
```
5253
5354
And the description of the available options are:
@@ -179,6 +180,24 @@ Date and time in the format `yyyy-MM-ddTHH:mm:ss` (eg `commits-before:
179180
2015-10-23T12:23:15`) to setup an exclusion range. Effectively any commit before
180181
`commits-before` will be ignored.
181182
183+
### merge-message-formats
184+
Custom merge message formats to enable identification of merge messages that do not
185+
follow the built-in conventions. Entries should be added as key-value pairs where
186+
the value is a regular expression.
187+
e.g.
188+
189+
```
190+
merge-message-formats:
191+
tfs: ^Merged (?:PR (?<PullRequestNumber>\d+)): Merge (?<SourceBranch>.+) to (?<TargetBranch>.+)
192+
```
193+
194+
The regular expression should contain the following capture groups:
195+
+ SourceBranch - Identifies the source branch of the merge
196+
+ TargetBranch - Identifies the target of the merge
197+
+ PullRequestNumber - Captures the pull-request number
198+
199+
Custom merge message formats are evalauted _before_ any built in formats.
200+
182201
## Branch configuration
183202
Then we have branch specific configuration, which looks something like this:
184203

src/GitVersionCore.Tests/ConfigProviderTests.CanWriteOutEffectiveConfiguration.approved.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,4 @@ branches:
122122
ignore:
123123
sha: []
124124
commit-date-format: yyyy-MM-dd
125+
merge-message-formats: {}

src/GitVersionCore.Tests/GitVersionCore.Tests.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111
</PropertyGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
14+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.0" />
1515
<PackageReference Include="FluentDateTime" Version="1.15.0" />
1616
<PackageReference Include="GitTools.Testing" Version="1.2.0" />
1717
<PackageReference Include="JetBrains.Annotations" Version="$(PackageVersion_JetBrainsAnnotations)"></PackageReference>
18-
<PackageReference Include="NSubstitute" Version="4.0.0" />
19-
<PackageReference Include="coverlet.msbuild" Version="2.6.0">
18+
<PackageReference Include="NSubstitute" Version="4.1.0" />
19+
<PackageReference Include="coverlet.msbuild" Version="2.6.1">
2020
<PrivateAssets>all</PrivateAssets>
2121
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
2222
</PackageReference>
23-
<PackageReference Include="NUnit" Version="3.11.0" />
23+
<PackageReference Include="NUnit" Version="3.12.0" />
2424
<packagereference Include="NUnit3TestAdapter" Version="3.13.0"></packagereference>
2525
<PackageReference Include="Shouldly" Version="3.0.2" />
2626
<PackageReference Include="TestStack.ConventionTests" Version="3.0.1" />

src/GitVersionCore.Tests/Init/InitScenarios.CanSetNextVersion.approved.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ next-version: 2.0.0
22
branches: {}
33
ignore:
44
sha: []
5+
merge-message-formats: {}

src/GitVersionCore.Tests/MergeMessageTests.cs

Lines changed: 149 additions & 105 deletions
Large diffs are not rendered by default.

src/GitVersionCore.Tests/VersionCalculation/Strategies/MergeMessageBaseVersionStrategyTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ public void ShouldNotAllowIncrementOfVersion()
4747
[TestCase("Merge branch 'Release-v2.2'", true, "2.2.0")]
4848
[TestCase("Merge remote-tracking branch 'origin/release/0.8.0' into develop/master", true, "0.8.0")]
4949
[TestCase("Merge remote-tracking branch 'refs/remotes/origin/release/2.0.0'", true, "2.0.0")]
50-
[TestCase("Merge release/5.1.0 to master", true, "5.1.0")] // Team Foundation Server 2017 default merge message (en-US)
51-
[TestCase("Zusammengeführter PR \"9\": release/5.1.0 mit master mergen", true, "5.1.0")] // Team Foundation Server 2017 default merge message (de-DE)
5250
public void TakesVersionFromMergeOfReleaseBranch(string message, bool isMergeCommit, string expectedVersion)
5351
{
5452
var parents = GetParents(isMergeCommit);

src/GitVersionCore/Configuration/Config.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,5 +145,8 @@ T MergeObjects<T>(T target, T source)
145145

146146
[YamlMember(Alias = "commit-date-format")]
147147
public string CommitDateFormat { get; set; }
148+
149+
[YamlMember(Alias = "merge-message-formats")]
150+
public Dictionary<string, string> MergeMessageFormats { get; set; } = new Dictionary<string, string>();
148151
}
149152
}

src/GitVersionCore/MergeMessage.cs

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,38 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using System.Text.RegularExpressions;
45

56
namespace GitVersion
67
{
7-
class MergeMessage
8+
public class MergeMessage
89
{
9-
private static readonly IList<MergeMessagePattern> Patterns = new List<MergeMessagePattern>
10+
private static readonly IList<MergeMessageFormat> DefaultFormats = new List<MergeMessageFormat>
1011
{
11-
new MergeMessagePattern("Default", @"^Merge (branch|tag) '(?<SourceBranch>[^']*)'(?: into (?<TargetBranch>[^\s]*))*"),
12-
new MergeMessagePattern("SmartGit", @"^Finish (?<SourceBranch>[^\s]*)(?: into (?<TargetBranch>[^\s]*))*"),
13-
new MergeMessagePattern("BitBucketPull", @"^Merge pull request #(?<PullRequestNumber>\d+) (from|in) (?<Source>.*) from (?<SourceBranch>[^\s]*) to (?<TargetBranch>[^\s]*)"),
14-
new MergeMessagePattern("GitHubPull", @"^Merge pull request #(?<PullRequestNumber>\d+) (from|in) (?:(?<SourceBranch>[^\s]*))(?: into (?<TargetBranch>[^\s]*))*"),
15-
new MergeMessagePattern("RemoteTracking", @"^Merge remote-tracking branch '(?<SourceBranch>[^\s]*)'(?: into (?<TargetBranch>[^\s]*))*"),
16-
new MergeMessagePattern("TfsMergeMessageEnglishUS", @"^Merge (?<SourceBranch>[^\s]*) to (?<TargetBranch>[^\s]*)"),
17-
new MergeMessagePattern("TfsMergeMessageGermanDE",@"^Zusammengeführter PR ""(?<PullRequestNumber>\d+)""\: (?<SourceBranch>.*) mit (?<TargetBranch>.*) mergen")
12+
new MergeMessageFormat("Default", @"^Merge (branch|tag) '(?<SourceBranch>[^']*)'(?: into (?<TargetBranch>[^\s]*))*"),
13+
new MergeMessageFormat("SmartGit", @"^Finish (?<SourceBranch>[^\s]*)(?: into (?<TargetBranch>[^\s]*))*"),
14+
new MergeMessageFormat("BitBucketPull", @"^Merge pull request #(?<PullRequestNumber>\d+) (from|in) (?<Source>.*) from (?<SourceBranch>[^\s]*) to (?<TargetBranch>[^\s]*)"),
15+
new MergeMessageFormat("GitHubPull", @"^Merge pull request #(?<PullRequestNumber>\d+) (from|in) (?:(?<SourceBranch>[^\s]*))(?: into (?<TargetBranch>[^\s]*))*"),
16+
new MergeMessageFormat("RemoteTracking", @"^Merge remote-tracking branch '(?<SourceBranch>[^\s]*)'(?: into (?<TargetBranch>[^\s]*))*")
1817
};
1918

2019
public MergeMessage(string mergeMessage, Config config)
2120
{
2221
if (mergeMessage == null)
2322
throw new NullReferenceException();
2423

25-
foreach (var pattern in Patterns)
24+
// Concat config formats with the defaults.
25+
// Ensure configs are processed first.
26+
var allFormats = config.MergeMessageFormats
27+
.Select(x => new MergeMessageFormat(x.Key, x.Value))
28+
.Concat(DefaultFormats);
29+
30+
foreach (var format in allFormats)
2631
{
27-
var match = pattern.Format.Match(mergeMessage);
32+
var match = format.Pattern.Match(mergeMessage);
2833
if (match.Success)
2934
{
30-
MatchDefinition = pattern.Name;
35+
FormatName = format.Name;
3136
MergedBranch = match.Groups["SourceBranch"].Value;
3237

3338
if (match.Groups["TargetBranch"].Success)
@@ -40,22 +45,21 @@ public MergeMessage(string mergeMessage, Config config)
4045
PullRequestNumber = pullNumber;
4146
}
4247

43-
Version = ParseVersion(MergedBranch, config.TagPrefix);
48+
Version = ParseVersion(config.TagPrefix);
4449

4550
break;
4651
}
4752
}
4853
}
4954

50-
public string MatchDefinition { get; }
55+
public string FormatName { get; }
5156
public string TargetBranch { get; }
5257
public string MergedBranch { get; } = "";
5358
public bool IsMergedPullRequest => PullRequestNumber != null;
5459
public int? PullRequestNumber { get; }
5560
public SemanticVersion Version { get; }
5661

57-
58-
private SemanticVersion ParseVersion(string branchName, string tagPrefix)
62+
private SemanticVersion ParseVersion(string tagPrefix)
5963
{
6064
// Remove remotes and branch prefixes like release/ feature/ hotfix/ etc
6165
var toMatch = Regex.Replace(MergedBranch, @"^(\w+[-/])*", "", RegexOptions.IgnoreCase);
@@ -72,17 +76,17 @@ private SemanticVersion ParseVersion(string branchName, string tagPrefix)
7276
return null;
7377
}
7478

75-
private class MergeMessagePattern
79+
private class MergeMessageFormat
7680
{
77-
public MergeMessagePattern(string name, string format)
81+
public MergeMessageFormat(string name, string pattern)
7882
{
7983
Name = name;
80-
Format = new Regex(format, RegexOptions.IgnoreCase | RegexOptions.Compiled);
84+
Pattern = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.Compiled);
8185
}
8286

8387
public string Name { get; }
8488

85-
public Regex Format { get; }
89+
public Regex Pattern { get; }
8690
}
8791
}
8892
}

src/GitVersionCore/VersionCalculation/BaseVersionCalculators/MergeMessageBaseVersionStrategy.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public override IEnumerable<BaseVersion> GetVersions(GitVersionContext context)
2323
mergeMessage.Version != null &&
2424
context.FullConfiguration.IsReleaseBranch(TrimRemote(mergeMessage.MergedBranch)))
2525
{
26+
Logger.WriteInfo($"Found commit [{context.CurrentCommit.Sha}] matching merge message format: {mergeMessage.FormatName}");
2627
var shouldIncrement = !context.Configuration.PreventIncrementForMergedBranchVersion;
2728
return new[]
2829
{

src/GitVersionExe.Tests/GitVersionExe.Tests.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
66
</PropertyGroup>
77
<ItemGroup>
8-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
8+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.0" />
99
<PackageReference Include="GitTools.Testing" Version="1.2.0"></PackageReference>
1010
<PackageReference Include="JetBrains.Annotations" Version="$(PackageVersion_JetBrainsAnnotations)"></PackageReference>
1111
<PackageReference Include="Mono.Cecil" Version="0.10.3"></PackageReference>
1212
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
13-
<PackageReference Include="NSubstitute" Version="4.0.0"></PackageReference>
14-
<PackageReference Include="coverlet.msbuild" Version="2.6.0">
13+
<PackageReference Include="NSubstitute" Version="4.1.0"></PackageReference>
14+
<PackageReference Include="coverlet.msbuild" Version="2.6.1">
1515
<PrivateAssets>all</PrivateAssets>
1616
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
1717
</PackageReference>
18-
<PackageReference Include="NUnit" Version="3.11.0"></PackageReference>
18+
<PackageReference Include="NUnit" Version="3.12.0"></PackageReference>
1919
<packagereference Include="NUnit3TestAdapter" Version="3.13.0"></packagereference>
2020
<PackageReference Include="Shouldly" Version="3.0.2"></PackageReference>
2121
</ItemGroup>

src/GitVersionTask.Tests/GitVersionTask.Tests.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
66
</PropertyGroup>
77
<ItemGroup>
8-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
8+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.0" />
99
<PackageReference Include="FluentDateTime" Version="1.15.0"></PackageReference>
1010
<PackageReference Include="JetBrains.Annotations" Version="$(PackageVersion_JetBrainsAnnotations)"></PackageReference>
1111
<PackageReference Include="Newtonsoft.Json" Version="12.0.2"></PackageReference>
12-
<PackageReference Include="NSubstitute" Version="4.0.0"></PackageReference>
13-
<PackageReference Include="coverlet.msbuild" Version="2.6.0">
12+
<PackageReference Include="NSubstitute" Version="4.1.0"></PackageReference>
13+
<PackageReference Include="coverlet.msbuild" Version="2.6.1">
1414
<PrivateAssets>all</PrivateAssets>
1515
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
1616
</PackageReference>
17-
<PackageReference Include="NUnit" Version="3.11.0"></PackageReference>
17+
<PackageReference Include="NUnit" Version="3.12.0"></PackageReference>
1818
<packagereference Include="NUnit3TestAdapter" Version="3.13.0"></packagereference>
1919
<PackageReference Include="Shouldly" Version="3.0.2"></PackageReference>
2020
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="16.0.461" />

0 commit comments

Comments
 (0)