GitTools / GitTools/GitVersion

[FEATURE]: Support of prevent increment of merged branch in GitHub workflow

Open
#4,433 11 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature help wanted
Dominant language
C#
Stars
3.1k
Forks
659
Avg merge
13h 15m
Merged PRs (30d)
51

Description

Prerequisites
  • I have written a descriptive issue title
  • I have searched issues to ensure it has not already been reported
GitVersion package

GitVersion.Tool

GitVersion version

6.1.0

Operating system

N/A, Windows

What are you seeing?

The feature to increment the version when merging into a branch by using the increment of the source branch is currently supported only in the TrunkBased workflow. It would be good to have the same behavior in the GitFlow and GitHubFlow workflows as well.

Hint: Needs to be implemented probably in MergeMessageVersionStrategy. We should create a separate version strategy class to be able to enable or disable the behavior via the configuration (strategies property).

What is expected?

Scenario 1:
When merging a hotfix branch with increment patch to a main branch with increment minor, I would expect the increment to be patch and not minor in a GitFlow workflow.

Scenario 2:
When merging a feature branch with increment minor to a main branch with increment patch, I would expect the increment to be minor and not patch in a GitFlow workflow.

Steps to Reproduce

Scenario 1:

 *  54 minutes ago  (HEAD -> main)
 |\
 | A 56 minutes ago  (hotfix/foo)
 |/
 *  58 minutes ago (tag: 1.0.0)

Scenario 2:

 *  54 minutes ago  (HEAD -> main)
 |\
 | A 56 minutes ago  (feature/foo)
 |/
 *  58 minutes ago (tag: 1.0.0)

See RepostioryFixture Test section below for more information.

RepositoryFixture Test
[Test]
public void Given_main_with_increment_minor_and_hotfix_with_increment_patch_When_hotfix_merged_into_main_Then_increment_should_be_patch()
{
    using var fixture = new EmptyRepositoryFixture("main");

    var configurationBuilder = TrunkBasedConfigurationBuilder.New
        .WithBranch("main", builder => builder
            .WithIncrement(IncrementStrategy.Minor)
            .WithDeploymentMode(DeploymentMode.ContinuousDelivery)
            .WithPreventIncrementOfMergedBranch(true)
        ).WithBranch("hotfix", builder => builder.WithIncrement(IncrementStrategy.Patch));

    fixture.MakeATaggedCommit("1.0.0");
    fixture.BranchTo("hotfix/foo");
    fixture.MakeACommit();
    fixture.MergeTo("main");

    // ✅ succeeds as expected
    fixture.AssertFullSemver("1.0.1-2", configurationBuilder.Build());
}

It would be good to have the same behavior in the GitFlow and GitHubFlow workflows:

[Test]
public void Given_main_with_increment_minor_and_hotfix_with_increment_patch_When_hotfix_merged_into_main_Then_increment_should_be_patch()
{
    using var fixture = new EmptyRepositoryFixture("main");

    var configurationBuilder = GitFlowConfigurationBuilder.New
        .WithBranch("main", builder => builder.WithIncrement(IncrementStrategy.Minor).WithPreventIncrementOfMergedBranch(true))
        .WithBranch("hotfix", builder => builder.WithIncrement(IncrementStrategy.Patch));

    fixture.MakeATaggedCommit("1.0.0");
    fixture.BranchTo("hotfix/foo");
    fixture.MakeACommit();
    fixture.MergeTo("main");

    // ❔ expected: "1.0.1-2"
    fixture.AssertFullSemver("1.1.0-2", configurationBuilder.Build());
}

Additional acceptance criteria:

[Test]
public void Given_main_with_increment_patch_and_feature_with_increment_minor_When_feature_merged_into_main_Then_increment_should_be_minor()
{
    using var fixture = new EmptyRepositoryFixture("main");

    var configurationBuilder = GitFlowConfigurationBuilder.New
        .WithBranch("main", builder => builder
            .WithIncrement(IncrementStrategy.Patch)
            .WithPreventIncrementOfMergedBranch(true)
        ).WithBranch("feature", builder => builder.WithIncrement(IncrementStrategy.Minor));

    fixture.MakeATaggedCommit("1.0.0");
    fixture.BranchTo("feature/foo");
    fixture.MakeACommit();
    fixture.MergeTo("main");

    // ❔ expected: "1.1.0-2"
    fixture.AssertFullSemver("1.0.1-2", configurationBuilder.Build());
}
Output log or link to your CI build (if appropriate).
N/A

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with MergeMessageVersionStrategy.cs and the RepositoryFixture tests, then compare the GitFlowConfigurationBuilder and TrunkBasedConfigurationBuilder scenarios. Check how the strategies configuration is represented and how merged-branch increments are currently enabled. Done means both GitFlow and GitHubFlow acceptance scenarios produce the expected patch or minor increment, with tests covering each case.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, git
Domain
devtools, release
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.