Skip to content

Commit 03271d6

Browse files
authored
Merge pull request #3455 from HHobeck/feature/2693_VersionInBranchNameVersionStrategy_only_considers_the_release_branch
Fix bug: VersionInBranchNameVersionStrategy only considers the release branch
2 parents 4e6051a + 3795785 commit 03271d6

33 files changed

+247
-99
lines changed

BREAKING_CHANGES.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
* Following root configuration properties have been removed:
2424
* continuous-delivery-fallback-tag
2525
* A new branch related property with name `track-merge-message` has been introduced. Consider we have a `main` branch and a `release/1.0.0` branch and merge changes from `release/1.0.0` to the main branch. In this scenario the merge message will be interpreted as a next version `1.0.0` when `track-merge-message` is set to `true` otherwise `0.0.1`.
26-
* The pre-release tags are only considered when they are matching with the label name of the branch. This has an effect on the way how the `CommitCountSource` will be determined.
27-
* The process of increasing the version with bump message when `CommitMessageIncrementing` is enabled and increment strategy is `None` has been changed.
26+
* The pre-release tags are only considered when they are matching with the label name of the branch. This has an effect on the way how the `CommitCountSource` will be determined.
27+
* The process of increasing the version with bump message when `CommitMessageIncrementing` is enabled and increment strategy is `None` has been changed.
28+
* A new configuration property with name `version-in-branch-pattern` has been introduced. This setting only applies on branches where the option `is-release-branch` is set to `true`. Please notice that the branch name needs to be defined after the version number by default (instead of `support/lts-2.0.0` please name the branch like `support/2.0.0-lts`).
29+
* The `is-release-branch` property of the `hotfix` branch setting has been changed from `false` to `true`. If present the hotfix number will be considered now by default.
2830
2931
## v5.0.0
3032

docs/input/docs/reference/configuration.md

