Skip to content

Commit 0b051f4

Browse files
authored
Merge pull request #1410 from ruhullahshah/branch_regex_fix
[Bugfix] GitVersion crashes if there are multiple branches containing the keyword develop and the current branch has Increment policy set to Inherit with current commit being a merge commit
2 parents 043e4d8 + 39fabd7 commit 0b051f4

File tree

6 files changed

+47
-25
lines changed

6 files changed

+47
-25
lines changed

docs/configuration.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ If you have branch specific configuration upgrading to v4 will force you to upgr
189189
```yaml
190190
branches:
191191
master:
192-
regex: master
192+
regex: ^master
193193
mode: ContinuousDelivery
194194
tag: ''
195195
increment: Patch
@@ -198,7 +198,7 @@ branches:
198198
tracks-release-branches: false
199199
is-release-branch: false
200200
release:
201-
regex: releases?[/-]
201+
regex: ^releases?[/-]
202202
mode: ContinuousDelivery
203203
tag: beta
204204
increment: Patch
@@ -207,7 +207,7 @@ branches:
207207
tracks-release-branches: false
208208
is-release-branch: true
209209
feature:
210-
regex: features?[/-]
210+
regex: ^features?[/-]
211211
mode: ContinuousDelivery
212212
tag: useBranchName
213213
increment: Inherit
@@ -216,7 +216,7 @@ branches:
216216
tracks-release-branches: false
217217
is-release-branch: false
218218
pull-request:
219-
regex: (pull|pull\-requests|pr)[/-]
219+
regex: ^(pull|pull\-requests|pr)[/-]
220220
mode: ContinuousDelivery
221221
tag: PullRequest
222222
increment: Inherit
@@ -226,7 +226,7 @@ branches:
226226
tracks-release-branches: false
227227
is-release-branch: false
228228
hotfix:
229-
regex: hotfix(es)?[/-]
229+
regex: ^hotfix(es)?[/-]
230230
mode: ContinuousDelivery
231231
tag: beta
232232
increment: Patch
@@ -235,7 +235,7 @@ branches:
235235
tracks-release-branches: false
236236
is-release-branch: false
237237
support:
238-
regex: support[/-]
238+
regex: ^support[/-]
239239
mode: ContinuousDelivery
240240
tag: ''
241241
increment: Patch
@@ -244,7 +244,7 @@ branches:
244244
tracks-release-branches: false
245245
is-release-branch: false
246246
develop:
247-
regex: dev(elop)?(ment)?$
247+
regex: ^dev(elop)?(ment)?$
248248
mode: ContinuousDeployment
249249
tag: unstable
250250
increment: Minor

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ branches:
1818
increment: Minor
1919
prevent-increment-of-merged-branch-version: false
2020
track-merge-target: true
21-
regex: dev(elop)?(ment)?$
21+
regex: ^dev(elop)?(ment)?$
2222
source-branches: []
2323
tracks-release-branches: true
2424
is-release-branch: false
@@ -29,7 +29,7 @@ branches:
2929
increment: Patch
3030
prevent-increment-of-merged-branch-version: true
3131
track-merge-target: false
32-
regex: master$
32+
regex: ^master$
3333
source-branches:
3434
- develop
3535
- release
@@ -42,7 +42,7 @@ branches:
4242
increment: Patch
4343
prevent-increment-of-merged-branch-version: true
4444
track-merge-target: false
45-
regex: releases?[/-]
45+
regex: ^releases?[/-]
4646
source-branches:
4747
- develop
4848
- master
@@ -57,7 +57,7 @@ branches:
5757
increment: Inherit
5858
prevent-increment-of-merged-branch-version: false
5959
track-merge-target: false
60-
regex: features?[/-]
60+
regex: ^features?[/-]
6161
source-branches:
6262
- develop
6363
- master
@@ -75,7 +75,7 @@ branches:
7575
prevent-increment-of-merged-branch-version: false
7676
tag-number-pattern: '[/-](?<number>\d+)'
7777
track-merge-target: false
78-
regex: (pull|pull\-requests|pr)[/-]
78+
regex: ^(pull|pull\-requests|pr)[/-]
7979
source-branches:
8080
- develop
8181
- master
@@ -92,7 +92,7 @@ branches:
9292
increment: Patch
9393
prevent-increment-of-merged-branch-version: false
9494
track-merge-target: false
95-
regex: hotfix(es)?[/-]
95+
regex: ^hotfix(es)?[/-]
9696
source-branches:
9797
- develop
9898
- master
@@ -106,7 +106,7 @@ branches:
106106
increment: Patch
107107
prevent-increment-of-merged-branch-version: true
108108
track-merge-target: false
109-
regex: support[/-]
109+
regex: ^support[/-]
110110
source-branches:
111111
- master
112112
tracks-release-branches: false

src/GitVersionCore.Tests/IntegrationTests/DevelopScenarios.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using GitTools.Testing;
1+
using GitTools.Testing;
22
using GitVersion;
33
using GitVersionCore.Tests;
44
using LibGit2Sharp;
@@ -183,4 +183,25 @@ public void InheritVersionFromReleaseBranch()
183183
fixture.AssertFullSemver("2.1.0-MyFeature.1+5");
184184
}
185185
}
186-
}
186+
187+
[Test]
188+
public void WhenMultipleDevelopBranchesExistAndCurrentBranchHasIncrementInheritPolicyAndCurrentCommitIsAMerge()
189+
{
190+
using (var fixture = new EmptyRepositoryFixture())
191+
{
192+
fixture.Repository.MakeATaggedCommit("1.0.0");
193+
fixture.Repository.CreateBranch("bob_develop");
194+
fixture.Repository.CreateBranch("develop");
195+
fixture.Repository.CreateBranch("feature/x");
196+
197+
Commands.Checkout(fixture.Repository, "develop");
198+
fixture.Repository.MakeACommit();
199+
200+
Commands.Checkout(fixture.Repository, "feature/x");
201+
fixture.Repository.MakeACommit();
202+
fixture.Repository.MergeNoFF("develop");
203+
204+
fixture.AssertFullSemver("1.0.1-x.1+3");
205+
}
206+
}
207+
}

src/GitVersionCore/Configuration/Config.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public BranchConfig GetConfigForBranch(string branchName)
101101
{
102102
if (branchName == null) throw new ArgumentNullException(nameof(branchName));
103103
var matches = Branches
104-
.Where(b => Regex.IsMatch(branchName, "^" + b.Value.Regex, RegexOptions.IgnoreCase));
104+
.Where(b => Regex.IsMatch(branchName, b.Value.Regex, RegexOptions.IgnoreCase));
105105

106106
try
107107
{

src/GitVersionCore/Configuration/ConfigurationProvider.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ public class ConfigurationProvider
1414
public const string DefaultConfigFileName = "GitVersion.yml";
1515
public const string ObsoleteConfigFileName = "GitVersionConfig.yaml";
1616

17-
public const string ReleaseBranchRegex = "releases?[/-]";
18-
public const string FeatureBranchRegex = "features?[/-]";
19-
public const string PullRequestRegex = @"(pull|pull\-requests|pr)[/-]";
20-
public const string HotfixBranchRegex = "hotfix(es)?[/-]";
21-
public const string SupportBranchRegex = "support[/-]";
22-
public const string DevelopBranchRegex = "dev(elop)?(ment)?$";
23-
public const string MasterBranchRegex = "master$";
17+
public const string ReleaseBranchRegex = "^releases?[/-]";
18+
public const string FeatureBranchRegex = "^features?[/-]";
19+
public const string PullRequestRegex = @"^(pull|pull\-requests|pr)[/-]";
20+
public const string HotfixBranchRegex = "^hotfix(es)?[/-]";
21+
public const string SupportBranchRegex = "^support[/-]";
22+
public const string DevelopBranchRegex = "^dev(elop)?(ment)?$";
23+
public const string MasterBranchRegex = "^master$";
2424
public const string MasterBranchKey = "master";
2525
public const string ReleaseBranchKey = "release";
2626
public const string FeatureBranchKey = "feature";

src/GitVersionCore/Configuration/LegacyConfigNotifier.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public class LegacyConfigNotifier
1717
{ConfigurationProvider.ReleaseBranchRegex, ConfigurationProvider.ReleaseBranchKey},
1818
{ConfigurationProvider.SupportBranchRegex, ConfigurationProvider.SupportBranchKey},
1919
{ConfigurationProvider.PullRequestRegex, ConfigurationProvider.PullRequestBranchKey},
20-
{"release[/-]", ConfigurationProvider.ReleaseBranchKey},
20+
{"dev(elop)?(ment)?$", ConfigurationProvider.DevelopBranchKey },
21+
{"release[/-]", ConfigurationProvider.ReleaseBranchKey },
2122
{"hotfix[/-]", ConfigurationProvider.HotfixBranchKey },
2223
{"feature(s)?[/-]", ConfigurationProvider.FeatureBranchKey },
2324
{"feature[/-]", ConfigurationProvider.FeatureBranchKey }

0 commit comments

Comments
 (0)