Skip to content

Commit 4531e3c

Browse files
committed
Fix bug: VersionInBranchNameVersionStrategy only considers the release branch
1 parent 4e6051a commit 4531e3c

16 files changed

+114
-54
lines changed

docs/input/docs/reference/configuration.md

Lines changed: 7 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)'
@@ -258,9 +259,12 @@ and [tracks-release-branches](#tracks-release-branches).
258259

259260
### label-prefix
260261

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`.
262+
A regular expression which is used to trim Git tags before processing (e.g., v1.0.0). The default value is `[vV]`.
263+
264+
### version-in-branch-pattern
265+
266+
A regular expression which is used to determine the version number in the branch name or commit message (e.g., v1.0.0-LTS).
267+
The default value is `(?<version>[vV]?\d+(\.\d+)?(\.\d+)?).*`.
264268

265269
### major-version-bump-message
266270

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/OtherBranchScenarios.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,19 @@ public void ShouldOnlyConsiderTagsMatchingOfCurrentBranch()
3333
[Test]
3434
public void CanTakeVersionFromReleaseBranch()
3535
{
36+
var configuration = GitFlowConfigurationBuilder.New
37+
.WithBranch("release", _ => _.WithLabel("{BranchName}"))
38+
.Build();
39+
3640
using var fixture = new EmptyRepositoryFixture();
41+
3742
const string taggedVersion = "1.0.3";
3843
fixture.Repository.MakeATaggedCommit(taggedVersion);
3944
fixture.Repository.MakeCommits(5);
40-
fixture.Repository.CreateBranch("release/beta-2.0.0");
41-
Commands.Checkout(fixture.Repository, "release/beta-2.0.0");
45+
fixture.Repository.CreateBranch("release/2.0.0-LTS");
46+
Commands.Checkout(fixture.Repository, "release/2.0.0-LTS");
4247

43-
fixture.AssertFullSemver("2.0.0-beta.1+0");
48+
fixture.AssertFullSemver("2.0.0-LTS.1+0", configuration);
4449
}
4550

4651
[Test]

src/GitVersion.Core.Tests/MergeMessageTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@ public void ParsesGitHubPullMergeMessage(
111111

112112
private static readonly object?[] BitBucketPullMergeMessages =
113113
{
114-
new object?[] { "Merge pull request #1234 from feature/one from feature/two to dev", "feature/two", "dev", null, 1234 },
114+
new object?[] { "Merge pull request #1234 from feature/one from feature/two to dev", "feature/two", "dev", null, 1234 },
115115
new object?[] { "Merge pull request #1234 in feature/one from feature/two to dev", "feature/two", "dev", null, 1234 },
116-
new object?[] { "Merge pull request #1234 in v4.0.0 from v4.1.0 to dev", "v4.1.0", "dev", new SemanticVersion(4,1), 1234 },
117-
new object?[] { "Merge pull request #1234 from origin/feature/one from origin/feature/4.2.0/two to dev", "origin/feature/4.2.0/two", "dev", new SemanticVersion(4,2), 1234 },
118-
new object?[] { "Merge pull request #1234 in feature/4.1.0/one from feature/4.2.0/two to dev", "feature/4.2.0/two", "dev", new SemanticVersion(4,2), 1234 },
116+
new object?[] { "Merge pull request #1234 in v4.0.0 from v4.1.0 to dev", "v4.1.0", "dev", new SemanticVersion(4,1), 1234 },
117+
new object?[] { "Merge pull request #1234 from origin/feature/one from origin/feature/4.2.0/two to dev", "origin/feature/4.2.0/two", "dev", new SemanticVersion(4,2), 1234 },
118+
new object?[] { "Merge pull request #1234 in feature/4.1.0/one from feature/4.2.0/two to dev", "feature/4.2.0/two", "dev", new SemanticVersion(4,2), 1234 },
119119
new object?[] { $"Merge pull request #1234 from feature/one from feature/two to {MainBranch}" , "feature/two", MainBranch, null, 1234 },
120120
new object?[] { "Merge pull request #1234 in V4.1.0 from V://10.10.10.10 to dev", "V://10.10.10.10", "dev", null, 1234 },
121121
//TODO: Investigate successful bitbucket merge messages that may be invalid

src/GitVersion.Core.Tests/VersionCalculation/Strategies/MergeMessageBaseVersionStrategyTests.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,7 @@ public void TakesVersionFromMergeOfReleaseBranch(string message, bool isMergeCom
7575
[TestCase("Merge branch '4.0.3'", true)]
7676
[TestCase("Merge branch 's'", true)]
7777
[TestCase("Merge tag '10.10.50'", true)]
78-
[TestCase("Merge branch 'hotfix-4.6.6' into support-4.6", true)]
79-
[TestCase("Merge branch 'hotfix-10.10.50'", true)]
80-
[TestCase("Merge branch 'Hotfix-10.10.50'", true)]
81-
[TestCase("Merge branch 'Hotfix/10.10.50'", true)]
82-
[TestCase("Merge branch 'hotfix-0.1.5'", true)]
83-
[TestCase("Merge branch 'hotfix-4.2.2' into support-4.2", true)]
8478
[TestCase("Merge branch 'somebranch' into release-3.0.0", true)]
85-
[TestCase("Merge branch 'hotfix-0.1.5'\n\nRelates to: TicketId", true)]
8679
[TestCase("Merge branch 'alpha-0.1.5'", true)]
8780
[TestCase("Merge pull request #95 from Particular/issue-94", false)]
8881
[TestCase("Merge pull request #95 in Particular/issue-94", true)]

src/GitVersion.Core.Tests/VersionCalculation/Strategies/VersionInBranchNameBaseVersionStrategyTests.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ public void CanTakeVersionFromNameOfReleaseBranch(string branchName, string expe
3333
baseVersion.SemanticVersion.ToString().ShouldBe(expectedBaseVersion);
3434
}
3535

36-
[TestCase("hotfix-2.0.0")]
36+
//[TestCase("hotfix-2.0.0")]
3737
[TestCase("origin/hotfix-2.0.0")]
3838
[TestCase("remotes/origin/hotfix-2.0.0")]
39-
[TestCase("hotfix/2.0.0")]
39+
//[TestCase("hotfix/2.0.0")]
4040
[TestCase("origin/hotfix/2.0.0")]
4141
[TestCase("remotes/origin/hotfix/2.0.0")]
4242
[TestCase("custom/JIRA-123")]
@@ -68,7 +68,7 @@ public void ShouldNotTakeVersionFromNameOfNonReleaseBranch(string branchName)
6868

6969
[TestCase("release-2.0.0", "2.0.0")]
7070
[TestCase("release/3.0.0", "3.0.0")]
71-
[TestCase("support/lts-2.0.0", "2.0.0")]
71+
[TestCase("support/2.0.0-lts", "2.0.0")]
7272
[TestCase("support-3.0.0-lts", "3.0.0")]
7373
public void CanTakeVersionFromNameOfConfiguredReleaseBranch(string branchName, string expectedBaseVersion)
7474
{
@@ -80,6 +80,7 @@ public void CanTakeVersionFromNameOfConfiguredReleaseBranch(string branchName, s
8080
var repository = fixture.Repository.ToGitRepository();
8181

8282
var configuration = GitFlowConfigurationBuilder.New
83+
.WithLabelPrefix("([vV]|lts-)?")
8384
.WithBranch("support", builder => builder.WithIsReleaseBranch(true))
8485
.Build();
8586
ConfigurationHelper configurationHelper = new(configuration);

src/GitVersion.Core/Configuration/ConfigurationBuilderBase.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ internal abstract class ConfigurationBuilderBase<TConfigurationBuilder> : IConfi
1212
private string? assemblyVersioningFormat;
1313
private string? assemblyFileVersioningFormat;
1414
private string? labelPrefix;
15+
private string? versionInBranchPattern;
1516
private string? nextVersion;
1617
private string? majorVersionBumpMessage;
1718
private string? minorVersionBumpMessage;
@@ -131,6 +132,12 @@ public virtual TConfigurationBuilder WithLabelPrefix(string? value)
131132
return (TConfigurationBuilder)this;
132133
}
133134

135+
public virtual TConfigurationBuilder WithVersionInBranchPattern(string? value)
136+
{
137+
this.versionInBranchPattern = value;
138+
return (TConfigurationBuilder)this;
139+
}
140+
134141
public virtual TConfigurationBuilder WithNextVersion(string? value)
135142
{
136143
this.nextVersion = value;
@@ -302,6 +309,7 @@ public virtual TConfigurationBuilder WithConfiguration(IGitVersionConfiguration
302309
WithAssemblyVersioningFormat(value.AssemblyVersioningFormat);
303310
WithAssemblyFileVersioningFormat(value.AssemblyFileVersioningFormat);
304311
WithLabelPrefix(value.LabelPrefix);
312+
WithVersionInBranchPattern(value.VersionInBranchPattern);
305313
WithNextVersion(value.NextVersion);
306314
WithMajorVersionBumpMessage(value.MajorVersionBumpMessage);
307315
WithMinorVersionBumpMessage(value.MinorVersionBumpMessage);
@@ -357,6 +365,7 @@ public virtual IGitVersionConfiguration Build()
357365
AssemblyVersioningFormat = this.assemblyVersioningFormat,
358366
AssemblyFileVersioningFormat = this.assemblyFileVersioningFormat,
359367
LabelPrefix = this.labelPrefix,
368+
VersionInBranchPattern = this.versionInBranchPattern,
360369
NextVersion = this.nextVersion,
361370
MajorVersionBumpMessage = this.majorVersionBumpMessage,
362371
MinorVersionBumpMessage = this.minorVersionBumpMessage,

src/GitVersion.Core/Configuration/ConfigurationConstants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ namespace GitVersion.Configuration;
33
internal static class ConfigurationConstants
44
{
55
public const string DefaultLabelPrefix = "[vV]?";
6+
public const string DefaultVersionInBranchPattern = @"(?<version>[vV]?\d+(\.\d+)?(\.\d+)?).*";
67
public const string BranchNamePlaceholder = "{BranchName}";
78

89
public const string MainBranchKey = "main";

src/GitVersion.Core/Configuration/EffectiveConfiguration.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Text.RegularExpressions;
12
using GitVersion.Extensions;
23
using GitVersion.VersionCalculation;
34

@@ -39,6 +40,7 @@ public EffectiveConfiguration(IGitVersionConfiguration configuration, IBranchCon
3940
AssemblyFileVersioningFormat = configuration.AssemblyFileVersioningFormat;
4041
VersioningMode = branchConfiguration.VersioningMode.Value;
4142
LabelPrefix = configuration.LabelPrefix;
43+
VersionInBranchRegex = configuration.VersionInBranchRegex;
4244
Label = branchConfiguration.Label;
4345
NextVersion = configuration.NextVersion;
4446
Increment = branchConfiguration.Increment;
@@ -137,6 +139,8 @@ protected EffectiveConfiguration(AssemblyVersioningScheme assemblyVersioningSche
137139
/// </summary>
138140
public string? LabelPrefix { get; }
139141

142+
public Regex VersionInBranchRegex { get; }
143+
140144
/// <summary>
141145
/// Label to use when calculating SemVer
142146
/// </summary>

src/GitVersion.Core/Configuration/GitFlowConfigurationBuilder.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ private GitFlowConfigurationBuilder()
2020
PatchVersionBumpMessage = IncrementStrategyFinder.DefaultPatchPattern,
2121
SemanticVersionFormat = SemanticVersionFormat.Strict,
2222
LabelPrefix = ConfigurationConstants.DefaultLabelPrefix,
23+
VersionInBranchPattern = ConfigurationConstants.DefaultVersionInBranchPattern,
2324
LabelPreReleaseWeight = 60000,
2425
UpdateBuildNumber = true,
2526
VersioningMode = VersioningMode.ContinuousDelivery,
@@ -133,6 +134,7 @@ private GitFlowConfigurationBuilder()
133134
HotfixBranch.Name
134135
},
135136
Label = "beta",
137+
IsReleaseBranch = true,
136138
PreReleaseWeight = 30000
137139
});
138140

0 commit comments

Comments
 (0)