Lines changed: 21 additions & 3 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
label-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)'
@@ -61,6 +62,7 @@ branches:
6162
track-merge-target: true
6263
regex: ^dev(elop)?(ment)?$
6364
source-branches: []
65+
is-source-branch-for: []
6466
tracks-release-branches: true
6567
is-release-branch: false
6668
is-mainline: false
@@ -74,6 +76,7 @@ branches:
7476
source-branches:
7577
- develop
7678
- release
79+
is-source-branch-for: []
7780
tracks-release-branches: false
7881
is-release-branch: false
7982
is-mainline: true
@@ -89,6 +92,7 @@ branches:
8992
- main
9093
- support
9194
- release
95+
is-source-branch-for: []
9296
tracks-release-branches: false
9397
is-release-branch: true
9498
is-mainline: false
@@ -105,6 +109,7 @@ branches:
105109
- feature
106110
- support
107111
- hotfix
112+
is-source-branch-for: []
108113
pre-release-weight: 30000
109114
pull-request:
110115
mode: ContinuousDelivery
@@ -119,6 +124,7 @@ branches:
119124
- feature
120125
- support
121126
- hotfix
127+
is-source-branch-for: []
122128
pre-release-weight: 30000
123129
hotfix:
124130
mode: ContinuousDelivery
@@ -130,6 +136,8 @@ branches:
130136
- main
131137
- support
132138
- hotfix
139+
is-source-branch-for: []
140+
is-release-branch: true
133141
pre-release-weight: 30000
134142
support:
135143
label: ''
@@ -139,6 +147,7 @@ branches:
139147
regex: ^support[/-]
140148
source-branches:
141149
- main
150+
is-source-branch-for: []
142151
tracks-release-branches: false
143152
is-release-branch: false
144153
is-mainline: true
@@ -156,6 +165,7 @@ branches:
156165
- pull-request
157166
- hotfix
158167
- support
168+
is-source-branch-for: []
159169
ignore:
160170
sha: []
161171
mode: ContinuousDelivery
@@ -166,6 +176,8 @@ track-merge-target: false
166176
track-merge-message: true
167177
commit-message-incrementing: Enabled
168178
regex: ''
179+
source-branches: []
180+
is-source-branch-for: []
169181
tracks-release-branches: false
170182
is-release-branch: false
171183
is-mainline: false
@@ -258,9 +270,15 @@ and [tracks-release-branches](#tracks-release-branches).
258270

259271
### label-prefix
260272

261-
A regex which is used to trim Git tags before processing (e.g., v1.0.0). Default
262-
is `[vV]`, although this is just for illustrative purposes as we do a IgnoreCase
263-
match and could be `v`.
273+
A regular expression which is used to trim Git tags before processing (e.g.,
274+
v1.0.0). The default value is `[vV]`.
275+
276+
### version-in-branch-pattern
277+
278+
A regular expression which is used to determine the version number in the branch
279+
name or commit message (e.g., v1.0.0-LTS). This setting only applies on branches
280+
where the option `is-release-branch` is set to `true`. The default value is
281+
`(?<version>[vV]?\d+(\.\d+)?(\.\d+)?).*`.
264282

265283
### major-version-bump-message
266284

new-cli/Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
<ItemGroup>
1818
<Using Include="System.Collections"/>
19+
<Using Include="System.Text"/>
1920
</ItemGroup>
2021

2122
</Project>

new-cli/GitVersion.Common/GitVersion.Common.csproj

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<PackageReference Include="Polly" />
44
</ItemGroup>
55
<ItemGroup>
6+
<Compile Include="..\..\src\GitVersion.Core\Extensions\StringExtensions.cs" Link="Extensions\StringExtensions.cs" />
67
<Compile Include="..\..\src\GitVersion.Core\Git\AuthenticationInfo.cs">
78
<Link>Git\AuthenticationInfo.cs</Link>
89
</Compile>
@@ -63,5 +64,23 @@
6364
<Compile Include="..\..\src\GitVersion.Core\Git\RefSpecDirection.cs">
6465
<Link>Git\RefSpecDirection.cs</Link>
6566
</Compile>
67+
<Compile Include="..\..\src\GitVersion.Core\Git\SemanticVersion.cs">
68+
<Link>Git\SemanticVersion.cs</Link>
69+
</Compile>
70+
<Compile Include="..\..\src\GitVersion.Core\Git\SemanticVersionBuildMetaData.cs">
71+
<Link>Git\SemanticVersionBuildMetaData.cs</Link>
72+
</Compile>
73+
<Compile Include="..\..\src\GitVersion.Core\Git\SemanticVersionFormat.cs">
74+
<Link>Git\SemanticVersionFormat.cs</Link>
75+
</Compile>
76+
<Compile Include="..\..\src\GitVersion.Core\Git\SemanticVersionPreReleaseTag.cs">
77+
<Link>Git\SemanticVersionPreReleaseTag.cs</Link>
78+
</Compile>
79+
<Compile Include="..\..\src\GitVersion.Core\Git\VersionField.cs">
80+
<Link>Git\VersionField.cs</Link>
81+
</Compile>
82+
<Compile Include="..\..\src\GitVersion.Core\Git\WarningException.cs">
83+
<Link>Git\WarningException.cs</Link>
84+
</Compile>
6685
</ItemGroup>
6786
</Project>

new-cli/GitVersion.Common/Helpers/EncodingHelper.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using System.Text;
2-
31
namespace GitVersion.Helpers;
42

53
public static class EncodingHelper

new-cli/GitVersion.Common/Infrastructure/IFileSystem.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using System.Text;
2-
31
namespace GitVersion.Infrastructure;
42

53
public interface IFileSystem

new-cli/GitVersion.Core/Infrastructure/FileSystem.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Text;
21
using GitVersion.Helpers;
32

43
namespace GitVersion.Infrastructure;

schemas/6.0/GitVersion.configuration.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@
161161
"description": "Whether to update the build number in the project file. Defaults to true.",
162162
"type": "boolean"
163163
},
164+
"version-in-branch-pattern": {
165+
"description": "A regular expression which is used to determine the version number in the branch name or commit message (e.g., v1.0.0-LTS). The default value is \u0027(?\u003Cversion\u003E[vV]?\\d\u002B(\\.\\d\u002B)?(\\.\\d\u002B)?).*\u0027.",
166+
"type": "string"
167+
},
164168
"mode": {
165169
"$ref": "#/$defs/Nullable\u006018"
166170
},

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
assembly-versioning-scheme: MajorMinorPatch
22
assembly-file-versioning-scheme: MajorMinorPatch
33
label-prefix: '[vV]?'
4+
version-in-branch-pattern: (?<version>[vV]?\d+(\.\d+)?(\.\d+)?).*
45
major-version-bump-message: '\+semver:\s?(breaking|major)'
56
minor-version-bump-message: '\+semver:\s?(feature|minor)'
67
patch-version-bump-message: '\+semver:\s?(fix|patch)'
@@ -94,6 +95,7 @@ branches:
9495
- support
9596
- hotfix
9697
is-source-branch-for: []
98+
is-release-branch: true
9799
pre-release-weight: 30000
98100
support:
99101
label: ''

src/GitVersion.Core.Tests/IntegrationTests/HotfixBranchScenarios.cs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public void CanTakeVersionFromHotfixesBranch()
6060

6161
// create hotfix branch
6262
Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("hotfixes/1.1.1"));
63-
fixture.AssertFullSemver("1.1.0"); // We are still on a tagged commit
63+
fixture.AssertFullSemver("1.1.1+0");
6464
fixture.Repository.MakeACommit();
6565

