Skip to content

Commit b725ab8

Browse files
committed
Implemented branch config keyed by well known keys
1 parent 90e23a0 commit b725ab8

18 files changed

+127
-78
lines changed

docs/configuration.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@ If you don't specify the regex the inbuilt for that branch config will be used (
227227
We don't envision many people needing to change most of these configuration
228228
values, but here they are if you need to:
229229

230+
### regex
231+
This is the regex which is used to match the current branch to the correct branch configuration.
232+
230233
### branches
231234
The header for all the individual branch configuration.
232235

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,61 +17,68 @@ branches:
1717
increment: Patch
1818
prevent-increment-of-merged-branch-version: true
1919
track-merge-target: false
20+
regex: master
2021
is-develop: false
2122
is-release-branch: false
2223
is-mainline: true
23-
releases?[/-]:
24+
release:
2425
mode: ContinuousDelivery
2526
tag: beta
2627
increment: Patch
2728
prevent-increment-of-merged-branch-version: true
2829
track-merge-target: false
30+
regex: releases?[/-]
2931
is-develop: false
3032
is-release-branch: true
3133
is-mainline: false
32-
features?[/-]:
34+
feature:
3335
mode: ContinuousDelivery
3436
tag: useBranchName
3537
increment: Inherit
3638
prevent-increment-of-merged-branch-version: false
3739
track-merge-target: false
40+
regex: features?[/-]
3841
is-develop: false
3942
is-release-branch: false
4043
is-mainline: false
41-
(pull|pull\-requests|pr)[/-]:
44+
pull-request:
4245
mode: ContinuousDelivery
4346
tag: PullRequest
4447
increment: Inherit
4548
prevent-increment-of-merged-branch-version: false
4649
tag-number-pattern: '[/-](?<number>\d+)[-/]'
4750
track-merge-target: false
51+
regex: (pull|pull\-requests|pr)[/-]
4852
is-develop: false
4953
is-release-branch: false
5054
is-mainline: false
51-
hotfix(es)?[/-]:
55+
hotfix:
5256
mode: ContinuousDelivery
5357
tag: beta
5458
increment: Patch
5559
prevent-increment-of-merged-branch-version: false
5660
track-merge-target: false
61+
regex: hotfix(es)?[/-]
5762
is-develop: false
5863
is-release-branch: false
5964
is-mainline: false
60-
support[/-]:
65+
support:
6166
mode: ContinuousDelivery
6267
tag: ''
6368
increment: Patch
6469
prevent-increment-of-merged-branch-version: true
6570
track-merge-target: false
71+
regex: support[/-]
6672
is-develop: false
6773
is-release-branch: false
6874
is-mainline: true
69-
dev(elop)?(ment)?$:
75+
develop:
7076
mode: ContinuousDeployment
7177
tag: alpha
7278
increment: Minor
7379
prevent-increment-of-merged-branch-version: false
7480
track-merge-target: true
81+
regex: dev(elop)?(ment)?$
7582
is-develop: true
7683
is-release-branch: false
7784
is-mainline: false

src/GitVersionCore.Tests/ConfigProviderTests.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using Shouldly;
55
using System;
66
using System.ComponentModel;
7-
using System.Configuration;
87
using System.IO;
98
using System.Linq;
109
using System.Reflection;
@@ -86,7 +85,7 @@ public void CanRemoveTag()
8685
var config = ConfigurationProvider.Provide(repoPath, fileSystem);
8786

8887
config.NextVersion.ShouldBe("2.0.0");
89-
config.Branches["releases?[/-]"].Tag.ShouldBe(string.Empty);
88+
config.Branches["release"].Tag.ShouldBe(string.Empty);
9089
}
9190

9291
[Test]
@@ -98,7 +97,7 @@ public void RegexIsRequired()
9897
bug:
9998
tag: bugfix";
10099
SetupConfigFileContent(text);
101-
var ex = Should.Throw<ConfigurationException>(() => ConfigurationProvider.Provide(repoPath, fileSystem));
100+
var ex = Should.Throw<GitVersionConfigurationException>(() => ConfigurationProvider.Provide(repoPath, fileSystem));
102101
ex.Message.ShouldBe("Branch configuration 'bug' is missing required configuration 'regex'");
103102
}
104103

@@ -109,7 +108,7 @@ public void CanProvideConfigForNewBranch()
109108
next-version: 2.0.0
110109
branches:
111110
bug:
112-
regex: bug[/-]:
111+
regex: 'bug[/-]'
113112
tag: bugfix";
114113
SetupConfigFileContent(text);
115114
var config = ConfigurationProvider.Provide(repoPath, fileSystem);

