Skip to content

feat: resolve increments from merged branches - #5140

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

fzlzjerry wants to merge 24 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

Moves merged-branch increment selection into IncrementStrategyFinder.DetermineIncrementedField, so every version strategy that already uses the finder receives the same behavior without adding a separate strategy or configuration surface.

For a branch with merge-message tracking enabled that is either an effective main branch or a compatible descendant preserving main-branch history through linear work and main-to-descendant updates, the finder separates first-parent target work from recognized two-parent merges. It calculates each source branch's effective increment from the merged history, preserves source +semver / =semver handling, and applies the target/source settings as follows:

Target of-merged-branch Source when-branch-merged Effective contribution
false false Target + source increment
false true Target increment
true false Source increment
true true Target increment

Main-to-descendant update merges carry main's recursively derived version floor rather than treating main as a completed source branch. Unrelated intervening merges still keep the descendant outside merge-history processing.

Direct target commits still contribute the target increment, unrecognized merge histories remain target-configured work, synthetic pull-request refs stay outside merge-history processing, and the highest contribution across multiple merges wins. Inherited source increments are resolved from the historical merged tip, including deleted or recreated topic refs and source branches that absorb the topic later. Per-merge and ancestry results use configuration-aware cache keys because the finder evaluates multiple base-version candidates for the same current commit.

Related Issue

Resolves #4433

Motivation and Context

Outside mainline calculation, a no-fast-forward merge currently falls back to the target branch's configured increment. This 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. The increment finder already owns configured and commit-message increment precedence, so handling merged histories there keeps the behavior consistent across dependent version strategies.

How Has This Been Tested?

Revalidated on Linux with .NET SDK 10.0.400 at 6d1169c5f after rebasing onto 88086843:

  • Added 46 integration cases covering the four effective configuration combinations, GitFlow/GitHubFlow acceptance scenarios, multiple merges and reset directives, target work before and after a merge, source commit-message overrides, unrecognized and ignored-merge side histories including chronological directive ordering across recognized boundaries, tagged and future-dated source tips including selected stable tags across source labels, inherited prevention and effective main-branch settings including source-branch inheritance, ignored branches including current and compatible-descendant main-history exceptions, synthetic pull-request refs, intervening target tags, pruned target segments, and off-first-parent base boundaries, nested and sibling inheritance for historical and retained tips, descendant-branch version floors including main update merges and an unrelated-merge guard, historical/local/remote source resolution, and retained/deleted orphan fallback parity including unresolved-Inherit skipping.
  • Added a focused IncrementStrategyFinder unit case proving that commit-message cache entries are isolated by regex configuration.
  • Updated the existing GitFlow/GitHubFlow alignment and merge scenarios to assert the corrected results.
  • dotnet build ./src/GitVersion.slnx --no-restore --verbosity:minimal -m:1 — succeeded with 0 warnings and 0 errors.
  • dotnet test --solution ./src/GitVersion.slnx --no-build --no-restore --max-parallel-test-modules 1 --no-progress --output Normal with TMPDIR and RUNNER_TEMP set to a clean directory under /var/tmp with no .git ancestor — 37,498 succeeded, 0 failed.
  • dotnet format --verify-no-changes ./src/GitVersion.slnx --no-restore — succeeded.
  • git diff --check — 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
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
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.

@fzlzjerry
fzlzjerry force-pushed the feat/4433-prevent-merged-branch-increment branch from 6d1169c to 2d9a2bd Compare September 10, 2026 23:37
Copilot AI review requested due to automatic review settings September 10, 2026 23:37

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

@fzlzjerry

Copy link
Copy Markdown
Contributor Author

Updated the branch onto current main (d29129202) as 2d9a2bd28. The original 23 commits remain separate; the rebase conflict in the recursive version calculation call retains upstream's currentCommit parameter.

The updated label API also required one compatibility adjustment in merged-branch increment lookup: SHA placeholders must use the commit being versioned, not the merged source tip. Four new cases cover both Git backends, full/short SHA labels and historical calculation after HEAD advances. A source-tip variant incorrectly returned 2.0.0 instead of 1.0.1; the final calculation-commit version passes all four.

Validation with .NET SDK 10.0.401:

  • src/GitVersion.slnx build: 0 warnings, 0 errors.
  • Full committed legacy solution tests: 37,601 passed, 0 failed, 0 skipped.
  • Formatting verification and git diff --check: passed.

The existing merge-prevention consolidation methods are unchanged. The behavior questions from the earlier discussion remain separate from this compatibility update.

@HHobeck

HHobeck commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Okay thank you! I will take a look soon.

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

5 participants