Skip to content

Commit 158bac4

Browse files
committed
Version not bumped if an irrelevant tag exists in latest commit.
1 parent df383b8 commit 158bac4

File tree

11 files changed

+130
-32
lines changed

11 files changed

+130
-32
lines changed

BREAKING_CHANGES.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* The `useBranchName` magic string has been removed. Instead use `{BranchName}` for `label`.
3232
* The `BranchPrefixToTrim` configuration property has been removed. `RegularExpression` is now used to capture named groups instead.
3333
* Default `RegularExpression` for feature branches is changed from `^features?[/-]` to `^features?[/-](?<BranchName>.+)` to support using `{BranchName}` out-of-the-box
34-
* Default `RegularExpression` for unknown branches is changed from `.*` to `(?<BranchName>.*)` to support using `{BranchName}` out-of-the-box
34+
* Default `RegularExpression` for unknown branches is changed from `.*` to `(?<BranchName>.+)` to support using `{BranchName}` out-of-the-box
3535
* The `Mainline` mode and the related implementation has been removed completely. The new `TrunkBased` version strategy should be used instead.
3636
* The branch related property `is-mainline` in the configuration system has been renamed to `is-main-branch`
3737
* The versioning mode has been renamed to deployment mode and consists of following values:

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

+13-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
assembly-versioning-scheme: MajorMinorPatch
22
assembly-file-versioning-scheme: MajorMinorPatch
33
tag-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)'
@@ -10,10 +11,14 @@ commit-date-format: yyyy-MM-dd
1011
merge-message-formats: {}
1112
update-build-number: true
1213
semantic-version-format: Strict
13-
strategies: [ConfigNext, MergeMessage, TaggedCommit, TrackReleaseBranches, VersionInBranchName]
14+
strategies:
15+
- ConfiguredNextVersion
16+
- MergeMessage
17+
- TaggedCommit
18+
- TrackReleaseBranches
19+
- VersionInBranchName
1420
branches:
1521
develop:
16-
mode: ContinuousDeployment
1722
label: alpha
1823
increment: Minor
1924
prevent-increment-of-merged-branch-version: false
@@ -38,6 +43,7 @@ branches:
3843
is-main-branch: true
3944
pre-release-weight: 55000
4045
release:
46+
mode: ManualDeployment
4147
label: beta
4248
increment: None
4349
prevent-increment-of-merged-branch-version: true
@@ -53,7 +59,7 @@ branches:
5359
is-main-branch: false
5460
pre-release-weight: 30000
5561
feature:
56-
mode: ContinuousDelivery
62+
mode: ManualDeployment
5763
label: '{BranchName}'
5864
increment: Inherit
5965
regex: ^features?[/-](?<BranchName>.+)
@@ -80,7 +86,7 @@ branches:
8086
- hotfix
8187
pre-release-weight: 30000
8288
hotfix:
83-
mode: ContinuousDelivery
89+
mode: ManualDeployment
8490
label: beta
8591
increment: Inherit
8692
regex: ^hotfix(es)?[/-]
@@ -89,6 +95,7 @@ branches:
8995
- main
9096
- support
9197
- hotfix
98+
is-release-branch: true
9299
pre-release-weight: 30000
93100
support:
94101
label: ''
@@ -103,10 +110,10 @@ branches:
103110
is-main-branch: true
104111
pre-release-weight: 55000
105112
unknown:
106-
mode: ContinuousDelivery
113+
mode: ManualDeployment
107114
label: '{BranchName}'
108115
increment: Inherit
109-
regex: (?<BranchName>.*)
116+
regex: (?<BranchName>.+)
110117
source-branches:
111118
- main
112119
- develop

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

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
assembly-versioning-scheme: MajorMinorPatch
22
assembly-file-versioning-scheme: MajorMinorPatch
33
tag-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)'
@@ -10,7 +11,12 @@ commit-date-format: yyyy-MM-dd
1011
merge-message-formats: {}
1112
update-build-number: true
1213
semantic-version-format: Strict
13-
strategies: [ConfigNext, MergeMessage, TaggedCommit, TrackReleaseBranches, VersionInBranchName]
14+
strategies:
15+
- ConfiguredNextVersion
16+
- MergeMessage
17+
- TaggedCommit
18+
- TrackReleaseBranches
19+
- VersionInBranchName
1420
branches:
1521
main:
1622
label: ''
@@ -25,6 +31,7 @@ branches:
2531
is-main-branch: true
2632
pre-release-weight: 55000
2733
release:
34+
mode: ManualDeployment
2835
label: beta
2936
increment: None
3037
prevent-increment-of-merged-branch-version: true
@@ -38,7 +45,7 @@ branches:
3845
is-main-branch: false
3946
pre-release-weight: 30000
4047
feature:
41-
mode: ContinuousDelivery
48+
mode: ManualDeployment
4249
label: '{BranchName}'
4350
increment: Inherit
4451
regex: ^features?[/-](?<BranchName>.+)
@@ -59,10 +66,10 @@ branches:
5966
- feature
6067
pre-release-weight: 30000
6168
unknown:
62-
mode: ContinuousDelivery
69+
mode: ManualDeployment
6370
label: '{BranchName}'
6471
increment: Inherit
65-
regex: (?<BranchName>.*)
72+
regex: (?<BranchName>.+)
6673
source-branches:
6774
- main
6875
- release

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
assembly-versioning-scheme: MajorMinorPatch
22
assembly-file-versioning-scheme: MajorMinorPatch
33
tag-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)'
@@ -10,7 +11,9 @@ commit-date-format: yyyy-MM-dd
1011
merge-message-formats: {}
1112
update-build-number: true
1213
semantic-version-format: Strict
13-
strategies: [TrunkBased, ConfiguredNextVersion]
14+
strategies:
15+
- TrunkBased
16+
- ConfiguredNextVersion
1417
branches:
1518
main:
1619
mode: ContinuousDeployment
@@ -48,7 +51,7 @@ branches:
4851
unknown:
4952
mode: ManualDeployment
5053
increment: Inherit
51-
regex: (?<BranchName>.*)
54+
regex: (?<BranchName>.+)
5255
source-branches:
5356
- main
5457
- release

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