src/GitVersionCore.Tests/GitVersionContextTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void UsesBranchSpecificConfigOverTopLevelDefaults()
4040
Branches =
4141
{
4242
{
43-
"dev(elop)?(ment)?$", new BranchConfig
43+
"develop", new BranchConfig
4444
{
4545
VersioningMode = VersioningMode.ContinuousDeployment,
4646
Tag = "alpha"
@@ -69,8 +69,8 @@ public void CanFindParentBranchForInheritingIncrementStrategy()
6969
{
7070
Branches =
7171
{
72-
{ "dev(elop)?(ment)?$", new BranchConfig { Increment = IncrementStrategy.Major} },
73-
{ "features?[/-]", new BranchConfig { Increment = IncrementStrategy.Inherit} }
72+
{ "develop", new BranchConfig { Increment = IncrementStrategy.Major} },
73+
{ "feature", new BranchConfig { Increment = IncrementStrategy.Inherit} }
7474
}
7575
}.ApplyDefaults();
7676

src/GitVersionCore.Tests/IntegrationTests/DevelopScenarios.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public void CanChangeDevelopTagViaConfig()
6262
Branches =
6363
{
6464
{
65-
"dev(elop)?(ment)?$", new BranchConfig
65+
"develop", new BranchConfig
6666
{
6767
Tag = "alpha"
6868
}
@@ -128,7 +128,7 @@ public void CanHandleContinuousDelivery()
128128
{
129129
Branches =
130130
{
131-
{"dev(elop)?(ment)?$", new BranchConfig
131+
{"develop", new BranchConfig
132132
{
133133
VersioningMode = VersioningMode.ContinuousDelivery
134134
}

src/GitVersionCore.Tests/IntegrationTests/FeatureBranchScenarios.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void BranchCreatedAfterFastForwardMergeShouldInheritCorrectly()
4141
{
4242
Branches =
4343
{
44-
{ "unstable", new BranchConfig { Increment = IncrementStrategy.Minor } }
44+
{ "unstable", new BranchConfig { Increment = IncrementStrategy.Minor, Regex = "unstable"} }
4545
}
4646
};
4747

@@ -183,7 +183,7 @@ public void ShouldUseConfiguredTag(string tag, string featureName, string preRel
183183
{
184184
Branches =
185185
{
186-
{ "features?[/-]", new BranchConfig { Tag = tag } }
186+
{ "feature", new BranchConfig { Tag = tag } }
187187
}
188188
};
189189

src/GitVersionCore.Tests/IntegrationTests/OtherScenarios.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ public void AllowNotHavingMaster()
4949
public void AllowHavingMainInsteadOfMaster()
5050
{
5151
var config = new Config();
52-
config.Branches.Add("main", new BranchConfig
52+
config.Branches.Add("master", new BranchConfig
5353
{
54+
Regex = "main",
5455
VersioningMode = VersioningMode.ContinuousDelivery,
5556
Tag = "useBranchName",
5657
Increment = IncrementStrategy.Patch,

src/GitVersionCore.Tests/IntegrationTests/ReleaseBranchScenarios.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public void CanTakeVersionFromReleaseBranchWithTagOverridden()
113113
{
114114
Branches =
115115
{
116-
{ "releases?[/-]", new BranchConfig { Tag = "rc" } }
116+
{ "release", new BranchConfig { Tag = "rc" } }
117117
}
118118
};
119119
using (var fixture = new EmptyRepositoryFixture())

src/GitVersionCore.Tests/VersionCalculation/NextVersionCalculatorTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ public void PreReleaseTagCanUseBranchName()
6262
var semanticVersionBuildMetaData = new SemanticVersionBuildMetaData(2, "develop", "b1a34e", DateTimeOffset.Now);
6363
var sut = new NextVersionCalculator(baseCalculator, new TestMetaDataCalculator(semanticVersionBuildMetaData));
6464
var config = new Config();
65-
config.Branches.Add("custom/", new BranchConfig
65+
config.Branches.Add("custom", new BranchConfig
6666
{
67+
Regex = "custom/",
6768
Tag = "useBranchName"
6869
});
6970
var context = new GitVersionContextBuilder()
@@ -84,8 +85,9 @@ public void PreReleaseTagCanUseBranchNameVariable()
8485
var semanticVersionBuildMetaData = new SemanticVersionBuildMetaData(2, "develop", "b1a34e", DateTimeOffset.Now);
8586
var sut = new NextVersionCalculator(baseCalculator, new TestMetaDataCalculator(semanticVersionBuildMetaData));
8687
var config = new Config();
87-
config.Branches.Add("custom/", new BranchConfig
88+
config.Branches.Add("custom", new BranchConfig
8889
{
90+
Regex = "custom/",
8991
Tag = "alpha.{BranchName}"
9092
});
9193
var context = new GitVersionContextBuilder()

src/GitVersionCore/BranchConfigurationCalculator.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ public static KeyValuePair<string, BranchConfig> GetBranchConfiguration(Commit c
1717

1818
if (matchingBranches.Length == 0)
1919
{
20+
Logger.WriteInfo(string.Format(
21+
"No branch configuration found for branch {0}, falling back to default configuration",
22+
currentBranch.FriendlyName));
23+
2024
var branchConfig = new BranchConfig();
21-
ConfigurationProvider.ApplyBranchDefaults(config, branchConfig);
25+
ConfigurationProvider.ApplyBranchDefaults(config, branchConfig, "");
2226
return new KeyValuePair<string, BranchConfig>(string.Empty, branchConfig);
2327
}
2428
if (matchingBranches.Length == 1)
@@ -49,8 +53,8 @@ static KeyValuePair<string, BranchConfig>[] LookupBranchConfiguration([NotNull]
4953
{
5054
throw new ArgumentNullException("currentBranch");
5155
}
52-
53-
return config.Branches.Where(b => Regex.IsMatch(currentBranch.FriendlyName, "^" + b.Key, RegexOptions.IgnoreCase)).ToArray();
56+
57+
return config.Branches.Where(b => Regex.IsMatch(currentBranch.FriendlyName, "^" + b.Value.Regex, RegexOptions.IgnoreCase)).ToArray();
5458
}
5559

5660

0 commit comments

Comments
 (0)