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

未关闭
#4,433 11 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@fzlzjerry 已经在做这个了。

开始于 2026年8月17日。

  • #5140 来自 @fzlzjerry —— 未关闭

评估

难度
4/5
预计耗时
3-5 天
新手友好度
58/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
活跃
技术栈
csharp, git
领域
devtools, release

调研方向

从 MergeMessageVersionStrategy.cs 和 RepositoryFixture 测试开始,然后比较 GitFlowConfigurationBuilder 和 TrunkBasedConfigurationBuilder 的场景。检查 strategies 配置是如何表示的,以及合并分支的 increment 当前是如何启用的。当 GitFlow 和 GitHubFlow 的 acceptance 场景都产生预期的 patch 或 minor increment,并且测试覆盖每种情况时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

feature help wanted
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
主要语言
C#
星标
3.1k
派生
661
平均合并
7 小时 4 分钟
30 天内合并 PR
77

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

GitTools/GitVersion 的其他 Issue

查看 GitTools/GitVersion 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。