Skip to content

Commit

Permalink
Merge pull request #3455 from HHobeck/feature/2693_VersionInBranchNam…
Browse files Browse the repository at this point in the history
…eVersionStrategy_only_considers_the_release_branch

Fix bug: VersionInBranchNameVersionStrategy only considers the release branch
  • Loading branch information
arturcic committed Apr 6, 2023
2 parents 4e6051a + 3795785 commit 03271d6
Show file tree
Hide file tree
Showing 33 changed files with 247 additions and 99 deletions.
6 changes: 4 additions & 2 deletions BREAKING_CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
* Following root configuration properties have been removed:
* continuous-delivery-fallback-tag
* 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`.
* 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.
* The process of increasing the version with bump message when `CommitMessageIncrementing` is enabled and increment strategy is `None` has been changed.
* 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.
* The process of increasing the version with bump message when `CommitMessageIncrementing` is enabled and increment strategy is `None` has been changed.
* 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`).
* 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.

## v5.0.0

Expand Down
24 changes: 21 additions & 3 deletions docs/input/docs/reference/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ The global configuration looks like this:
assembly-versioning-scheme: MajorMinorPatch
assembly-file-versioning-scheme: MajorMinorPatch
label-prefix: '[vV]?'
version-in-branch-pattern: (?<version>[vV]?\d+(\.\d+)?(\.\d+)?).*
major-version-bump-message: '\+semver:\s?(breaking|major)'
minor-version-bump-message: '\+semver:\s?(feature|minor)'
patch-version-bump-message: '\+semver:\s?(fix|patch)'
Expand All @@ -61,6 +62,7 @@ branches:
track-merge-target: true
regex: ^dev(elop)?(ment)?$
source-branches: []
is-source-branch-for: []
tracks-release-branches: true
is-release-branch: false
is-mainline: false
Expand All @@ -74,6 +76,7 @@ branches:
source-branches:
- develop
- release
is-source-branch-for: []
tracks-release-branches: false
is-release-branch: false
is-mainline: true
Expand All @@ -89,6 +92,7 @@ branches:
- main
- support
- release
is-source-branch-for: []
tracks-release-branches: false
is-release-branch: true
is-mainline: false
Expand All @@ -105,6 +109,7 @@ branches:
- feature
- support
- hotfix
is-source-branch-for: []
pre-release-weight: 30000
pull-request:
mode: ContinuousDelivery
Expand All @@ -119,6 +124,7 @@ branches:
- feature
- support
- hotfix
is-source-branch-for: []
pre-release-weight: 30000
hotfix:
mode: ContinuousDelivery
Expand All @@ -130,6 +136,8 @@ branches:
- main
- support
- hotfix
is-source-branch-for: []
is-release-branch: true
pre-release-weight: 30000
support:
label: ''
Expand All @@ -139,6 +147,7 @@ branches:
regex: ^support[/-]
source-branches:
- main
is-source-branch-for: []
tracks-release-branches: false
is-release-branch: false
is-mainline: true
Expand All @@ -156,6 +165,7 @@ branches:
- pull-request
- hotfix
- support
is-source-branch-for: []
ignore:
sha: []
mode: ContinuousDelivery
Expand All @@ -166,6 +176,8 @@ track-merge-target: false
track-merge-message: true
commit-message-incrementing: Enabled
regex: ''
source-branches: []
is-source-branch-for: []
tracks-release-branches: false
is-release-branch: false
is-mainline: false
Expand Down Expand Up @@ -258,9 +270,15 @@ and [tracks-release-branches](#tracks-release-branches).

### label-prefix

A regex which is used to trim Git tags before processing (e.g., v1.0.0). Default
is `[vV]`, although this is just for illustrative purposes as we do a IgnoreCase
match and could be `v`.
A regular expression which is used to trim Git tags before processing (e.g.,
v1.0.0). The default value is `[vV]`.

### version-in-branch-pattern

A regular expression which is used to determine the version number in the branch
name or commit message (e.g., v1.0.0-LTS). This setting only applies on branches
where the option `is-release-branch` is set to `true`. The default value is
`(?<version>[vV]?\d+(\.\d+)?(\.\d+)?).*`.

### major-version-bump-message

Expand Down
1 change: 1 addition & 0 deletions new-cli/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

<ItemGroup>
<Using Include="System.Collections"/>
<Using Include="System.Text"/>
</ItemGroup>

</Project>
19 changes: 19 additions & 0 deletions new-cli/GitVersion.Common/GitVersion.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PackageReference Include="Polly" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\src\GitVersion.Core\Extensions\StringExtensions.cs" Link="Extensions\StringExtensions.cs" />
<Compile Include="..\..\src\GitVersion.Core\Git\AuthenticationInfo.cs">
<Link>Git\AuthenticationInfo.cs</Link>
</Compile>
Expand Down Expand Up @@ -63,5 +64,23 @@
<Compile Include="..\..\src\GitVersion.Core\Git\RefSpecDirection.cs">
<Link>Git\RefSpecDirection.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.Core\Git\SemanticVersion.cs">
<Link>Git\SemanticVersion.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.Core\Git\SemanticVersionBuildMetaData.cs">
<Link>Git\SemanticVersionBuildMetaData.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.Core\Git\SemanticVersionFormat.cs">
<Link>Git\SemanticVersionFormat.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.Core\Git\SemanticVersionPreReleaseTag.cs">
<Link>Git\SemanticVersionPreReleaseTag.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.Core\Git\VersionField.cs">
<Link>Git\VersionField.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.Core\Git\WarningException.cs">
<Link>Git\WarningException.cs</Link>
</Compile>
</ItemGroup>
</Project>
2 changes: 0 additions & 2 deletions new-cli/GitVersion.Common/Helpers/EncodingHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Text;

namespace GitVersion.Helpers;

public static class EncodingHelper
Expand Down
2 changes: 0 additions & 2 deletions new-cli/GitVersion.Common/Infrastructure/IFileSystem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Text;

namespace GitVersion.Infrastructure;

public interface IFileSystem
Expand Down
1 change: 0 additions & 1 deletion new-cli/GitVersion.Core/Infrastructure/FileSystem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Text;
using GitVersion.Helpers;

namespace GitVersion.Infrastructure;
Expand Down
4 changes: 4 additions & 0 deletions schemas/6.0/GitVersion.configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@
"description": "Whether to update the build number in the project file. Defaults to true.",
"type": "boolean"
},
"version-in-branch-pattern": {
"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.",
"type": "string"
},
"mode": {
"$ref": "#/$defs/Nullable\u006018"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
assembly-versioning-scheme: MajorMinorPatch
assembly-file-versioning-scheme: MajorMinorPatch
label-prefix: '[vV]?'
version-in-branch-pattern: (?<version>[vV]?\d+(\.\d+)?(\.\d+)?).*
major-version-bump-message: '\+semver:\s?(breaking|major)'
minor-version-bump-message: '\+semver:\s?(feature|minor)'
patch-version-bump-message: '\+semver:\s?(fix|patch)'
Expand Down Expand Up @@ -94,6 +95,7 @@ branches:
- support
- hotfix
is-source-branch-for: []
is-release-branch: true
pre-release-weight: 30000
support:
label: ''
Expand Down
39 changes: 20 additions & 19 deletions src/GitVersion.Core.Tests/IntegrationTests/HotfixBranchScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void CanTakeVersionFromHotfixesBranch()

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

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

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

fixture.AssertFullSemver("1.1.1-beta.1+1");
fixture.Repository.MakeACommit();
fixture.MakeACommit();
fixture.AssertFullSemver("1.1.1-beta.1+2");

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

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

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

// Verify develop version
Commands.Checkout(fixture.Repository, "develop");
fixture.Checkout("develop");
fixture.AssertFullSemver("2.1.0-alpha.1");
fixture.Repository.MergeNoFF("support-1.1", Generate.SignatureNow());
fixture.MergeNoFF("support-1.1");
fixture.AssertFullSemver("2.1.0-alpha.7");
}

