Skip to content

Commit 2f72ea3

Browse files
authored
Merge pull request #3924 from HHobeck/feature/increment-of-the-target-branch-will-be-ignored
The increment of the branch will be ignored when prevent-increment is set to true on the branch
2 parents 6281286 + 6897a3a commit 2f72ea3

File tree

31 files changed

+302
-163
lines changed

31 files changed

+302
-163
lines changed

BREAKING_CHANGES.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
* Default `RegularExpression` for feature branches is changed from `^features?[/-]` to `^features?[/-](?<BranchName>.+)` to support using `{BranchName}` out-of-the-box
4141
* Default `RegularExpression` for unknown branches is changed from `.*` to `(?<BranchName>.+)` to support using `{BranchName}` out-of-the-box
4242
* The `Mainline` mode and the related implementation has been removed completely. The new `TrunkBased` version strategy should be used instead.
43+
* The `TrunkBased` workflow doesn't support downgrading the increment for calculating the next version. This is the case if e.g. a bump messages has been defined which is lower than the branch increment.
4344
* The branch related property `is-mainline` in the configuration system has been renamed to `is-main-branch`
4445
* The versioning mode has been renamed to deployment mode and consists of following values:
4546
* ManualDeployment (previously ContinuousDelivery)
@@ -53,7 +54,7 @@
5354
* VersionInBranchName
5455
* TrunkBased
5556
* The initialization wizard has been removed.
56-
* On the `develop`, `release` and `hotfix` branch the introduced branch related property `prevent-increment-when-current-commit-tagged` has been set to `false` to get the incremented instead of the tagged semantic version.
57+
* On the `develop`, `release` and `hotfix` branch the introduced branch related property `prevent-increment.when-current-commit-tagged` has been set to `false` to get the incremented instead of the tagged semantic version.
5758
5859
## v5.0.0
5960

