Skip to content

Branch's increment not used when merging feature branch in main #4430

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

Closed
prantzos opened this issue Feb 21, 2025 · 9 comments
Closed

Branch's increment not used when merging feature branch in main #4430

prantzos opened this issue Feb 21, 2025 · 9 comments

Comments

@prantzos
Copy link

prantzos commented Feb 21, 2025

Hi,

I would like your help with a configuration that even though simple, I could not get it to work and I believe there is a bug here.

I have attempted many many different variations and I cannot compose a GitVersion.yml that does the following:

  • Increment version with Patch when a commit is pushed on main
  • Increment version with Minor when a feature branch is merged on main

I removed any other configurations for hotfix and other non-default properties and regular expressions to keep it simple, but still the strategy followed is the increment value of the main branch which is "Patch" instead of the "Minor" which is of the merged branch

This is my GitVersion.yml

assembly-versioning-format: '{SemVer}.{ShortSha}--{CommitDate}'
assembly-informational-format: '{SemVer}.{ShortSha}--{CommitDate}'

assembly-versioning-scheme: MajorMinorPatch
assembly-file-versioning-scheme: MajorMinorPatchTag
commit-date-format: yyyy-MM-dd
update-build-number: true

strategies:
  - Fallback
  - ConfiguredNextVersion
  - MergeMessage
  - TaggedCommit
  - TrackReleaseBranches
  - VersionInBranchName

branches:
  main:
    mode: ContinuousDeployment
    label: ''
    increment: Patch
    prevent-increment:
      of-merged-branch: false
      when-branch-merged: false
      when-current-commit-tagged: true
    regex: ^master$|^main$
    is-main-branch: true
  feature:
    mode: ContinuousDelivery
    label: 'rc'
    increment: Minor
    prevent-increment:
      of-merged-branch: true
      when-branch-merged: false
      when-current-commit-tagged: true
    track-merge-target: false
    track-merge-message: true
    regex: (?<BranchName>.+)
    source-branches:
      - main
      - feature
    is-source-branch-for:
      - feature
    is-main-branch: false

dotnet-gitversion output on the main branch before merging the test-branch

%dotnet-version

{
  "AssemblySemFileVer": "4.1.9.0",
  "AssemblySemVer": "4.1.9.a03f84e--2025-02-19",
  "BranchName": "main",
  "BuildMetaData": null,
  "CommitDate": "2025-02-19",
  "CommitsSinceVersionSource": 2,
  "EscapedBranchName": "main",
  "FullBuildMetaData": "Branch.main.Sha.a03f84ed0b90f6b69c11ab98fc3d93e512d87139",
  "FullSemVer": "4.1.9",
  "InformationalVersion": "4.1.9.a03f84e--2025-02-19",
  "Major": 4,
  "MajorMinorPatch": "4.1.9",
  "Minor": 1,
  "Patch": 9,
  "PreReleaseLabel": "",
  "PreReleaseLabelWithDash": "",
  "PreReleaseNumber": null,
  "PreReleaseTag": "",
  "PreReleaseTagWithDash": "",
  "SemVer": "4.1.9",
  "Sha": "a03f84ed0b90f6b69c11ab98fc3d93e512d87139",
  "ShortSha": "a03f84e",
  "UncommittedChanges": 0,
  "VersionSourceSha": "0383b76abf3aef1c1d384db6627473b2493a5318",
  "WeightedPreReleaseNumber": 60000
}

dotnet-gitversion of the feature branch

% dotnet-gitversion
{
  "AssemblySemFileVer": "4.2.0.3",
  "AssemblySemVer": "4.2.0-rc.3.56e6a67--2025-02-19",
  "BranchName": "test-branch",
  "BuildMetaData": null,
  "CommitDate": "2025-02-19",
  "CommitsSinceVersionSource": 3,
  "EscapedBranchName": "test-branch",
  "FullBuildMetaData": "Branch.test-branch.Sha.56e6a675df1e6f2ed58d2bdc5c7dfdcd11a0dd24",
  "FullSemVer": "4.2.0-rc.3",
  "InformationalVersion": "4.2.0-rc.3.56e6a67--2025-02-19",
  "Major": 4,
  "MajorMinorPatch": "4.2.0",
  "Minor": 2,
  "Patch": 0,
  "PreReleaseLabel": "rc",
  "PreReleaseLabelWithDash": "-rc",
  "PreReleaseNumber": 3,
  "PreReleaseTag": "rc.3",
  "PreReleaseTagWithDash": "-rc.3",
  "SemVer": "4.2.0-rc.3",
  "Sha": "56e6a675df1e6f2ed58d2bdc5c7dfdcd11a0dd24",
  "ShortSha": "56e6a67",
  "UncommittedChanges": 0,
  "VersionSourceSha": "0383b76abf3aef1c1d384db6627473b2493a5318",
  "WeightedPreReleaseNumber": 30003
}