Expand Down Expand Up @@ -167,7 +167,7 @@ public void FeatureOnHotfixFeatureBranchDeleted()
fixture.Checkout(hotfix451);
fixture.MergeNoFF(featureBranch); // commit 2
fixture.Repository.Branches.Remove(featureBranch);
fixture.AssertFullSemver("4.5.1-beta.2", configuration);
fixture.AssertFullSemver("4.5.1-beta.3", configuration);
}

/// <summary>
Expand Down Expand Up @@ -217,7 +217,8 @@ public void FeatureOnHotfixFeatureBranchNotDeleted()
fixture.MakeACommit("blabla"); // commit 1
fixture.Checkout(hotfix451);
fixture.MergeNoFF(featureBranch); // commit 2
fixture.AssertFullSemver("4.5.1-beta.2", configuration);

fixture.AssertFullSemver("4.5.1-beta.3", configuration);
}

[Test]
Expand Down
30 changes: 26 additions & 4 deletions src/GitVersion.Core.Tests/IntegrationTests/OtherBranchScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,36 @@ public void ShouldOnlyConsiderTagsMatchingOfCurrentBranch()
[Test]
public void CanTakeVersionFromReleaseBranch()
{
var configuration = GitFlowConfigurationBuilder.New
.WithBranch("release", _ => _.WithLabel("{BranchName}"))
.Build();

using var fixture = new EmptyRepositoryFixture();

const string taggedVersion = "1.0.3";
fixture.Repository.MakeATaggedCommit(taggedVersion);
fixture.MakeATaggedCommit(taggedVersion);
fixture.Repository.MakeCommits(5);
fixture.Repository.CreateBranch("release/beta-2.0.0");
Commands.Checkout(fixture.Repository, "release/beta-2.0.0");
fixture.BranchTo("release/2.0.0-LTS");
fixture.MakeACommit();

fixture.AssertFullSemver("2.0.0-LTS.1+1", configuration);
}

