Skip to content

Commit ad400b7

Browse files
committed
Same version computed on different branches
1 parent f185574 commit ad400b7

23 files changed

+127
-25
lines changed

docs/input/docs/reference/configuration.md

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ The global configuration looks like this:
4343
assembly-versioning-scheme: MajorMinorPatch
4444
assembly-file-versioning-scheme: MajorMinorPatch
4545
tag-prefix: '[vV]?'
46+
version-in-branch-pattern: (?<version>[vV]?\d+(\.\d+)?(\.\d+)?).*
4647
major-version-bump-message: '\+semver:\s?(breaking|major)'
4748
minor-version-bump-message: '\+semver:\s?(feature|minor)'
4849
patch-version-bump-message: '\+semver:\s?(fix|patch)'
@@ -52,16 +53,22 @@ commit-date-format: yyyy-MM-dd
5253
merge-message-formats: {}
5354
update-build-number: true
5455
semantic-version-format: Strict
55-
strategies: [ConfigNext, MergeMessage, TaggedCommit, TrackReleaseBranches, VersionInBranchName]
56+
strategies:
57+
- ConfiguredNextVersion
58+
- MergeMessage
59+
- TaggedCommit
60+
- TrackReleaseBranches
61+
- VersionInBranchName
5662
branches:
5763
develop:
58-
mode: ContinuousDeployment
64+
take-incremented-version: TakeAlwaysIncrementedVersion
5965
label: alpha
6066
increment: Minor
6167
prevent-increment-of-merged-branch-version: false
6268
track-merge-target: true
6369
regex: ^dev(elop)?(ment)?$
6470
source-branches: []
71+
is-source-branch-for: []
6572
tracks-release-branches: true
6673
is-release-branch: false
6774
is-main-branch: false
@@ -75,11 +82,14 @@ branches:
7582
source-branches:
7683
- develop
7784
- release
85+
is-source-branch-for: []
7886
tracks-release-branches: false
7987
is-release-branch: false
8088
is-main-branch: true
8189
pre-release-weight: 55000
8290
release:
91+
mode: ManualDeployment
92+
take-incremented-version: TakeAlwaysIncrementedVersion
8393
label: beta
8494
increment: None
8595
prevent-increment-of-merged-branch-version: true
@@ -90,12 +100,13 @@ branches:
90100
- main
91101
- support
92102
- release
103+
is-source-branch-for: []
93104
tracks-release-branches: false
94105
is-release-branch: true
95106
is-main-branch: false
96107
pre-release-weight: 30000
97108
feature:
98-
mode: ContinuousDelivery
109+
mode: ManualDeployment
99110
label: '{BranchName}'
100111
increment: Inherit
101112
regex: ^features?[/-](?<BranchName>.+)
@@ -106,6 +117,7 @@ branches:
106117
- feature
107118
- support
108119
- hotfix
120+
is-source-branch-for: []
109121
pre-release-weight: 30000
110122
pull-request:
111123
mode: ContinuousDelivery
@@ -120,9 +132,10 @@ branches:
120132
- feature
121133
- support
122134
- hotfix
135+
is-source-branch-for: []
123136
pre-release-weight: 30000
124137
hotfix:
125-
mode: ContinuousDelivery
138+
mode: ManualDeployment
126139
label: beta
127140
increment: Inherit
128141
regex: ^hotfix(es)?[/-]
@@ -131,6 +144,8 @@ branches:
131144
- main
132145
- support
133146
- hotfix
147+
is-source-branch-for: []
148+
is-release-branch: true
134149
pre-release-weight: 30000
135150
support:
136151
label: ''
@@ -140,15 +155,16 @@ branches:
140155
regex: ^support[/-]
141156
source-branches:
142157
- main
158+
is-source-branch-for: []
143159
tracks-release-branches: false
144160
is-release-branch: false
145161
is-main-branch: true
146162
pre-release-weight: 55000
147163
unknown:
148-
mode: ContinuousDelivery
164+
mode: ManualDeployment
149165
label: '{BranchName}'
150166
increment: Inherit
151-
regex: (?<BranchName>.*)
167+
regex: (?<BranchName>.+)
152168
source-branches:
153169
- main
154170
- develop
@@ -157,16 +173,20 @@ branches:
157173
- pull-request
158174
- hotfix
159175
- support
176+
is-source-branch-for: []
160177
ignore:
161178
sha: []
162179
mode: ContinuousDelivery
180+
take-incremented-version: TakeTaggedOtherwiseIncrementedVersion
163181
label: '{BranchName}'
164182
increment: Inherit
165183
prevent-increment-of-merged-branch-version: false
166184
track-merge-target: false
167185
track-merge-message: true
168186
commit-message-incrementing: Enabled
169187
regex: ''
188+
source-branches: []
189+
is-source-branch-for: []
170190
tracks-release-branches: false
171191
is-release-branch: false
172192
is-main-branch: false
@@ -244,7 +264,11 @@ The default value is `{InformationalVersion}`.
244264
### mode
245265