Merging a branch
% git merge test-branch
...

dotnet-gitversion with diagnostic output on the main branch after merging the test-branch

% dotnet-gitversion /diag
INFO [25-02-19 23:34:35:50] Please run `git log --graph --format="%h %cr %d" --decorate --date=relative --all --remotes=*` to see the git graph. This can help you troubleshoot any issues.

INFO [25-02-19 23:34:35:51] Working directory: /Users/vasilis.prantzos/Projects/review-api
INFO [25-02-19 23:34:35:52] Project root is: /Users/vasilis.prantzos/Projects/review-api/
INFO [25-02-19 23:34:35:52] DotGit directory is: /Users/vasilis.prantzos/Projects/review-api/.git
INFO [25-02-19 23:34:35:52] Branch from build environment: 
INFO [25-02-19 23:34:35:52] Found configuration file at '/Users/vasilis.prantzos/Projects/review-api/GitVersion.yml'
INFO [25-02-19 23:34:35:58] Using latest commit on specified branch
INFO [25-02-19 23:34:35:63] Getting tagged semantic versions. TagPrefix: [vV]? and Format: Strict
INFO [25-02-19 23:34:35:67] Running against branch: main ('40bf003' - Merge branch 'test-branch')
INFO [25-02-19 23:34:35:67] -< Begin: Fetching the base versions for version calculation... >-
  INFO [25-02-19 23:34:35:67] -< Begin: Calculating base versions for 'main' >-
    INFO [25-02-19 23:34:35:67] -< Begin: [Using 'ConfiguredNextVersionVersionStrategy' strategy] >-
    INFO [25-02-19 23:34:35:67] -< End: [Using 'ConfiguredNextVersionVersionStrategy' strategy] (Took: 0.32ms) >-
    INFO [25-02-19 23:34:35:67] -< Begin: [Using 'MainlineVersionStrategy' strategy] >-
    INFO [25-02-19 23:34:35:67] -< End: [Using 'MainlineVersionStrategy' strategy] (Took: 0.25ms) >-
    INFO [25-02-19 23:34:35:67] -< Begin: [Using 'MergeMessageVersionStrategy' strategy] >-
    INFO [25-02-19 23:34:35:70] -< End: [Using 'MergeMessageVersionStrategy' strategy] (Took: 27.45ms) >-
    INFO [25-02-19 23:34:35:70] -< Begin: [Using 'TaggedCommitVersionStrategy' strategy] >-
      INFO [25-02-19 23:34:35:70] -< Begin: Getting tagged semantic versions on branch 'refs/heads/main'. TagPrefix: [vV]? and Format: Strict >-
      INFO [25-02-19 23:34:35:71] -< End: Getting tagged semantic versions on branch 'refs/heads/main'. TagPrefix: [vV]? and Format: Strict (Took: 0.95ms) >-
      INFO [25-02-19 23:34:35:75] Git tag '4.1.8': Version increment '4.1.8' +semver 'Patch' with label '' based on commit '0383b76'.
      INFO [25-02-19 23:34:35:75] Git tag '4.1.7': Version increment '4.1.7' +semver 'Patch' with label '' based on commit '553c03f'.
      INFO [25-02-19 23:34:35:75] Git tag '4.1.6': Version increment '4.1.6' +semver 'Patch' with label '' based on commit '6fcaaac'.
      INFO [25-02-19 23:34:35:75] Git tag '4.1.5': Version increment '4.1.5' +semver 'Patch' with label '' based on commit 'ba99153'.
      INFO [25-02-19 23:34:35:75] Git tag '4.1.4': Version increment '4.1.4' +semver 'Patch' with label '' based on commit 'daaa3ad'.
      INFO [25-02-19 23:34:35:75] Git tag '4.1.3': Version increment '4.1.3' +semver 'Patch' with label '' based on commit '4954b87'.
      INFO [25-02-19 23:34:35:75] Git tag '4.1.2': Version increment '4.1.2' +semver 'Patch' with label '' based on commit 'a156711'.
      INFO [25-02-19 23:34:35:75] Git tag '4.1.1': Version increment '4.1.1' +semver 'Patch' with label '' based on commit '8add235'.
      INFO [25-02-19 23:34:35:75] Git tag '4.1.0': Version increment '4.1.0' +semver 'Patch' with label '' based on commit 'de07a0c'.
      INFO [25-02-19 23:34:35:75] Git tag '4.0.752': Version increment '4.0.752' +semver 'Patch' with label '' based on commit '0961991'.
    INFO [25-02-19 23:34:35:75] -< End: [Using 'TaggedCommitVersionStrategy' strategy] (Took: 50.75ms) >-
    INFO [25-02-19 23:34:35:75] -< Begin: [Using 'TrackReleaseBranchesVersionStrategy' strategy] >-
    INFO [25-02-19 23:34:35:75] -< End: [Using 'TrackReleaseBranchesVersionStrategy' strategy] (Took: 0.24ms) >-
    INFO [25-02-19 23:34:35:75] -< Begin: [Using 'VersionInBranchNameVersionStrategy' strategy] >-
    INFO [25-02-19 23:34:35:75] -< End: [Using 'VersionInBranchNameVersionStrategy' strategy] (Took: 0.27ms) >-
  INFO [25-02-19 23:34:35:75] -< End: Calculating base versions for 'main' (Took: 80.55ms) >-
