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

[Bug] Mainline mode breaks hotfix version when commit is tagged #2786

Closed
Tracked by #3445
koershov opened this issue Jul 27, 2021 · 7 comments
Closed
Tracked by #3445

[Bug] Mainline mode breaks hotfix version when commit is tagged #2786

koershov opened this issue Jul 27, 2021 · 7 comments
Labels

Comments

@koershov
Copy link

koershov commented Jul 27, 2021

Describe the bug
When I use mainline mode with master and hotfix branch it works fine unless I start tagging every commit.
Imagine a hotfix branch is branched out from the mainline at version 1.2.0. From that point, every commit on that branch should increment only the patch version. But if one of the commits on hotfix was tagged with current version the next version calculation will be broken (the minor version will be affected by an unrelated commit on mainline)
Here's an example how the git structure for that case looks like

* 45d2cdf 44 minutes ago  (HEAD -> hotfix/may)
* a756535 46 minutes ago  (tag: 1.2.2)
* 104d39d 48 minutes ago 
| * b6e989c 50 minutes ago  (main)
|/  
* 1a4437e 52 minutes ago 
* 6ef88f0 54 minutes ago  (tag: 1.1.0)
* 0ad3ed8 56 minutes ago  (tag: 1.0.0)
* eb7857c 58 minutes ago 

The same thing happens when the commit where the hotfix branch was branched of is tagged

* 5b74598 50 minutes ago  (HEAD -> hotfix/may)
| * 5a68be2 52 minutes ago  (main)
|/  
* d44f7f1 54 minutes ago  (tag: 1.1.0)
* 7784f67 56 minutes ago  (tag: 1.0.0)
* 6d36b75 58 minutes ago 

Expected Behavior

First example, the version should be "1.2.3"
Second example, the version should be "1.1.1"

Actual Behavior

First example, the version should is "1.3.1"
Second example, the version should be "1.2.1"

Possible Fix

It feels like mainlineCommitLog should include also the commit where the current branch was branched off. In FindMergeBaseBeforeForwardMerge method

Steps to Reproduce

Tests are here #2787

Context

Our strategy is very simple. Each commit on main should increment minor. Each commit on hotfix should increment patch.

@asbjornu
Copy link
Member

While this does sound like a bug, I wonder why you would tag the hotfix branch?

@koershov
Copy link
Author

koershov commented Jul 30, 2021

We just tag every commit on which we run the build. But even if we don't, there still gonna be an issue when the parent commit of the hotfix branch is tagged (example 2)

@asbjornu
Copy link
Member

Are you able to submit this as a (failing) test in a PR?

@koershov
Copy link
Author

koershov commented Jul 30, 2021

I've already provided 2 tests here: #2787

@asbjornu
Copy link
Member

Ah, sorry. I haven't had time to investigate.

@Bazaleev
Copy link

Hi @asbjornu, any update on this one? It does look like a bug and quite unpleasant one.

@HHobeck
Copy link
Contributor

HHobeck commented Mar 20, 2023

The hotfix branch inherits from the main branch and gets the IncrementStrategy.Minor. Why would you expect that the patch number increases!? And I don't understand why you would create a tag (an exception might be a pre-release tag) on the hotfix branch. Your scenario seems to me not following the git hub workflow. Please see this documentation https://gitversion.net/docs/learn/branching-strategies/gitflow/examples#hotfix-branches.

The following configuration is something which might be suit better for your use case:

[Test]
public void HotfixScenarioWithVersioningModeMainline()
{
    var configuration = GitFlowConfigurationBuilder.New
        .WithVersioningMode(VersioningMode.Mainline)
        .WithBranch("main", _ => _.WithIncrement(IncrementStrategy.Minor))
        .WithBranch("hotfix", _ => _.WithIncrement(IncrementStrategy.Patch))
        .Build();

    using var fixture = new EmptyRepositoryFixture("main");

    fixture.MakeATaggedCommit("1.0.0");

    // ✅ succeeds as expected
    fixture.AssertFullSemver("1.0.0", configuration);

    fixture.MakeACommit();

    // ✅ succeeds as expected
    fixture.AssertFullSemver("1.1.0", configuration);

    fixture.MakeACommit();

    // ✅ succeeds as expected
    fixture.AssertFullSemver("1.2.0", configuration);

    fixture.ApplyTag("1.2.0");

    // ✅ succeeds as expected
    fixture.AssertFullSemver("1.2.0", configuration);

    fixture.BranchTo("hotfix/1.2.1");
    fixture.MakeACommit();

    // ✅ succeeds as expected
    fixture.AssertFullSemver("1.2.1-beta.1+1", configuration);

    fixture.MakeACommit();

    // ✅ succeeds as expected
    fixture.AssertFullSemver("1.2.1-beta.1+2", configuration);

    fixture.ApplyTag("1.2.1-beta.1");

    // ✅ succeeds as expected
    fixture.AssertFullSemver("1.2.1-beta.1", configuration);

    fixture.MakeACommit();

    // ✅ succeeds as expected
    fixture.AssertFullSemver("1.2.1-beta.2+1", configuration);

    fixture.Checkout("main");
    fixture.MergeNoFF("hotfix/1.2.1");

    // ✅ succeeds as expected
    fixture.AssertFullSemver("1.2.1", configuration);

    fixture.ApplyTag("1.2.1");

    // ✅ succeeds as expected
    fixture.AssertFullSemver("1.2.1", configuration);

    fixture.MakeACommit();

    // ✅ succeeds as expected
    fixture.AssertFullSemver("1.3.0", configuration);
}

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

No branches or pull requests

4 participants