6666
fixture.AssertFullSemver("1.1.1-beta.1+1");
@@ -78,44 +78,44 @@ public void PatchOlderReleaseExample()
7878
r.MakeATaggedCommit("2.0.0");
7979
});
8080
// Merge hotfix branch to support
81-
Commands.Checkout(fixture.Repository, MainBranch);
81+
fixture.Checkout(MainBranch);
8282
var tag = fixture.Repository.Tags.Single(t => t.FriendlyName == "1.1.0");
83-
var supportBranch = fixture.Repository.CreateBranch("support-1.1", (LibGit2Sharp.Commit)tag.Target);
84-
Commands.Checkout(fixture.Repository, supportBranch);
83+
fixture.Repository.CreateBranch("support-1.1", (LibGit2Sharp.Commit)tag.Target);
84+
fixture.Checkout("support-1.1");
8585
fixture.AssertFullSemver("1.1.0");
8686

8787
// create hotfix branch
88-
Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("hotfix-1.1.1"));
89-
fixture.AssertFullSemver("1.1.0"); // We are still on a tagged commit
90-
fixture.Repository.MakeACommit();
88+
fixture.BranchTo("hotfix-1.1.1");
89+
fixture.AssertFullSemver("1.1.1+0");
90+
fixture.MakeACommit();
9191

9292
fixture.AssertFullSemver("1.1.1-beta.1+1");
93-
fixture.Repository.MakeACommit();
93+
fixture.MakeACommit();
9494
fixture.AssertFullSemver("1.1.1-beta.1+2");
9595

9696
// Create feature branch off hotfix branch and complete
97-
Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("feature/fix"));
97+
fixture.BranchTo("feature/fix");
9898
fixture.AssertFullSemver("1.1.1-fix.1+2");
99-
fixture.Repository.MakeACommit();
99+
fixture.MakeACommit();
100100
fixture.AssertFullSemver("1.1.1-fix.1+3");
101101

102102
fixture.Repository.CreatePullRequestRef("feature/fix", "hotfix-1.1.1", prNumber: 8, normalise: true);
103103
fixture.AssertFullSemver("1.1.1-PullRequest8.4");
104-
Commands.Checkout(fixture.Repository, "hotfix-1.1.1");
105-
fixture.Repository.MergeNoFF("feature/fix", Generate.SignatureNow());
104+
fixture.Checkout("hotfix-1.1.1");
105+
fixture.MergeNoFF("feature/fix");
106106
fixture.AssertFullSemver("1.1.1-beta.1+4");
107107

108108
// Merge hotfix into support branch to complete hotfix
109-
Commands.Checkout(fixture.Repository, "support-1.1");
110-
fixture.Repository.MergeNoFF("hotfix-1.1.1", Generate.SignatureNow());
109+
fixture.Checkout("support-1.1");
110+
fixture.MergeNoFF("hotfix-1.1.1");
111111
fixture.AssertFullSemver("1.1.1+5");
112-
fixture.Repository.ApplyTag("1.1.1");
112+
fixture.ApplyTag("1.1.1");
113113
fixture.AssertFullSemver("1.1.1");
114114

115115
// Verify develop version
116-
Commands.Checkout(fixture.Repository, "develop");
116+
fixture.Checkout("develop");
117117
fixture.AssertFullSemver("2.1.0-alpha.1");
118-
fixture.Repository.MergeNoFF("support-1.1", Generate.SignatureNow());
118+
fixture.MergeNoFF("support-1.1");
119119
fixture.AssertFullSemver("2.1.0-alpha.7");
120120
}
121121

@@ -167,7 +167,7 @@ public void FeatureOnHotfixFeatureBranchDeleted()
167167
fixture.Checkout(hotfix451);
168168
fixture.MergeNoFF(featureBranch); // commit 2
169169
fixture.Repository.Branches.Remove(featureBranch);
170-
fixture.AssertFullSemver("4.5.1-beta.2", configuration);
170+
fixture.AssertFullSemver("4.5.1-beta.3", configuration);
171171
}
172172

173173
/// <summary>
@@ -217,7 +217,8 @@ public void FeatureOnHotfixFeatureBranchNotDeleted()
217217
fixture.MakeACommit("blabla"); // commit 1
218218
fixture.Checkout(hotfix451);
219219
fixture.MergeNoFF(featureBranch); // commit 2
220-
fixture.AssertFullSemver("4.5.1-beta.2", configuration);
220+
221+
fixture.AssertFullSemver("4.5.1-beta.3", configuration);
221222
}
222223

223224
[Test]

0 commit comments

Comments
 (0)