Skip to content

feat: add merge commit version strategy - #5140

Open
fzlzjerry wants to merge 8 commits into
GitTools:mainfrom
fzlzjerry:feat/4433-prevent-merged-branch-increment
Open

feat: add merge commit version strategy#5140
fzlzjerry wants to merge 8 commits into
GitTools:mainfrom
fzlzjerry:feat/4433-prevent-merged-branch-increment

Conversation

@fzlzjerry

@fzlzjerry fzlzjerry commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Description

Adds a configurable MergeCommit version strategy for GitFlow and GitHubFlow main branches with prevent-increment.of-merged-branch enabled.

The strategy walks the target branch's first-parent history, uses the latest target-branch version tag as the reset boundary, and consolidates the highest effective increment across the post-tag history. Recognized merges contribute the source branch configuration, while direct target commits and merges whose source cannot be resolved contribute the target branch configuration. Repeated increments of the same kind do not accumulate. Source-branch commit-message increments and reset messages are honored, as is prevent-increment.when-branch-merged; nested merge branch configurations do not replace the directly merged branch configuration.

The strategy also preserves tags introduced by merged branches as alternative semantic versions and suppresses the regular tagged-commit candidate while active, so a larger target-branch increment cannot override the merged-branch increment. Each alternative tag tracks only increments encountered from the point where it enters the target history, allowing post-tag work to advance a higher merged tag without reapplying earlier target work. Historical source references are scored by graph distance before local-versus-remote preference is applied. The strategy is enabled in the GitFlow and GitHubFlow defaults and can be disabled through strategies.

Related Issue

Resolves #4433

Motivation and Context

Outside the mainline strategy, a no-fast-forward merge currently falls back to the target branch's configured increment. That makes a patch hotfix merged into a minor-increment main branch produce a minor version, and a minor feature merged into a patch-increment main branch produce a patch version. This change lets the merged branch determine the increment while retaining the existing tag-based version source and non-cumulative workflow semantics.

How Has This Been Tested?

Tested on Linux with .NET SDK 10.0.400:

  • Added 35 integration cases covering GitFlow and GitHubFlow acceptance scenarios, disabled strategy behavior, repeated merges, highest-increment selection, tag reset boundaries, commit-message increments and resets, when-branch-merged, nested merges, merged-branch tags and their post-tag increments (including a tag at the source tip with no later work), unrelated histories, inherited source-branch increments (including ignored commits, reused local names, valid remote refs, sources that later absorb the topic, and retained branches that later absorb the target), inherited main-branch configurations, target commits before and after recognized merges, unrecognized later merges with tags, older higher target tags behind later lower tags, merge-message ordering, and timestamp-skewed tags and first-parent traversal.
  • Added a focused source-selection unit case covering same-named local and remote refs with different ancestry distances.
  • dotnet build ./src/GitVersion.slnx --configuration Release --no-restore --verbosity minimal — succeeded with 0 warnings and 0 errors.
  • dotnet test --solution ./src/GitVersion.slnx --configuration Release --no-build --output Normal — 37,238 succeeded, 0 failed.
  • dotnet format ./src/GitVersion.slnx --verify-no-changes --no-restore --verbosity minimal — succeeded.

Screenshots (if appropriate):

N/A

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.

Copilot AI lite review requested due to automatic review settings August 17, 2026 11:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 18f6910930

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copilot AI review requested due to automatic review settings August 17, 2026 12:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4e34bfa475

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@fzlzjerry
fzlzjerry force-pushed the feat/4433-prevent-merged-branch-increment branch from 4e34bfa to f6b83bb Compare August 17, 2026 12:57
Copilot AI review requested due to automatic review settings August 17, 2026 12:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f6b83bb5c1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copilot AI review requested due to automatic review settings August 17, 2026 13:44
@fzlzjerry
fzlzjerry force-pushed the feat/4433-prevent-merged-branch-increment branch from f6b83bb to 52598be Compare August 17, 2026 13:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 52598be177

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copilot AI review requested due to automatic review settings August 17, 2026 14:02
@fzlzjerry
fzlzjerry force-pushed the feat/4433-prevent-merged-branch-increment branch from 52598be to 1c8f29f Compare August 17, 2026 14:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@arturcic
arturcic requested a review from HHobeck August 17, 2026 16:41
Walk first-parent history in ancestry order, resolve inherited increments from the merged branch source, and remove identical conditional test branches flagged by analysis.
Resolve reused branch names from the historical first-parent lineage, align source reset detection with tagged commit history, preserve merge-message ordering, and stop scanning at the latest target tag.
Copilot AI review requested due to automatic review settings August 18, 2026 12:24
@fzlzjerry
fzlzjerry force-pushed the feat/4433-prevent-merged-branch-increment branch from 1c8f29f to 3f8211c Compare August 18, 2026 12:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3f8211c580

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copilot AI review requested due to automatic review settings August 18, 2026 12:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d8823790f7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copilot AI review requested due to automatic review settings August 18, 2026 13:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5cee297f10

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread docs/input/docs/reference/version-sources.md Outdated
Keep merged tags tied to post-tag work, reconstruct inherited branch configuration from the historical merge tip, and retain higher first-parent tag candidates across later target tags.

Also enable the strategy for inherited main configurations without applying it to pull request branches, and document how target-branch work contributes to the effective increment.
Copilot AI review requested due to automatic review settings August 18, 2026 13:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@sonarqubecloud

Copy link
Copy Markdown

@HHobeck

HHobeck commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Thank you very much for the PR. Actually, I need some time for the review.

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.

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

3 participants