INFO [25-02-19 23:34:35:75] -< End: Fetching the base versions for version calculation... (Took: 81.69ms) >-
INFO [25-02-19 23:34:35:75] -------------------------------------------------------
INFO [25-02-19 23:34:35:75] Base version used: Git tag '4.1.8': Take '4.1.8' based on commit '0383b76'.
INFO [25-02-19 23:34:35:75] -------------------------------------------------------
INFO [25-02-19 23:34:35:75] -< Begin: Using continuous deployment workflow to calculate the incremented version. >-
  INFO [25-02-19 23:34:35:76] 4 commits found between '0383b76' - Merge branch 'WT-9010-review-moderation-notifications-with-token' into 'main' and '40bf003' - Merge branch 'test-branch'
INFO [25-02-19 23:34:35:76] -< End: Using continuous deployment workflow to calculate the incremented version. (Took: 1.55ms) >-
INFO [25-02-19 23:34:35:77] Found configuration file at '/Users/vasilis.prantzos/Projects/review-api/GitVersion.yml'
Executing GenerateSetVersionMessage for 'LocalBuild'.

Executing GenerateBuildLogOutput for 'LocalBuild'.
{
  "AssemblySemFileVer": "4.1.9.0",
  "AssemblySemVer": "4.1.9.40bf003--2025-02-19",
  "BranchName": "main",
  "BuildMetaData": null,
  "CommitDate": "2025-02-19",
  "CommitsSinceVersionSource": 4,
  "EscapedBranchName": "main",
  "FullBuildMetaData": "Branch.main.Sha.40bf003a7b0e378364a965881703375401ae59b8",
  "FullSemVer": "4.1.9",
  "InformationalVersion": "4.1.9.40bf003--2025-02-19",
  "Major": 4,
  "MajorMinorPatch": "4.1.9",
  "Minor": 1,
  "Patch": 9,
  "PreReleaseLabel": "",
  "PreReleaseLabelWithDash": "",
  "PreReleaseNumber": null,
  "PreReleaseTag": "",
  "PreReleaseTagWithDash": "",
  "SemVer": "4.1.9",
  "Sha": "40bf003a7b0e378364a965881703375401ae59b8",
  "ShortSha": "40bf003",
  "UncommittedChanges": 0,
  "VersionSourceSha": "0383b76abf3aef1c1d384db6627473b2493a5318",
  "WeightedPreReleaseNumber": 60000
}