246266
Sets the `mode` of how GitVersion should create a new version. Read more at
247-
[versioning modes][modes].
267+
[deployment modes][modes].
268+
269+
### take-incremented-version
270+
271+
This branch related property can be used to control the behavior weither to take the incremented or the tagged version.
248272

249273
### increment
250274

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ strategies:
1919
- VersionInBranchName
2020
branches:
2121
develop:
22+
take-incremented-version: TakeAlwaysIncrementedVersion
2223
label: alpha
2324
increment: Minor
2425
prevent-increment-of-merged-branch-version: false
@@ -46,6 +47,7 @@ branches:
4647
pre-release-weight: 55000
4748
release:
4849
mode: ManualDeployment
50+
take-incremented-version: TakeAlwaysIncrementedVersion
4951
label: beta
5052
increment: None
5153
prevent-increment-of-merged-branch-version: true
@@ -133,6 +135,7 @@ branches:
133135
ignore:
134136
sha: []
135137
mode: ContinuousDelivery
138+
take-incremented-version: TakeTaggedOtherwiseIncrementedVersion
136139
label: '{BranchName}'
137140
increment: Inherit
138141
prevent-increment-of-merged-branch-version: false

src/GitVersion.Configuration/BranchConfiguration.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ internal record BranchConfiguration : IBranchConfiguration
1010
[JsonPropertyDescription("The deployment mode for this branch. Can be 'ManualDeployment', 'ContinuousDelivery', 'ContinuousDeployment'.")]
1111
public DeploymentMode? DeploymentMode { get; internal set; }
1212