[Test]
public void CanTakeVersionFromHotfixBranch()
{
var configuration = GitFlowConfigurationBuilder.New
.WithBranch("hotfix", _ => _.WithLabel("{BranchName}"))
.Build();

using var fixture = new EmptyRepositoryFixture();

const string taggedVersion = "1.0.3";
fixture.MakeATaggedCommit(taggedVersion);
fixture.BranchTo("hotfix/1.0.5-LTS");
fixture.MakeACommit();

fixture.AssertFullSemver("2.0.0-beta.1+0");
fixture.AssertFullSemver("1.0.5-LTS.1+1", configuration);
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,41 @@ public void SupportIsCalculatedCorrectly()
{
using var fixture = new EmptyRepositoryFixture();
// Start at 1.0.0
fixture.Repository.MakeACommit();
fixture.Repository.ApplyTag("1.1.0");
fixture.MakeACommit();
fixture.ApplyTag("1.1.0");

// Create 2.0.0 release
Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("release-2.0.0"));
fixture.BranchTo("release-2.0.0");
fixture.Repository.MakeCommits(2);

// Merge into develop and main
Commands.Checkout(fixture.Repository, MainBranch);
fixture.Repository.MergeNoFF("release-2.0.0");
fixture.Repository.ApplyTag("2.0.0");
fixture.Checkout(MainBranch);
fixture.MergeNoFF("release-2.0.0");
fixture.ApplyTag("2.0.0");
fixture.AssertFullSemver("2.0.0");

// Now lets support 1.x release
Commands.Checkout(fixture.Repository, "1.1.0");
Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("support/1.0.0"));
fixture.Checkout("1.1.0");
fixture.BranchTo("support/1.0.0");
fixture.AssertFullSemver("1.1.0");

// Create release branch from support branch
Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("release/1.2.0"));
fixture.Repository.MakeACommit();
fixture.BranchTo("release/1.2.0");
fixture.MakeACommit();
fixture.AssertFullSemver("1.2.0-beta.1+1");

// Create 1.2.0 release
Commands.Checkout(fixture.Repository, "support/1.0.0");
fixture.Repository.MergeNoFF("release/1.2.0");
fixture.Checkout("support/1.0.0");
fixture.MergeNoFF("release/1.2.0");
fixture.AssertFullSemver("1.2.0+0");
fixture.Repository.ApplyTag("1.2.0");
fixture.ApplyTag("1.2.0");

// Create 1.2.1 hotfix
Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("hotfix/1.2.1"));
fixture.Repository.MakeACommit();
fixture.AssertFullSemver("1.2.1-beta.1+1");
Commands.Checkout(fixture.Repository, "support/1.0.0");
fixture.Repository.MergeNoFF("hotfix/1.2.1");
fixture.BranchTo("hotfix/1.2.1");
fixture.MakeACommit();
fixture.AssertFullSemver("1.2.1-beta.1+3");
fixture.Checkout("support/1.0.0");
fixture.MergeNoFF("hotfix/1.2.1");
fixture.AssertFullSemver("1.2.1+2");
}

Expand Down
Loading

0 comments on commit 03271d6

Please sign in to comment.