Skip to content

Commit 067d3c4

Browse files
authored
Merge pull request #1029 from JakeGinnivan/namedBranchConfigs
Named branch configuration
2 parents b5b359e + 11aeab1 commit 067d3c4

19 files changed

+213
-121
lines changed

BREAKING CHANGES.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
v4.0.0
2+
- When using GitFlow, a few things have changed. Hopefully the new settings just work for you
3+
- develop has pre-release tag of `alpha` now, not unstable
4+
- develop will bump as soon as a release branch is created
5+
- Look at the [GitFlow examples](http://gitversion.readthedocs.io/en/latest/git-branching-strategies/gitflow-examples/) for details of how it works now
6+
- Regex's are no longer used as keys in branch config
7+
- We have named branches, and introduced a `regex` config which you can override.
8+
- The default keys are: master, develop, feature, release, pull-request, hotfix, support
9+
- Just run GitVersion.exe in your project directory and it will tell you what to change your config keys to
10+
- For example, `dev(elop)?(ment)?$` is now just `develop`, we suggest not overring regex's unless you really want to use a different convention.
11+
112
v3.0.0
213
- NextVersion.txt has been deprecated, only GitVersionConfig.yaml is supported
314
- `AssemblyFileSemVer` variable removed, AssemblyVersioningScheme configuration value makes this variable obsolete

docs/configuration.md

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,21 @@ The header for ignore configuration.
126126

127127
#### sha
128128
A sequence of SHAs to be excluded from the version calculations. Useful when
129-
there is a rogue commit in history yielding a bad version.
129+
there is a rogue commit in history yielding a bad version. You can use either style below:
130+
131+
```
132+
ignore:
133+
sha: [e7bc24c0f34728a25c9187b8d0b041d935763e3a, 764e16321318f2fdb9cdeaa56d1156a1cba307d7]
134+
```
135+
136+
or
137+
138+
```
139+
ignore:
140+
sha:
141+
- e7bc24c0f34728a25c9187b8d0b041d935763e3a
142+
- 764e16321318f2fdb9cdeaa56d1156a1cba307d7
143+
```
130144
131145
#### commits-before
132146
Date and time in the format `yyyy-MM-ddTHH:mm:ss` (eg `commits-before:
@@ -136,33 +150,41 @@ Date and time in the format `yyyy-MM-ddTHH:mm:ss` (eg `commits-before:
136150
## Branch configuration
137151
Then we have branch specific configuration, which looks something like this:
138152
153+
**NOTE: ** v4 changed from using regexes for keys, to named configs
154+
155+
If you have branch specific configuration upgrading to v4 will force you to upgrade.
156+
139157
```yaml
140158
branches:
141159
master:
160+
regex: master
142161
mode: ContinuousDelivery
143162
tag: ''
144163
increment: Patch
145164
prevent-increment-of-merged-branch-version: true
146165
track-merge-target: false
147166
is-develop: false
148167
is-release-branch: false
149-
releases?[/-]:
168+
release:
169+
regex: releases?[/-]
150170
mode: ContinuousDelivery
151171
tag: beta
152172
increment: Patch
153173
prevent-increment-of-merged-branch-version: true
154174
track-merge-target: false
155175
is-develop: false
156176
is-release-branch: true
157-
features?[/-]:
177+
feature:
178+
regex: features?[/-]
158179
mode: ContinuousDelivery
159180
tag: useBranchName
160181
increment: Inherit
161182
prevent-increment-of-merged-branch-version: false
162183
track-merge-target: false
163184
is-develop: false
164185
is-release-branch: false
165-
(pull|pull\-requests|pr)[/-]:
186+
pull-request:
187+
regex: (pull|pull\-requests|pr)[/-]
166188
mode: ContinuousDelivery
167189
tag: PullRequest
168190
increment: Inherit
@@ -171,23 +193,26 @@ branches:
171193
track-merge-target: false
172194
is-develop: false
173195
is-release-branch: false
174-
hotfix(es)?[/-]:
196+
hotfix:
197+
regex: hotfix(es)?[/-]
175198
mode: ContinuousDelivery
176199
tag: beta
177200
increment: Patch
178201
prevent-increment-of-merged-branch-version: false
179202
track-merge-target: false
180203
is-develop: false
181204
is-release-branch: false
182-
support[/-]:
205+
support:
206+
regex: support[/-]
183207
mode: ContinuousDelivery
184208
tag: ''
185209
increment: Patch
186210
prevent-increment-of-merged-branch-version: true
187211
track-merge-target: false
188212
is-develop: false
189213
is-release-branch: false
190-
dev(elop)?(ment)?$:
214+
develop:
215+
regex: dev(elop)?(ment)?$
191216
mode: ContinuousDeployment
192217
tag: unstable
193218
increment: Minor
@@ -197,9 +222,14 @@ branches:
197222
is-release-branch: false
198223
```
199224

225+
If you don't specify the regex the inbuilt for that branch config will be used (recommended)
226+
200227
We don't envision many people needing to change most of these configuration
201228
values, but here they are if you need to:
202229

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

@@ -239,7 +269,7 @@ the branch is configured to use ContinuousDeployment mode.
239269

240270
```yaml
241271
branches:
242-
(pull|pull\-requests|pr)[/-]:
272+
pull-request:
243273
mode: ContinuousDeployment
244274
tag: PullRequest
245275
increment: Inherit

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: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -29,46 +29,28 @@ public void Setup()
2929
}
3030

3131
[Test]
32-
public void CanReadDocumentAndMigrate()
32+
public void CanReadOldDocument()
3333
{
3434
const string text = @"
35-
assembly-versioning-scheme: MajorMinor
36-
next-version: 2.0.0
37-
tag-prefix: '[vV|version-]'
38-
mode: ContinuousDelivery
35+
assemblyVersioningScheme: MajorMinor
36+
develop-branch-tag: alpha
37+
release-branch-tag: rc
3938
branches:
40-
develop:
39+
master:
40+
mode: ContinuousDeployment
41+
dev(elop)?(ment)?$:
4142
mode: ContinuousDeployment
4243
tag: dev
4344
release[/-]:
4445
mode: continuousDeployment
45-
tag: rc
46-
";
47-
SetupConfigFileContent(text);
48-
49-
var config = ConfigurationProvider.Provide(repoPath, fileSystem);
50-
config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinor);
51-
config.AssemblyInformationalFormat.ShouldBe(null);
52-
config.NextVersion.ShouldBe("2.0.0");
53-
config.TagPrefix.ShouldBe("[vV|version-]");
54-
config.VersioningMode.ShouldBe(VersioningMode.ContinuousDelivery);
55-
config.Branches["dev(elop)?(ment)?$"].Tag.ShouldBe("dev");
56-
config.Branches["releases?[/-]"].Tag.ShouldBe("rc");
57-
config.Branches["releases?[/-]"].VersioningMode.ShouldBe(VersioningMode.ContinuousDeployment);
58-
config.Branches["dev(elop)?(ment)?$"].VersioningMode.ShouldBe(VersioningMode.ContinuousDeployment);
59-
}
60-
61-
[Test]
62-
public void CanReadOldDocument()
63-
{
64-
const string text = @"
65-
assemblyVersioningScheme: MajorMinor
66-
develop-branch-tag: alpha
67-
release-branch-tag: rc
46+
tag: rc
6847
";
6948
SetupConfigFileContent(text);
7049
var error = Should.Throw<OldConfigurationException>(() => ConfigurationProvider.Provide(repoPath, fileSystem));
7150
error.Message.ShouldContainWithoutWhitespace(@"GitVersion configuration file contains old configuration, please fix the following errors:
51+
GitVersion branch configs no longer are keyed by regexes, update:
52+
dev(elop)?(ment)?$ -> develop
53+
release[/-] -> release
7254
assemblyVersioningScheme has been replaced by assembly-versioning-scheme
7355
develop-branch-tag has been replaced by branch specific configuration.See http://gitversion.readthedocs.org/en/latest/configuration/#branch-configuration
7456
release-branch-tag has been replaced by branch specific configuration.See http://gitversion.readthedocs.org/en/latest/configuration/#branch-configuration");
@@ -81,16 +63,16 @@ public void OverwritesDefaultsWithProvidedConfig()
8163
const string text = @"
8264
next-version: 2.0.0
8365
branches:
84-
dev(elop)?(ment)?$:
66+
develop:
8567
mode: ContinuousDeployment
8668
tag: dev";
8769
SetupConfigFileContent(text);
8870
var config = ConfigurationProvider.Provide(repoPath, fileSystem);
8971

9072
config.NextVersion.ShouldBe("2.0.0");
91-
config.Branches["dev(elop)?(ment)?$"].Increment.ShouldBe(defaultConfig.Branches["dev(elop)?(ment)?$"].Increment);
92-
config.Branches["dev(elop)?(ment)?$"].VersioningMode.ShouldBe(defaultConfig.Branches["dev(elop)?(ment)?$"].VersioningMode);
93-
config.Branches["dev(elop)?(ment)?$"].Tag.ShouldBe("dev");
73+
config.Branches["develop"].Increment.ShouldBe(defaultConfig.Branches["develop"].Increment);
74+
config.Branches["develop"].VersioningMode.ShouldBe(defaultConfig.Branches["develop"].VersioningMode);
75+
config.Branches["develop"].Tag.ShouldBe("dev");
9476
}
9577

9678
[Test]
@@ -99,13 +81,26 @@ public void CanRemoveTag()
9981
const string text = @"
10082
next-version: 2.0.0
10183
branches:
102-
releases?[/-]:
84+
release:
10385
tag: """"";
10486
SetupConfigFileContent(text);
10587
var config = ConfigurationProvider.Provide(repoPath, fileSystem);
10688

10789
config.NextVersion.ShouldBe("2.0.0");
108-
config.Branches["releases?[/-]"].Tag.ShouldBe(string.Empty);
90+
config.Branches["release"].Tag.ShouldBe(string.Empty);
91+
}
92+
93+
[Test]
94+
public void RegexIsRequired()
95+
{
96+
const string text = @"
97+
next-version: 2.0.0
98+
branches:
99+
bug:
100+
tag: bugfix";
101+
SetupConfigFileContent(text);
102+
var ex = Should.Throw<GitVersionConfigurationException>(() => ConfigurationProvider.Provide(repoPath, fileSystem));
103+
ex.Message.ShouldBe("Branch configuration 'bug' is missing required configuration 'regex'");
109104
}
110105

111106
[Test]
@@ -114,12 +109,14 @@ public void CanProvideConfigForNewBranch()
114109
const string text = @"
115110
next-version: 2.0.0
116111
branches:
117-
bug[/-]:
112+
bug:
113+
regex: 'bug[/-]'
118114
tag: bugfix";
119115
SetupConfigFileContent(text);
120116
var config = ConfigurationProvider.Provide(repoPath, fileSystem);
121117

122-
config.Branches["bug[/-]"].Tag.ShouldBe("bugfix");
118+
config.Branches["bug"].Regex.ShouldBe("bug[/-]");
119+
config.Branches["bug"].Tag.ShouldBe("bugfix");
123120
}
124121

125122
[Test]
@@ -216,8 +213,8 @@ public void CanReadDefaultDocument()
216213
var config = ConfigurationProvider.Provide(repoPath, fileSystem);
217214
config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinorPatch);
218215
config.AssemblyInformationalFormat.ShouldBe(null);
219-
config.Branches["dev(elop)?(ment)?$"].Tag.ShouldBe("alpha");
220-
config.Branches["releases?[/-]"].Tag.ShouldBe("beta");
216+
config.Branches["develop"].Tag.ShouldBe("alpha");
217+
config.Branches["release"].Tag.ShouldBe("beta");
221218
config.TagPrefix.ShouldBe(ConfigurationProvider.DefaultTagPrefix);
222219
config.NextVersion.ShouldBe(null);
223220
}

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
}

0 commit comments

Comments
 (0)