Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug: VersionInBranchNameVersionStrategy only considers the release branch #3455

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we not still on a tagged commit here?

Copy link
Contributor Author

@HHobeck HHobeck Apr 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm very good question. I think you have found a bug. ;) The same question applies to the following scenario:

[Test]
public void __Just_A_Test__()
{
    using var fixture = new EmptyRepositoryFixture();

    fixture.MakeATaggedCommit("1.0.0");
    fixture.BranchTo("release/1.1.0");

    fixture.AssertFullSemver("1.1.0+0");
}

Why it yields to 1.1.0 and not to 1.0.0?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is one of those edge-cases that no matter which solution we pick, we are going to make some people unhappy. I'm in the "a tag should always win" camp, but I can definitely see how some people would expect release/1.1.0 to yield 1.1.0 even though the same commit is tagged 1.0.0. I don't think there's a right answer here, we just need to pick one way or the other, stick to it and document it well.

Copy link
Contributor Author

@HHobeck HHobeck Apr 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this discussion is related to this issue here: Same version computed on different branches #3453

We need to introduce a new branch related property (like take-incremented-version) or make the behavior dependent on the used version-mode option and make it configurable. The point is if you are on the hotfix branch you don't want to have properly the tagged version you would like to have the next version 1.1.0+0. Other way around if you are on the main branch you would like to have the tagged version 1.0.0. In both cases you are on the same commit with different result dependent on what branch you are. If you don't want this behavior neither then you are able to change it. I see the following enum values: TakeAlwaysBaseVersion, TakeTaggedOtherwiseIncrementedVersion, TakeAlwaysIncrementedVersion

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we were to base this on mode, how would you suggest we do it?

Copy link
Contributor Author

@HHobeck HHobeck Apr 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I think it would be not a good idea to put it on the version-mode option because it is very confusing and would lead to issues complaining about that the tag is not recognice correctly.

Also if I think about the behavior of real live deplyoment scenarios (trunk-based, continues-deployment, continues-delivery and manually-deployment) this question is totally independent of that. Because it depends on the fact: Do I create a artifact after I have tagged the commit or before. Or do I take a pre-release version and just re-declare it to production version or not.

What is your opinion about that?

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did this go from 4.5.1-beta.2 to 4.5.1-beta.3?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm very good question. I think it has something to do with the logic in GitVersionVariables.cs which you know will be changed in PR #2347. I have checked the source of the resulting base version and it looks okay for me:

image

image

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the .3 in 4.5.1-beta.3 indicates that there's 3 commits since the version source, but it is only 2 indicated by the previous .2 as in 4.5.1-beta.2. So this feels like a bug to me? Why does it count to 3 and not 2?

Copy link
Contributor Author

@HHobeck HHobeck Apr 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have take a look and I think it's correct. If you take a look to the following figure:

image

then you see that GitVersion uses the highest version (4.5.1). If there are ambiguous results (like in this case) the oldest commit as a source will be taken. Here it is the commit with the identifier bf7a8f7f. Thus if you have this in mind 4.5.1-beta.3 is totally correct. See yor comment here #2394 (comment)

If you don't agree then we need to create a bug or feature issue and change the logic. But this has nothing to do with this PR IMO.

}

/// <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