+71-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,80 @@
11
using GitVersion.Configuration;
22
using GitVersion.Core.Tests.Helpers;
3+
using GitVersion.VersionCalculation;
34
using LibGit2Sharp;
45

56
namespace GitVersion.Core.Tests.IntegrationTests;
67

78
[TestFixture]
89
public class OtherBranchScenarios : TestBase
910
{
11+
[TestCase("", "NotAVersion", "2.0.0-1", "1.9.0", "1.9.0", "1.9.1-1")]
12+
[TestCase("", "1.5.0", "1.5.0", "1.9.0", "1.9.0", "1.9.1-1")]
13+
[TestCase("prefix", "1.5.0", "2.0.0-1", "1.9.0", "2.0.0-1", "2.0.0-2")]
14+
[TestCase("prefix", "1.5.0", "2.0.0-1", "prefix1.9.0", "1.9.0", "1.9.1-1")]
15+
[TestCase("prefix", "prefix1.5.0", "1.5.0", "1.9.0", "1.5.0", "1.5.1-1")]
16+
public void CanUseCommitMessagesToBumpVersion_TagsTakePriorityOnlyIfVersions(
17+
string tagPrefix,
18+
string firstTag,
19+
string expectedAfterFirstTag,
20+
string secondTag,
21+
string expectedAfterSecondTag,
22+
string expectedVersionAfterNewCommit)
23+
{
24+
var configuration = GitFlowConfigurationBuilder.New
25+
.WithTagPrefix(tagPrefix)
26+
.Build();
27+
28+
using var fixture = new EmptyRepositoryFixture();
29+
var repo = fixture.Repository;
30+
31+
repo.MakeATaggedCommit($"{tagPrefix}1.0.0");
32+
repo.MakeACommit("+semver:major");
33+
fixture.AssertFullSemver("2.0.0-1", configuration);
34+
35+
repo.ApplyTag(firstTag);
36+
fixture.AssertFullSemver(expectedAfterFirstTag, configuration);
37+
38+
repo.ApplyTag(secondTag);
39+
fixture.AssertFullSemver(expectedAfterSecondTag, configuration);
40+
41+
repo.MakeACommit();
42+
fixture.AssertFullSemver(expectedVersionAfterNewCommit, configuration);
43+
}
44+
45+
[TestCase("", null, "1.9.0-1", "2.0.0-1+1", ExpectedResult = "1.9.0-1")]
46+
[TestCase("", "", "1.9.0-1", "2.0.0-1+1", ExpectedResult = "1.9.0-1")]
47+
[TestCase("", "foo", "1.9.0-1", "2.0.0-foo.1+1", ExpectedResult = "2.0.0-foo.1+1")]
48+
[TestCase("", "bar", "1.9.0-1", "2.0.0-bar.1+1", ExpectedResult = "2.0.0-bar.1+1")]
49+
[TestCase("prefix", null, "1.9.0-1", "2.0.0-1+1", ExpectedResult = "2.0.0-1+1")]
50+
[TestCase("prefix", "", "1.9.0-1", "2.0.0-1+1", ExpectedResult = "2.0.0-1+1")]
51+
[TestCase("prefix", "foo", "1.9.0-1", "2.0.0-foo.1+1", ExpectedResult = "2.0.0-foo.1+1")]
52+
[TestCase("prefix", "bar", "1.9.0-1", "2.0.0-bar.1+1", ExpectedResult = "2.0.0-bar.1+1")]
53+
54+
[TestCase("", null, "2.1.0-1", "2.0.0-1+1", ExpectedResult = "2.1.0-1")]
55+
[TestCase("", "", "2.1.0-1", "2.0.0-1+1", ExpectedResult = "2.1.0-1")]
56+
[TestCase("", "foo", "2.1.0-1", "2.0.0-foo.1+1", ExpectedResult = "2.1.0-foo.1+1")]
57+
[TestCase("", "bar", "2.1.0-1", "2.0.0-bar.1+1", ExpectedResult = "2.1.0-bar.1+1")]
58+
[TestCase("prefix", null, "2.1.0-1", "2.0.0-1+1", ExpectedResult = "2.0.0-1+1")]
59+
[TestCase("prefix", "", "2.1.0-1", "2.0.0-1+1", ExpectedResult = "2.0.0-1+1")]
60+
[TestCase("prefix", "foo", "2.1.0-1", "2.0.0-foo.1+1", ExpectedResult = "2.0.0-foo.1+1")]
61+
[TestCase("prefix", "bar", "2.1.0-1", "2.0.0-bar.1+1", ExpectedResult = "2.0.0-bar.1+1")]
62+
public string WhenTaggingACommitAsPreRelease(string tagPrefix, string? label, string tag, string expectedVersion)
63+
{
64+
var configuration = GitFlowConfigurationBuilder.New.WithLabel(null).WithTagPrefix(tagPrefix)
65+
.WithBranch("main", _ => _.WithLabel(label).WithDeploymentMode(DeploymentMode.ManualDeployment))
66+
.Build();
67+
68+
using EmptyRepositoryFixture fixture = new("main");
69+
70+
fixture.MakeATaggedCommit($"{tagPrefix}1.0.0");
71+
fixture.MakeACommit("+semver:major");
72+
fixture.AssertFullSemver(expectedVersion, configuration);
73+
fixture.ApplyTag(tag);
74+
75+
return fixture!.GetVersion(configuration).FullSemVer;
76+
}
77+
1078
/// <summary>
1179
/// https://github.com/GitTools/GitVersion/issues/2340
1280
/// </summary>
@@ -34,7 +102,7 @@ public void ShouldOnlyConsiderTagsMatchingOfCurrentBranch()
34102
public void CanTakeVersionFromReleaseBranch()
35103
{
36104
var configuration = GitFlowConfigurationBuilder.New
37-
.WithBranch("release", _ => _.WithLabel("{BranchName}").WithRegularExpression("(?<BranchName>.*)"))
105+
.WithBranch("release", _ => _.WithLabel("{BranchName}").WithRegularExpression("(?<BranchName>.+)"))
38106
.Build();
39107

40108
using var fixture = new EmptyRepositoryFixture();
@@ -52,7 +120,7 @@ public void CanTakeVersionFromReleaseBranch()
52120
public void CanTakeVersionFromHotfixBranch()
53121
{
54122
var configuration = GitFlowConfigurationBuilder.New
55-
.WithBranch("hotfix", _ => _.WithLabel("{BranchName}").WithRegularExpression("(?<BranchName>.*)"))
123+
.WithBranch("hotfix", _ => _.WithLabel("{BranchName}").WithRegularExpression("(?<BranchName>.+)"))
56124
.Build();
57125

58126
using var fixture = new EmptyRepositoryFixture();
@@ -112,7 +180,7 @@ public void LabelIsBranchNameForBranchesWithoutPrefixedBranchName(string label,
112180
var configuration = GitFlowConfigurationBuilder.New
113181
.WithBranch("other", builder => builder
114182
.WithIncrement(IncrementStrategy.Patch)
115-
.WithRegularExpression("(?<BranchName>.*)")
183+
.WithRegularExpression("(?<BranchName>.+)")
116184
.WithSourceBranches()
117185
.WithLabel(label))
118186
.Build();

src/GitVersion.Core/Core/ITaggedSemanticVersionRepository.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersionsOfMergeTarget(
1616
string? tagPrefix,
1717
SemanticVersionFormat format);
1818

19-
ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersionsOfMainlineBranches(
19+
ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersionsOfMainBranches(
2020
string? tagPrefix,
2121
SemanticVersionFormat format,
2222
params IBranch[] excludeBranches);
@@ -25,4 +25,6 @@ ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersionsOfReleaseBranc
2525
string? tagPrefix,
2626
SemanticVersionFormat format,
2727
params IBranch[] excludeBranches);
28+
29+
ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersions(string? tagPrefix, SemanticVersionFormat format);
2830
}

src/GitVersion.Core/Core/TaggedSemanticVersionRepository.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public ILookup<ICommit, SemanticVersionWithTag> GetAllTaggedSemanticVersions(IBr
8787

8888
if (!configuration.IsMainBranch && !configuration.IsReleaseBranch)
8989
{
90-
var semanticVersionsOfMainlineBranches = GetTaggedSemanticVersionsOfMainlineBranches(
90+
var semanticVersionsOfMainlineBranches = GetTaggedSemanticVersionsOfMainBranches(
9191
tagPrefix: configuration.TagPrefix,
9292
format: configuration.SemanticVersionFormat,
9393
excludeBranches: branch
@@ -188,7 +188,7 @@ public ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersionsOfMerge
188188
return result;
189189
}
190190

191-
public ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersionsOfMainlineBranches(
191+
public ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersionsOfMainBranches(
192192
string? tagPrefix, SemanticVersionFormat format, params IBranch[] excludeBranches)
193193
{
194194
tagPrefix ??= string.Empty;
@@ -236,7 +236,7 @@ IEnumerable<SemanticVersionWithTag> GetElements()
236236
return GetElements().Distinct().ToLookup(element => element.Tag.Commit, element => element);
237237
}
238238

239-
private ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersions(string? tagPrefix, SemanticVersionFormat format)
239+
public ILookup<ICommit, SemanticVersionWithTag> GetTaggedSemanticVersions(string? tagPrefix, SemanticVersionFormat format)
240240
{
241241
tagPrefix ??= string.Empty;
242242

src/GitVersion.Core/PublicAPI.Unshipped.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ GitVersion.VersionCalculation.DeploymentMode.ManualDeployment = 0 -> GitVersion.
693693
GitVersion.VersionCalculation.IEffectiveBranchConfigurationFinder
694694
GitVersion.VersionCalculation.IEffectiveBranchConfigurationFinder.GetConfigurations(GitVersion.IBranch! branch, GitVersion.Configuration.IGitVersionConfiguration! configuration) -> System.Collections.Generic.IEnumerable<GitVersion.Configuration.EffectiveBranchConfiguration!>!
695695
GitVersion.VersionCalculation.IIncrementStrategyFinder
696-
GitVersion.VersionCalculation.IIncrementStrategyFinder.DetermineIncrementedField(GitVersion.ICommit! currentCommit, GitVersion.VersionCalculation.BaseVersion! baseVersion, GitVersion.Configuration.EffectiveConfiguration! configuration) -> GitVersion.VersionField
696+
GitVersion.VersionCalculation.IIncrementStrategyFinder.DetermineIncrementedField(GitVersion.ICommit! currentCommit, GitVersion.VersionCalculation.BaseVersion! baseVersion, GitVersion.Configuration.EffectiveConfiguration! configuration, string? label) -> GitVersion.VersionField
697697
GitVersion.VersionCalculation.IIncrementStrategyFinder.GetIncrementForcedByCommit(GitVersion.ICommit! commit, GitVersion.Configuration.EffectiveConfiguration! configuration) -> GitVersion.VersionField
698698
GitVersion.VersionCalculation.IIncrementStrategyFinder.GetIncrementForCommits(string? majorVersionBumpMessage, string? minorVersionBumpMessage, string? patchVersionBumpMessage, string? noBumpMessage, GitVersion.ICommit![]! commits) -> GitVersion.VersionField?
699699
GitVersion.VersionCalculation.IIncrementStrategyFinder.GetMergedCommits(GitVersion.ICommit! mergeCommit, int index) -> System.Collections.Generic.IEnumerable<GitVersion.ICommit!>!

src/GitVersion.Core/VersionCalculation/Abstractions/IIncrementStrategyFinder.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ namespace GitVersion.VersionCalculation;
44

55
public interface IIncrementStrategyFinder
66
{
7-
VersionField DetermineIncrementedField(ICommit currentCommit, BaseVersion baseVersion, EffectiveConfiguration configuration);
7+
VersionField DetermineIncrementedField(
8+
ICommit currentCommit, BaseVersion baseVersion, EffectiveConfiguration configuration, string? label);
89

910
VersionField? GetIncrementForCommits(
1011
string? majorVersionBumpMessage, string? minorVersionBumpMessage, string? patchVersionBumpMessage, string? noBumpMessage,

0 commit comments

Comments
 (0)