docs/input/docs/reference/configuration.md

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ branches:
7272
develop:
7373
label: alpha
7474
increment: Minor
75-
prevent-increment-of-merged-branch-version: false
76-
prevent-increment-when-tagged: false
75+
prevent-increment:
76+
when-current-commit-tagged: false
7777
track-merge-target: true
7878
regex: ^dev(elop)?(ment)?$
7979
source-branches: []
@@ -85,7 +85,8 @@ branches:
8585
main:
8686
label: ''
8787
increment: Patch
88-
prevent-increment-of-merged-branch-version: true
88+
prevent-increment:
89+
of-merged-branch: true
8990
track-merge-target: false
9091
regex: ^master$|^main$
9192
source-branches:
@@ -100,8 +101,9 @@ branches:
100101
mode: ManualDeployment
101102
label: beta
102103
increment: None
103-
prevent-increment-of-merged-branch-version: true
104-
prevent-increment-when-tagged: false
104+
prevent-increment:
105+
of-merged-branch: true
106+
when-current-commit-tagged: false
105107
track-merge-target: false
106108
regex: ^releases?[/-]
107109
source-branches:
@@ -118,6 +120,7 @@ branches:
118120
mode: ManualDeployment
119121
label: '{BranchName}'
120122
increment: Inherit
123+
prevent-increment: {}
121124
regex: ^features?[/-](?<BranchName>.+)
122125
source-branches:
123126
- develop
@@ -132,6 +135,7 @@ branches:
132135
mode: ContinuousDelivery
133136
label: PullRequest
134137
increment: Inherit
138+
prevent-increment: {}
135139
label-number-pattern: '[/-](?<number>\d+)'
136140
regex: ^(pull|pull\-requests|pr)[/-]
137141
source-branches:
@@ -147,7 +151,8 @@ branches:
147151
mode: ManualDeployment
148152
label: beta
149153
increment: Inherit
150-
prevent-increment-when-tagged: false
154+
prevent-increment:
155+
when-current-commit-tagged: false
151156
regex: ^hotfix(es)?[/-]
152157
source-branches:
153158
- release
@@ -160,7 +165,8 @@ branches:
160165
support:
161166
label: ''
162167
increment: Patch
163-
prevent-increment-of-merged-branch-version: true
168+
prevent-increment:
169+
of-merged-branch: true
164170
track-merge-target: false
165171
regex: ^support[/-]
166172
source-branches:
@@ -174,6 +180,7 @@ branches:
174180
mode: ManualDeployment
175181
label: '{BranchName}'
176182
increment: Inherit
183+
prevent-increment: {}
177184
regex: (?<BranchName>.+)
178185
source-branches:
179186
- main
@@ -189,8 +196,10 @@ ignore:
189196
mode: ContinuousDelivery
190197
label: '{BranchName}'
191198
increment: Inherit
192-
prevent-increment-of-merged-branch-version: false
193-
prevent-increment-when-tagged: true
199+
prevent-increment:
200+
of-merged-branch: false
201+
when-branch-merged: false
202+
when-current-commit-tagged: true
194203
track-merge-target: false
195204
track-merge-message: true
196205
commit-message-incrementing: Enabled
@@ -200,6 +209,7 @@ is-source-branch-for: []
200209
tracks-release-branches: false
201210
is-release-branch: false
202211
is-main-branch: false
212+
203213
```
204214

205215
The supported built-in configuration for the `GitHubFlow` workflow (`workflow: GitHubFlow/v1`) looks like:
@@ -228,7 +238,8 @@ branches:
228238
main:
229239
label: ''
230240
increment: Patch
231-
prevent-increment-of-merged-branch-version: true
241+
prevent-increment:
242+
of-merged-branch: true
232243
track-merge-target: false
233244
regex: ^master$|^main$
234245
source-branches:
@@ -242,8 +253,9 @@ branches:
242253
mode: ManualDeployment
243254
label: beta
244255
increment: None
245-
prevent-increment-of-merged-branch-version: true
246-
prevent-increment-when-tagged: false
256+
prevent-increment:
257+
of-merged-branch: true
258+
when-current-commit-tagged: false
247259
track-merge-target: false
248260
regex: ^releases?[/-]
249261
source-branches:
@@ -293,8 +305,10 @@ ignore:
293305
mode: ContinuousDelivery
294306
label: '{BranchName}'
295307
increment: Inherit
296-
prevent-increment-of-merged-branch-version: false
297-
prevent-increment-when-tagged: true
308+
prevent-increment:
309+
of-merged-branch: false
310+
when-branch-merged: false
311+
when-current-commit-tagged: true
298312
track-merge-target: false
299313
track-merge-message: true
300314
commit-message-incrementing: Enabled
@@ -330,7 +344,8 @@ branches:
330344
mode: ContinuousDeployment
331345
label: ''
332346
increment: Patch
333-
prevent-increment-of-merged-branch-version: true
347+
prevent-increment:
348+
of-merged-branch: true
334349
track-merge-target: false
335350
regex: ^master$|^main$
336351
source-branches: []
@@ -341,14 +356,16 @@ branches:
341356
feature:
342357
increment: Minor
343358
regex: ^features?[/-](?<BranchName>.+)
344-
prevent-increment-when-tagged: false
359+
prevent-increment:
360+
when-current-commit-tagged: false
345361
source-branches:
346362
- main
347363
pre-release-weight: 30000
348364
hotfix:
349365
increment: Patch
350366
regex: ^hotfix(es)?[/-](?<BranchName>.+)
351-
prevent-increment-when-tagged: false
367+
prevent-increment:
368+
when-current-commit-tagged: false
352369
source-branches:
353370
- main
354371
pre-release-weight: 30000
@@ -375,8 +392,10 @@ ignore:
375392
mode: ManualDeployment
376393
label: '{BranchName}'
377394
increment: Inherit
378-
prevent-increment-of-merged-branch-version: false
379-
prevent-increment-when-tagged: true
395+
prevent-increment:
396+
of-merged-branch: false
397+
when-branch-merged: false
398+
when-current-commit-tagged: true
380399
track-merge-target: false
381400
track-merge-message: true
382401
commit-message-incrementing: Enabled
@@ -467,9 +486,7 @@ increased, such as for commits after a tag: `Major`, `Minor`, `Patch`, `None`.
467486

468487
The special value `Inherit` means that GitVersion should find the parent branch
469488
(i.e. the branch where the current branch was branched from), and use its values
470-
for [increment](#increment),
471-
[prevent-increment-of-merged-branch-version](#prevent-increment-of-merged-branch-version)
472-
and [tracks-release-branches](#tracks-release-branches).
489+
for [increment](#increment) or other branch related properties.
473490

474491
### tag-prefix
475492

@@ -791,7 +808,9 @@ Another example: branch `features/sc-12345/some-description` would become a pre-
791808

792809
Same as for the [global configuration, explained above](#increment).
793810

794-
### prevent-increment-of-merged-branch-version
811+
### prevent-increment-of-merged-branch
812+
813+
The increment of the branch merged to will be ignored, regardless of whether the merged branch has a version number or not, when this branch related property is set to true on the target branch.
795814

796815
When `release-2.0.0` is merged into main, we want main to build `2.0.0`. If
797816
`release-2.0.0` is merged into develop we want it to build `2.1.0`, this option
@@ -802,6 +821,10 @@ In a GitFlow-based repository, setting this option can have implications on the
802821
better version source proposed by the `MergeMessageBaseVersionStrategy`. For
803822
more details and an in-depth analysis, please see [the discussion][2506].
804823

824+
### prevent-increment-when-branch-merged
825+
826+
The increment of the merged branch will be ignored when this branch related property is set to `true` on the source branch.
827+
805828
### prevent-increment-when-current-commit-tagged
806829

807830
This branch related property controls the behvior whether to use the tagged (value set to true) or the incremented (value set to false) semantic version. Defaults to true.

src/GitVersion.Configuration.Tests/Configuration/ConfigurationProviderTests.CanWriteOutEffectiveConfiguration.approved.txt

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ branches:
2121
develop:
2222
label: alpha
2323
increment: Minor
24-
prevent-increment-of-merged-branch-version: false
25-
prevent-increment-when-current-commit-tagged: false
24+
prevent-increment:
25+
when-current-commit-tagged: false
2626
track-merge-target: true
2727
regex: ^dev(elop)?(ment)?$
2828
source-branches: []
@@ -34,7 +34,8 @@ branches:
3434
main:
3535
label: ''
3636
increment: Patch
37-
prevent-increment-of-merged-branch-version: true
37+
prevent-increment:
38+
of-merged-branch: true
3839
track-merge-target: false
3940
regex: ^master$|^main$
4041
source-branches:
@@ -49,8 +50,9 @@ branches:
4950
mode: ManualDeployment
5051
label: beta
5152
increment: None
52-
prevent-increment-of-merged-branch-version: true
53-
prevent-increment-when-current-commit-tagged: false
53+
prevent-increment:
54+
of-merged-branch: true
55+
when-current-commit-tagged: false
5456
track-merge-target: false
5557
regex: ^releases?[/-]
5658
source-branches:
@@ -67,6 +69,7 @@ branches:
6769
mode: ManualDeployment
6870
label: '{BranchName}'
6971
increment: Inherit
72+
prevent-increment: {}
7073
regex: ^features?[/-](?<BranchName>.+)
7174
source-branches:
7275
- develop
@@ -81,6 +84,7 @@ branches:
8184
mode: ContinuousDelivery
8285
label: PullRequest
8386
increment: Inherit
87+
prevent-increment: {}
8488
label-number-pattern: '[/-](?<number>\d+)'
8589
regex: ^(pull|pull\-requests|pr)[/-]
8690
source-branches:
@@ -96,7 +100,8 @@ branches:
96100
mode: ManualDeployment
97101
label: beta
98102
increment: Inherit
99-
prevent-increment-when-current-commit-tagged: false
103+
prevent-increment:
104+
when-current-commit-tagged: false
100105
regex: ^hotfix(es)?[/-]
101106
source-branches:
102107
- release
@@ -109,7 +114,8 @@ branches:
109114
support:
110115
label: ''
111116
increment: Patch
112-
prevent-increment-of-merged-branch-version: true
117+
prevent-increment:
118+
of-merged-branch: true
113119
track-merge-target: false
114120
regex: ^support[/-]
115121
source-branches:
@@ -123,6 +129,7 @@ branches:
123129
mode: ManualDeployment
124130
label: '{BranchName}'
125131
increment: Inherit
132+
prevent-increment: {}
126133
regex: (?<BranchName>.+)
127134
source-branches:
128135
- main
@@ -138,8 +145,10 @@ ignore:
138145
mode: ContinuousDelivery
139146
label: '{BranchName}'
140147
increment: Inherit
141-
prevent-increment-of-merged-branch-version: false
142-
prevent-increment-when-current-commit-tagged: true
148+
prevent-increment:
149+
of-merged-branch: false
150+
when-branch-merged: false
151+
when-current-commit-tagged: true
143152
track-merge-target: false
144153
track-merge-message: true
145154
commit-message-incrementing: Enabled

src/GitVersion.Configuration/BranchConfiguration.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@ internal record BranchConfiguration : IBranchConfiguration
1818
[JsonPropertyDescription("The increment strategy for this branch. Can be 'Inherit', 'Patch', 'Minor', 'Major', 'None'.")]
1919
public IncrementStrategy Increment { get; internal set; }
2020

21-
[JsonPropertyName("prevent-increment-of-merged-branch-version")]
22-
[JsonPropertyDescription("Prevent increment of merged branch version.")]
23-
public bool? PreventIncrementOfMergedBranchVersion { get; internal set; }
21+
[JsonIgnore]
22+
IPreventIncrementConfiguration IBranchConfiguration.PreventIncrement => PreventIncrement;
2423

25-
[JsonPropertyName("prevent-increment-when-current-commit-tagged")]
26-
[JsonPropertyDescription("This branch related property controls the behvior whether to use the tagged (value set to true) or the incremented (value set to false) semantic version. Defaults to true.")]
27-
public bool? PreventIncrementWhenCurrentCommitTagged { get; internal set; }
24+
[JsonPropertyName("prevent-increment")]
25+
[JsonPropertyDescription("The prevent increment configuration section.")]
26+
public PreventIncrementConfiguration PreventIncrement { get; internal set; } = new();
2827

2928
[JsonPropertyName("label-number-pattern")]
3029
[JsonPropertyDescription($"The regular expression pattern to use to extract the number from the branch name. Defaults to '{ConfigurationConstants.DefaultLabelNumberPattern}'.")]
@@ -91,10 +90,12 @@ public virtual IBranchConfiguration Inherit(IBranchConfiguration configuration)
9190
Increment = Increment == IncrementStrategy.Inherit ? configuration.Increment : Increment,
9291
DeploymentMode = DeploymentMode ?? configuration.DeploymentMode,
9392
Label = Label ?? configuration.Label,
94-
PreventIncrementOfMergedBranchVersion = PreventIncrementOfMergedBranchVersion
95-
?? configuration.PreventIncrementOfMergedBranchVersion,
96-
PreventIncrementWhenCurrentCommitTagged = PreventIncrementWhenCurrentCommitTagged
97-
?? configuration.PreventIncrementWhenCurrentCommitTagged,
93+
PreventIncrement = new PreventIncrementConfiguration()
94+
{
95+
OfMergedBranch = PreventIncrement.OfMergedBranch ?? configuration.PreventIncrement.OfMergedBranch,
96+
WhenBranchMerged = PreventIncrement.WhenBranchMerged ?? configuration.PreventIncrement.WhenBranchMerged,
97+
WhenCurrentCommitTagged = PreventIncrement.WhenCurrentCommitTagged ?? configuration.PreventIncrement.WhenCurrentCommitTagged
98+
},
9899
LabelNumberPattern = LabelNumberPattern ?? configuration.LabelNumberPattern,
99100
TrackMergeTarget = TrackMergeTarget ?? configuration.TrackMergeTarget,
100101
TrackMergeMessage = TrackMergeMessage ?? configuration.TrackMergeMessage,

0 commit comments

Comments
 (0)