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

Conversation

HHobeck
Copy link
Contributor

@HHobeck HHobeck commented Mar 31, 2023

Fix [Bug] VersionInBranchNameVersionStrategy only considers the release branch #2693

Is related to #2336

Close #2693

Description

Related Issue

Motivation and Context

How Has This Been Tested?

Screenshots (if appropriate):

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@HHobeck HHobeck force-pushed the feature/2693_VersionInBranchNameVersionStrategy_only_considers_the_release_branch branch 2 times, most recently from bd3c051 to ec14032 Compare April 1, 2023 08:18
@HHobeck
Copy link
Contributor Author

HHobeck commented Apr 1, 2023

Okay I'm done please review and merge to main.

@arturcic arturcic requested a review from asbjornu April 1, 2023 10:32
Copy link
Member

@asbjornu asbjornu left a comment

Choose a reason for hiding this comment

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

Nice! Does version-in-branch-pattern require is-release-branch to be true? If so, we should say something about that in the documentation.

docs/input/docs/reference/configuration.md Outdated Show resolved Hide resolved
docs/input/docs/reference/configuration.md Outdated Show resolved Hide resolved
@@ -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.

@@ -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?

@asbjornu
Copy link
Member

asbjornu commented Apr 1, 2023

Nice! Does version-in-branch-pattern require is-release-branch to be true? If so, we should say something about that in the documentation.

Can you please answer this, @HHobeck? ☝🏼

@HHobeck
Copy link
Contributor Author

HHobeck commented Apr 2, 2023

Nice! Does version-in-branch-pattern require is-release-branch to be true? If so, we should say something about that in the documentation.

Can you please answer this, @HHobeck? ☝🏼

Yes you are right the property version-in-branch-pattern effects only branches where the is-release-branch option is set to true. I have changed the documentation :)

@asbjornu asbjornu changed the title Fix bug: VersionInBranchNameVersionStrategy only considers the releae branch Fix bug: VersionInBranchNameVersionStrategy only considers the release branch Apr 3, 2023
@@ -80,6 +82,7 @@ public void CanTakeVersionFromNameOfConfiguredReleaseBranch(string branchName, s
var repository = fixture.Repository.ToGitRepository();

var configuration = GitFlowConfigurationBuilder.New
.WithLabelPrefix("([vV]|lts-)?")
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to document this change being required, perhaps?

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.

What is requirement behind it to support lts before the number will be present? For sure if you define support/2.0.0-lts it works by default if you define support/lts-2.0.0 it's not working by default and a change in the configuration needs to be done (either changing label-prefix or version-in-branch-name). I think this line is not necessary anymore because I have changed the test case. Done.

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps we can add a negative test for this, then? To illustrate that hotfix/downgrade-some-lib-to-3.2.1 don't generate the version number 3.2.1 by default. Such a test case would also provide as good documentation of why this change is made in the first place.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added a new test DoesNotTakeVersionFromNameWhenItHasBeenAccidentalSpecifiedInBranch

@HHobeck HHobeck force-pushed the feature/2693_VersionInBranchNameVersionStrategy_only_considers_the_release_branch branch from 844f00e to ad5f11d Compare April 3, 2023 11:15
@HHobeck
Copy link
Contributor Author

HHobeck commented Apr 3, 2023

Okay I'm done with the integration of review comments. Please check and merge to main.

Copy link
Member

@asbjornu asbjornu left a comment

Choose a reason for hiding this comment

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

There's suddenly a lot of formatting changes here. Please do formatting and refactoring in separate pull requests from bug fixes and feature implementations.

Also, I would love to see a test case added for hotfix/downgrade-library-to-3.1.2 not yielding the version number 3.1.2 as that seems to be one of the primary reasons behind this PR.

src/GitVersion.Core/Git/ReferenceName.cs Outdated Show resolved Hide resolved
src/GitVersion.Core/Git/SemanticVersion.cs Outdated Show resolved Hide resolved
src/GitVersion.Core/Git/SemanticVersionBuildMetaData.cs Outdated Show resolved Hide resolved
src/GitVersion.Core/Git/SemanticVersionBuildMetaData.cs Outdated Show resolved Hide resolved
@HHobeck
Copy link
Contributor Author

HHobeck commented Apr 4, 2023

There's suddenly a lot of formatting changes here. Please do formatting and refactoring in separate pull requests from bug fixes and feature implementations.

Also, I would love to see a test case added for hotfix/downgrade-library-to-3.1.2 not yielding the version number 3.1.2 as that seems to be one of the primary reasons behind this PR.

You mean such tests!? There are already existing. Nevermind let me know if you are missing test scenarios.

[Test]
public void DoesNotTakeVersionFromNameOfNonReleaseBranch()
{
    using var fixture = new BaseGitFlowRepositoryFixture("1.0.0");
    fixture.CreateAndMergeBranchIntoDevelop("pull-request/improved-by-upgrading-some-lib-to-4.5.6");
    fixture.CreateAndMergeBranchIntoDevelop("hotfix/downgrade-some-lib-to-3.2.1-to-avoid-breaking-changes");

    fixture.AssertFullSemver("1.1.0-alpha.5");
}

[TestCase("release-2.0.0", "2.0.0")]
[TestCase("release/3.0.0", "3.0.0")]
[TestCase("support/2.0.0-lts", "2.0.0")]
[TestCase("support-3.0.0-lts", "3.0.0")]
[TestCase("hotfix/2.0.0", "2.0.0")]
[TestCase("hotfix-3.0.0", "3.0.0")]
[TestCase("hotfix/2.0.0-lts", "2.0.0")]
[TestCase("hotfix-3.0.0-lts", "3.0.0")]
public void CanTakeVersionFromNameOfConfiguredReleaseBranch(string branchName, string expectedBaseVersion)
{
    using var fixture = new EmptyRepositoryFixture();

    fixture.MakeACommit();
    fixture.CreateBranch(branchName);

    var repository = fixture.Repository.ToGitRepository();

    var configuration = GitFlowConfigurationBuilder.New
        .WithBranch("support", builder => builder.WithIsReleaseBranch(true))
   ...
}

@HHobeck HHobeck force-pushed the feature/2693_VersionInBranchNameVersionStrategy_only_considers_the_release_branch branch from 0560fd4 to 4c10925 Compare April 4, 2023 08:08
…chNameScenarios.cs

Co-authored-by: Asbjørn Ulsberg <asbjorn@ulsberg.no>
@arturcic arturcic force-pushed the feature/2693_VersionInBranchNameVersionStrategy_only_considers_the_release_branch branch from 137647f to 3795785 Compare April 5, 2023 07:49
@arturcic arturcic requested a review from asbjornu April 5, 2023 08:15
Copy link
Member

@asbjornu asbjornu left a comment

Choose a reason for hiding this comment

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

Fabulous! 🚀

@arturcic arturcic merged commit 03271d6 into GitTools:main Apr 6, 2023
@mergify
Copy link
Contributor

mergify bot commented Apr 6, 2023

Thank you @HHobeck for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] VersionInBranchNameVersionStrategy only considers the release branch
3 participants