And the commits from the git log are the following:

% git log --merges --oneline

40bf003 (HEAD -> main) Merge branch 'test-branch'
a03f84e Merge branch 'test-gitversion-configuration'
0383b76 (tag: 4.1.8, origin/main) Merge branch .....
.....

Maybe a combination of the prevent-increment and the increment makes it so that the merging strategy does not work as expected.
I would appreciate any response, help, feedback and potentially a bug fix if that indeed is the case.

Originally posted by @prantzos in #4425

@HHobeck
Copy link
Contributor

HHobeck commented Feb 22, 2025

This is only possible with TrunkBased workflow. Please see the following integrations tests:

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

    var configurationBuilder = GitFlowConfigurationBuilder.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");

    fixture.AssertFullSemver("1.1.0-2", configurationBuilder.Build());
}

[Test]
public void __Just_A_Test_2__()
{
    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());
}

This feature was introduced in the mainline version strategy and needs to be implemented in MergeMessageVersionStrategy.

@prantzos
Copy link
Author

Hi @HHobeck,

Thank you very much for your response, I highly appreciate it!

I must confess that I am a bit confused though.
What do you mean that my example should work with TrunkBased workflow? I did use the TrunkBased example, but made some changes for the sake of simplifying my post here.

I removed all regex from the feature branch and I removed completely any configurations for other branches, like a hotfix branch.
I made some changes to the prevent-increment, thinking that they would aid in how the increment would be calculated when I am merging a branch in the main branch.

I did not find the tests you posted in the repo's tests. I read through a lot of them, especially in the FeatureBranchScenarios and could not find a scenario that a feature branch is merged and then main gets a minor version bump.

I tried to use again the GitHubFlow example and the TrunkBasedFlow example configurations but I get the same results.

You said that "it" needs to be implemented in MergeMessageVersionStrategy. What do you mean by "it"?
Did you maybe want to say that the MergeMessage strategy does not work as expected yet?

I had configured it (at various points in my tests) like so:

merge-message-formats:
  feature: "^Merge branch '.*'"

In any case, I would like to use a "mix" of GitHubFlow and TrunkBasedFlow.
Namely:

  • Have a main branch with mode as ContinuousDelivery and increment as Patch, for direct commits on master
  • When a feature branch is merged its Minor increment to be applied as the version bump on the main branch
  • When a hotfix branch is merged its Patch increment to be applied as the version bump on the main branch

The configuration below is the final configuration that I would like to have, which I think is correct for what I want.

## You can configure branching strategy in GitVersion.yml. See: https://gitversion.net/docs/reference/configuration
#next-version: 4.0
assembly-informational-format: '{SemVer}.{ShortSha}--{CommitDate}'

assembly-versioning-scheme: MajorMinorPatch
assembly-file-versioning-scheme: MajorMinorPatchTag
commit-date-format: yyyy-MM-dd
update-build-number: true
merge-message-formats:
  feature: "^Merge branch '.*'"

strategies:
  - Fallback
  - ConfiguredNextVersion
  - MergeMessage
  - TaggedCommit
  - TrackReleaseBranches
  - VersionInBranchName

branches:
  main:
    regex: ^master$|^main$
    mode: ContinuousDelivery
    label: ''
    increment: Patch
    prevent-increment:
      of-merged-branch: true
      when-branch-merged: false
      when-current-commit-tagged: true
    track-merge-target: false
    track-merge-message: true
    source-branches: [ ]
    is-source-branch-for: [ ]
    is-release-branch: false
    is-main-branch: true
  feature:
    regex: (?<BranchName>.+)
    mode: ManualDeployment
    label: 'rc'
    increment: Minor
    prevent-increment:
      of-merged-branch: true
      when-branch-merged: false
      when-current-commit-tagged: false
    track-merge-target: false
    track-merge-message: true
    source-branches:
      - main
      - feature
    is-source-branch-for: [ ]
    is-release-branch: false
    is-main-branch: false
  hotfix:
    regex: ^hotfix[/-](?<BranchName>.+)
    mode: ContinuousDelivery
    label: 'patch'
    increment: Patch
    prevent-increment:
      of-merged-branch: true
      when-branch-merged: true
      when-current-commit-tagged: false
    source-branches:
      - main
    is-source-branch-for: [ ]
    is-release-branch: false
    is-main-branch: false