13+
[JsonPropertyName("take-incremented-version")]
14+
[JsonPropertyDescription("Option to control which version should be taken for this branch. Can be 'TakeAlwaysBaseVersion', 'TakeTaggedOtherwiseIncrementedVersion', 'TakeAlwaysIncrementedVersion'.")]
15+
public TakeIncrementedVersion? TakeIncrementedVersion { get; internal set; }
16+
1317
[JsonPropertyName("label")]
1418
[JsonPropertyDescription("The label to use for this branch. Use the value {BranchName} or similar as a placeholder to insert a named capture group from RegularExpression (fx. the branch name).")]
1519
public string? Label { get; internal set; }
@@ -86,6 +90,7 @@ public virtual IBranchConfiguration Inherit(IBranchConfiguration configuration)
8690
{
8791
Increment = Increment == IncrementStrategy.Inherit ? configuration.Increment : Increment,
8892
DeploymentMode = DeploymentMode ?? configuration.DeploymentMode,
93+
TakeIncrementedVersion = TakeIncrementedVersion ?? configuration.TakeIncrementedVersion,
8994
Label = Label ?? configuration.Label,
9095
PreventIncrementOfMergedBranchVersion = PreventIncrementOfMergedBranchVersion
9196
?? configuration.PreventIncrementOfMergedBranchVersion,

src/GitVersion.Configuration/BranchConfigurationBuilder.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ internal class BranchConfigurationBuilder
77
public static BranchConfigurationBuilder New => new();
88

99
private DeploymentMode? deploymentMode;
10+
private TakeIncrementedVersion? takeIncrementedVersion;
1011
private string? label;
1112
private IncrementStrategy increment;
1213
private bool? preventIncrementOfMergedBranchVersion;
@@ -32,6 +33,12 @@ public virtual BranchConfigurationBuilder WithDeploymentMode(DeploymentMode? val
3233
return this;
3334
}
3435

36+
public virtual BranchConfigurationBuilder WithTakeIncrementedVersion(TakeIncrementedVersion? value)
37+
{
38+
this.takeIncrementedVersion = value;
39+
return this;
40+
}
41+
3542
public virtual BranchConfigurationBuilder WithLabel(string? value)
3643
{
3744
this.label = value;
@@ -131,6 +138,7 @@ public virtual BranchConfigurationBuilder WithPreReleaseWeight(int? value)
131138
public virtual BranchConfigurationBuilder WithConfiguration(IBranchConfiguration value)
132139
{
133140
WithDeploymentMode(value.DeploymentMode);
141+
WithTakeIncrementedVersion(value.TakeIncrementedVersion);
134142
WithLabel(value.Label);
135143
WithIncrement(value.Increment);
136144
WithPreventIncrementOfMergedBranchVersion(value.PreventIncrementOfMergedBranchVersion);
@@ -151,6 +159,7 @@ public virtual BranchConfigurationBuilder WithConfiguration(IBranchConfiguration
151159
public IBranchConfiguration Build() => new BranchConfiguration
152160
{
153161
DeploymentMode = deploymentMode,
162+
TakeIncrementedVersion = takeIncrementedVersion,
154163
Label = label,
155164
Increment = increment,
156165
RegularExpression = regularExpression,

src/GitVersion.Configuration/ConfigurationBuilderBase.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ internal abstract class ConfigurationBuilderBase<TConfigurationBuilder> : IConfi
2929
private readonly List<IReadOnlyDictionary<object, object?>> overrides = new();
3030
private readonly Dictionary<string, BranchConfigurationBuilder> branchConfigurationBuilders = new();
3131
private DeploymentMode? versioningMode;
32+
private TakeIncrementedVersion? takeIncrementedVersion;
3233
private string? label;
3334
private IncrementStrategy increment = IncrementStrategy.Inherit;
3435
private bool? preventIncrementOfMergedBranchVersion;
@@ -237,6 +238,12 @@ public virtual TConfigurationBuilder WithDeploymentMode(DeploymentMode? value)
237238
return (TConfigurationBuilder)this;
238239
}
239240

241+
public virtual TConfigurationBuilder WithTakeIncrementedVersion(TakeIncrementedVersion? value)
242+
{
243+
this.takeIncrementedVersion = value;
244+
return (TConfigurationBuilder)this;
245+
}
246+
240247
public virtual TConfigurationBuilder WithLabel(string? value)
241248
{
242249
this.label = value;
@@ -335,6 +342,7 @@ public virtual TConfigurationBuilder WithConfiguration(IGitVersionConfiguration
335342
WithBranch(name).WithConfiguration(branchConfiguration);
336343
}
337344
WithDeploymentMode(value.DeploymentMode);
345+
WithTakeIncrementedVersion(value.TakeIncrementedVersion);
338346
WithLabel(value.Label);
339347
WithIncrement(value.Increment);
340348
WithPreventIncrementOfMergedBranchVersion(value.PreventIncrementOfMergedBranchVersion);
@@ -393,6 +401,7 @@ public virtual IGitVersionConfiguration Build()
393401
Branches = branches,
394402
MergeMessageFormats = this.mergeMessageFormats,
395403
DeploymentMode = this.versioningMode,
404+
TakeIncrementedVersion = this.takeIncrementedVersion,
396405
Label = this.label,
397406
Increment = this.increment,
398407
RegularExpression = this.regularExpression,

src/GitVersion.Configuration/GitFlowConfigurationBuilder.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ private GitFlowConfigurationBuilder()
2424
TagPreReleaseWeight = ConfigurationConstants.DefaultTagPreReleaseWeight,
2525
UpdateBuildNumber = ConfigurationConstants.DefaultUpdateBuildNumber,
2626
DeploymentMode = DeploymentMode.ContinuousDelivery,
27+
TakeIncrementedVersion = TakeIncrementedVersion.TakeTaggedOtherwiseIncrementedVersion,
2728
RegularExpression = string.Empty,
2829
Label = ConfigurationConstants.BranchNamePlaceholder,
2930
Increment = IncrementStrategy.Inherit,
@@ -39,6 +40,7 @@ private GitFlowConfigurationBuilder()
3940
WithBranch(DevelopBranch.Name).WithConfiguration(new BranchConfiguration
4041
{
4142
Increment = IncrementStrategy.Minor,
43+
TakeIncrementedVersion = TakeIncrementedVersion.TakeAlwaysIncrementedVersion,
4244
RegularExpression = DevelopBranch.RegexPattern,
4345
SourceBranches = [],
4446
Label = "alpha",
@@ -71,6 +73,7 @@ private GitFlowConfigurationBuilder()
7173
WithBranch(ReleaseBranch.Name).WithConfiguration(new BranchConfiguration
7274
{
7375
Increment = IncrementStrategy.None,
76+
TakeIncrementedVersion = TakeIncrementedVersion.TakeAlwaysIncrementedVersion,
7477
DeploymentMode = DeploymentMode.ManualDeployment,
7578
RegularExpression = ReleaseBranch.RegexPattern,
7679
SourceBranches =

src/GitVersion.Configuration/GitHubFlowConfigurationBuilder.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ private GitHubFlowConfigurationBuilder()
2727
RegularExpression = string.Empty,
2828
Label = ConfigurationConstants.BranchNamePlaceholder,
2929
Increment = IncrementStrategy.Inherit,
30+
TakeIncrementedVersion = TakeIncrementedVersion.TakeTaggedOtherwiseIncrementedVersion,
3031
CommitMessageIncrementing = CommitMessageIncrementMode.Enabled,
3132
PreventIncrementOfMergedBranchVersion = false,
3233
TrackMergeTarget = false,
@@ -53,6 +54,7 @@ private GitHubFlowConfigurationBuilder()
5354
WithBranch(ReleaseBranch.Name).WithConfiguration(new BranchConfiguration
5455
{
5556
Increment = IncrementStrategy.None,
57+
TakeIncrementedVersion = TakeIncrementedVersion.TakeAlwaysIncrementedVersion,
5658
RegularExpression = ReleaseBranch.RegexPattern,
5759
DeploymentMode = DeploymentMode.ManualDeployment,
5860
SourceBranches =

src/GitVersion.Configuration/SupportedWorkflows/GitFlow/v1.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ strategies:
1919
- VersionInBranchName
2020
branches:
2121
develop:
22+
take-incremented-version: TakeAlwaysIncrementedVersion
2223
label: alpha
2324
increment: Minor
2425
prevent-increment-of-merged-branch-version: false
2526
track-merge-target: true
2627
regex: ^dev(elop)?(ment)?$
2728
source-branches: []
29+
is-source-branch-for: []
2830
tracks-release-branches: true
2931
is-release-branch: false
3032
is-main-branch: false
@@ -38,12 +40,14 @@ branches:
3840
source-branches:
3941
- develop
4042
- release
43+
is-source-branch-for: []
4144
tracks-release-branches: false
4245
is-release-branch: false
4346
is-main-branch: true
4447
pre-release-weight: 55000
4548
release:
4649
mode: ManualDeployment
50+
take-incremented-version: TakeAlwaysIncrementedVersion
4751
label: beta
4852
increment: None
4953
prevent-increment-of-merged-branch-version: true
@@ -54,6 +58,7 @@ branches:
5458
- main
5559
- support
5660
- release
61+
is-source-branch-for: []
5762
tracks-release-branches: false
5863
is-release-branch: true
5964
is-main-branch: false
@@ -70,6 +75,7 @@ branches:
7075
- feature
7176
- support
7277
- hotfix
78+
is-source-branch-for: []
7379
pre-release-weight: 30000
7480
pull-request:
7581
mode: ContinuousDelivery
@@ -84,6 +90,7 @@ branches:
8490
- feature
8591
- support
8692
- hotfix
93+
is-source-branch-for: []
8794
pre-release-weight: 30000
8895
hotfix:
8996
mode: ManualDeployment
@@ -95,6 +102,7 @@ branches:
95102
- main
96103
- support
97104
- hotfix
105+
is-source-branch-for: []
98106
is-release-branch: true
99107
pre-release-weight: 30000
100108
support:
@@ -105,6 +113,7 @@ branches:
105113
regex: ^support[/-]
106114
source-branches:
107115
- main
116+
is-source-branch-for: []
108117
tracks-release-branches: false
109118
is-release-branch: false
110119
is-main-branch: true
@@ -122,16 +131,20 @@ branches:
122131
- pull-request
123132
- hotfix
124133
- support
134+
is-source-branch-for: []
125135
ignore:
126136
sha: []
127137
mode: ContinuousDelivery
138+
take-incremented-version: TakeTaggedOtherwiseIncrementedVersion
128139
label: '{BranchName}'
129140
increment: Inherit
130141
prevent-increment-of-merged-branch-version: false
131142
track-merge-target: false
132143
track-merge-message: true
133144
commit-message-incrementing: Enabled
134145
regex: ''
146+
source-branches: []
147+
is-source-branch-for: []
135148
tracks-release-branches: false
136149
is-release-branch: false
137150
is-main-branch: false

0 commit comments

Comments
 (0)