Would you be so kind as to explain what combination or single setting is wrong or missing or redundant, that is responsible for my troubles?

OR if I have not understood your point(s) and I am misusing some configuration(s), can you let me know what do I need to do to achieve my goals above?

Thank you so much again for helping out!!! 😊🥰

@HHobeck
Copy link
Contributor

HHobeck commented Feb 23, 2025

I did not find the tests you posted in the repo's tests.

I have just posted the tests to illustrate the different between the two workflows. They are not in the repository present.

I read through a lot of them, especially in the FeatureBranchScenarios and could not find a scenario that a feature branch is merged and then main gets a minor version bump.

You can find your scenario in the following integration test:

internal partial class MainlineScenariosWithAGitHubFlow
{
[Parallelizable(ParallelScope.All)]
public class GivenAFeatureBranchWithOneCommitMergedToMainWhen
{
private EmptyRepositoryFixture? fixture;
private static GitFlowConfigurationBuilder MainlineBuilder => GitFlowConfigurationBuilder.New
.WithVersionStrategy(VersionStrategies.Mainline).WithLabel(null)
.WithBranch("main", b => b.WithDeploymentMode(DeploymentMode.ManualDeployment))
.WithBranch("feature", b => b
.WithDeploymentMode(DeploymentMode.ManualDeployment).WithPreventIncrementWhenCurrentCommitTagged(true)
);
[OneTimeSetUp]
public void OneTimeSetUp()
{
// * 54 minutes ago (HEAD -> main)
// |\
// | B 56 minutes ago (feature/foo)
// |/
// A 58 minutes ago
fixture = new EmptyRepositoryFixture();
fixture.MakeACommit("A");
fixture.BranchTo("feature/foo");
fixture.MakeACommit("B");
fixture.MergeTo("main");
}

I tried to use again the GitHubFlow example and the TrunkBasedFlow example configurations but I get the same results.

Okay then you need to maybe go some steps back and start from the beginning by using just the TrunkBased workflow with minimal customization. You know the workflow property and how to customize existing workflows, right? I have gave to you the proof that your scenario is generally working with the TrunkBased workflow by providing the integration tests.

You said that "it" needs to be implemented in MergeMessageVersionStrategy. What do you mean by "it"?
Did you maybe want to say that the MergeMessage strategy does not work as expected yet?

Actually this behavior we are talking about is something which was implemented in Mainline mode (OLD, in version 5.x) and migrated to the new Mainline version strategy (NEW, in version 6.x). Yes, it's a feature which is worth to implement in MergeMessage version strategy. I have created a new feature ticket for this:

Would you be so kind as to explain what combination or single setting is wrong or missing or redundant, that is responsible for my troubles?
OR if I have not understood your point(s) and I am misusing some configuration(s), can you let me know what do I need to do to achieve my goals above?
Thank you so much again for helping out!!! 😊🥰

I'm sorry if I can't fulfill your expectation. Please understand that I cannot provide advice/consultancy on individual workflows. However, you are free to engage me or other experts to help you.

Thank you very much for your understanding.

@HHobeck HHobeck closed this as completed Feb 23, 2025
@HHobeck HHobeck closed this as not planned Won't fix, can't repro, duplicate, stale Feb 23, 2025
@prantzos
Copy link
Author

Hi @HHobeck,

Thanks for getting back to me so soon!

I got that you posted example tests and they were not copied from the repository itself. What I meant is I could not find them or their counterparts, in the repository while reading all related tests to what I am trying to accomplish.

I did not come across GivenAFeatureBranchWithOneCommitMergedToMainWhen, so thank you for posting it. I did not realize that the MainLine strategy should be involved, but rather that the MergeMessage is the one that I should focus on. If I understand the tests correctly, there are indeed tests that assert what I am aiming for, which is the main branch to bump the merged branch's Minor increment when merged into main, instead of following main's Patch increment rule.

At first your comment and example test threw me off, since you said that what I wanted should work on TrunkBased workflow and the example test was mentioning a hotfix branch with specific naming rule, and the assertion in the test was for a Patch bump and not a Minor bump. The example test for GitHubFlow seems like the behavior I would like to replicate 🤔. And this confusion is why in my previous comment I posted explanation in bullets and mentioned it is a mix of both workflows.
My excuses for the long posts, and any confusion, I just wanted to be as analytical as possible to make myself understood.

I will try again and use the workflow property, which I admit I did not pay much attention to, since it was not part of the example yaml files in the Configuration documentation, but mentioned before each one of the workflows examples.

My excuses again if I asked too much in the end of my previous comment. It just felt easier to ask the question "what is wrong with this then??" than a gazillion of others. If you had pinpointed the problem, then I would try and figure out myself what went wrong in my previous attempts.
I am not interested in a quick fix-and-forget. I want a (quick) fix and to be able to understand how everything works, so I can be in a position to advise my colleagues how to set up their own pipelines properly.

So, all in all, I will give it another try and if in need bother you some more 😬
Many thanks again!
Oh and thank you for opening #4433 👍

@prantzos
Copy link
Author

Hi @HHobeck,

I spend some time trying out using the workflow and I used the yaml files from the configuration page as-they-were, and also trimmed down for simplicity and I even only specified the workflow and nothing else in my GitVersion.yml. I have been having the same result.

I then tried again to create a simple configuration from scratch and this time I left the workflow value empty as advised in the documentation.

workflow: ''
tag-prefix: ''
tag-pre-release-weight: 90000

Since the MergeMessageVersionStrategy produces no logs, and no results,

INFO [25-02-23 11:40:31:97] -< Begin: [Using 'MergeMessageVersionStrategy' strategy] >-
INFO [25-02-23 11:40:31:99] -< End: [Using 'MergeMessageVersionStrategy' strategy] (Took: 21.69ms) >-

I tried to understand how it works
I read the code in MergeMessageVersionStrategy and I have a couple of observations/questions.

It seems that for this strategy to be even used:

  • the merged branch needs to have the is-release-branch set to true
  • a non null version needs to be extracted from the name of the merged branch (See: TryGetSemanticVersion in ReferenceNameExtensions)

Then and only then the IIncrementStrategyFinder is used to calculate the increment 🤔

It seems to me that the MergeMessageVersionStrategy can only be used for GitFlow and GitHubFlow for release and hotfix branches and for TrunkBased flow for only hotfix branches.

Thus it seems that what I am aiming for, cannot be done using MergeMessageVersionStrategy at least.
Namely, one cannot configure gitversion to use the version of the merged feature branch to as the new version of the main branch.

I can perhaps describe it with a test

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

    // No specific Flow builder, but an empty/custom flow
    var configurationBuilder = EmptyConfigurationBuilder.New
        .WithBranch("main", builder => builder
            .WithIncrement(IncrementStrategy.Patch)
            .WithDeploymentMode(DeploymentMode.ContinuousDelivery)
            .WithPreventIncrementOfMergedBranch(true) // ignore the Patch when a feature branch is merged in main
            .WithPreventIncrementWhenBranchMerged(false)
            .WithIsMainBranch(true)
        ).WithBranch("feature", builder => builder
             .WithIncrement(IncrementStrategy.Minor)
             .WithRegularExpression("(?<BranchName>.+)")
             .WithDeploymentMode(DeploymentMode.ManualDeployment)
             .WithPreventIncrementOfMergedBranch(true)
             .WithPreventIncrementWhenBranchMerged(false) // don''t ignore Minor when merging this branch to main
             .WithIsReleaseBranch(false)
        );

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

    fixture.AssertFullSemver("1.1.0-2", configurationBuilder.Build());
}

So could it be that the issue #4433 you created can be generalized for other custom flows and not only be about the GitHubFlow?

@prantzos prantzos changed the title Hi, Branch's increment not used when merging feature branch in main Feb 23, 2025
@HHobeck
Copy link
Contributor

HHobeck commented Feb 24, 2025

So could it be that the #4433 you created can be generalized for other custom flows and not only be about the GitHubFlow?

Like I mentioned in the ticket:

Image

Of course this behavior will be applying to all workflows (including custom workflows) which are using the MergeMassage version strategy. Your example makes no sense because there is no version strategy specified and not all required configuration properties are set.

@prantzos
Copy link
Author

Hi @HHobeck,

When I say "other custom flows", I am not referring to GitFlow or GitHubFlow, which you mention in the #4433 issue, nor their templates (GitFlow template, GitHubFlow template, TrunkBased template)

I was referring to workflows that do not follow a predefined/approved template, by setting the workflow as empty as described in the documentation.

Image

If as you say the behavior will apply to all workflows, including custom ones, then my question above regarding how the code of MergeMessageVersionStrategy works still stands.

My apologies if my example does not make sense to you. I tried to explain what I am trying to accomplish with snippets from GitVersion.yml, with a fake test method and with explaining the behavior in bullet points, but it seems I failed to convey my point.

If you see something missing, like a required configuration property, as you mentioned above, please indicate which one(s) you believe is missing that is required and I have missed to configure properly.

I am posting here the full GitVersion.yml that I am currently working with, with all branch configurations and strategies for your reference.
And a short description of the desired behavior:

  • All non-merge commits on main should increment Patch
  • All feature branch merges (with specified merge message format) on main, should increment Minor
  • All other (unknown) branch merges, should increment Patch
  • All hotfix branch merges should increment Patch
## You can configure branching strategy in GitVersion.yml. See: https://gitversion.net/docs/reference/configuration
## Bump the next version explicitly. Use for bumping the major version increment.
#next-version: 4.0

workflow: ''
tag-prefix: ''
tag-pre-release-weight: 90000
assembly-informational-format: '{SemVer}.{ShortSha}'

assembly-versioning-scheme: MajorMinorPatch
assembly-file-versioning-scheme: MajorMinorPatchTag
commit-date-format: yyyy-MM-dd
update-build-number: true
commit-message-incrementing: Enabled
merge-message-formats:
  git: "^Merge branch '.*'"

strategies:
  - Fallback
  - ConfiguredNextVersion
  - MergeMessage
  - TaggedCommit

branches:
  main:
    regex: ^master$|^main$
    mode: ContinuousDelivery
    label: ''
    increment: Patch
    prevent-increment:
      of-merged-branch: true
      when-branch-merged: false
      when-current-commit-tagged: true
    track-merge-target: false
    track-merge-message: false
    source-branches: [ ]
    is-source-branch-for: [ ]
    is-release-branch: false
    is-main-branch: true
  feature:
    regex: ^(WT-.*)
    mode: ManualDeployment
    label: 'rc'
    increment: Minor
    prevent-increment:
      of-merged-branch: true
      when-branch-merged: false
      when-current-commit-tagged: false
    track-merge-target: false
    track-merge-message: false
    source-branches:
      - main
      - feature
    is-source-branch-for: [ ]
    is-release-branch: false
    is-main-branch: false
  hotfix:
    regex: ^hotfix[/-](?<BranchName>.+)
    mode: ContinuousDelivery
    label: 'patch'
    increment: Patch
    prevent-increment:
      of-merged-branch: true
      when-branch-merged: true
      when-current-commit-tagged: false
    track-merge-target: false
    track-merge-message: false
    source-branches:
      - main
    is-source-branch-for: [ ]
    is-release-branch: false
    is-main-branch: false
  unknown:
    regex: (?<BranchName>.+)
    mode: ManualDeployment
    label: ''
    increment: Patch
    prevent-increment:
      of-merged-branch: true
      when-branch-merged: true
      when-current-commit-tagged: false
    track-merge-target: false
    track-merge-message: false
    source-branches:
      - main
      - feature
      - unknown
    is-source-branch-for: [ ]
    is-release-branch: false
    is-main-branch: false

I would appreciate it if you could indicate which required properties are not set, or have a wrong value.
I could not extract this information from the /diag outputs of my tests

And again, many thanks for helping out! 🙏

@HHobeck
Copy link
Contributor

HHobeck commented Feb 24, 2025

Yes no problem I can help you out with your custom workflow. But therefor you need to engage me. Please contact me per email to agree on the conditions.

@prantzos
Copy link
Author

Oh yes okay sure, I can contact you via email 👍

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

No branches or pull requests

2 participants