[ISSUE]: Mainline: version on main falls back to 0.0.x when a branch named in a merge message still exists

オープン
#5,405 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@arturcic がすでに取り組んでいます。

2026年10月9日 から。

  • #5295 @arturcic による — オープン

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
csharp, git
領域
backend, devtools

調査の方向性

Start by reviewing the Mainline strategy log and the branch source and merge-base lookup for main and part1; the issue includes a bash reproduction script that creates the problematic history. Run it with GitVersion.Tool 6.8.2, then trace how the existing part1 branch affects version selection. Done means the same version is calculated on main whether part1 exists or has been deleted.

索引モデルが issue の本文から書いたものです。

説明

bug
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.MsBuild

GitVersion version

6.8.2

Operating system

Windows

What are you seeing?

With the Mainline strategy, the version calculated on main depends on
whether a branch that is only named in a merge message on main still
exists. If it exists, the tag on main is ignored and the version is counted
from 0.0.0. If the branch is deleted, the same commit gets the expected
version.

In the minimal repro below, the same commit on main gets:

  • 1.0.0 while branch part1 exists. The base version is 0.0.2-1, and the
    result looks like it is then raised to the tag.
  • 1.0.7 after git branch -D part1.

The history is the usual "update a stacked feature branch, then complete the
pull request" flow:

  1. part2 is branched off part1.
  2. main is merged into part1.
  3. part1 is merged into part2 ("Merge branch 'part1' into part2").
  4. part2 is merged into main.

The merge message names part1. The log shows that GitVersion then looks for
the source of part1 and takes the merge base with main to be Part 1, not
the tip of part1. It ends up with CommitOnTrunk: Force version increment '0.0.2-1'.

In our real repository (Azure DevOps, PR merges with "Merged PR n: …"
messages, completed branches kept), every build on master produced
11.1.0 instead of 11.1.3xx after upgrading from GitVersion 5.12 to 6.8.2.
That was caused by one such kept branch. There is no warning and the build
succeeds, so it publishes packages with a wrong, lower version. On CI this
is easy to hit, because the checkout fetches all remote branches and
GitVersion creates local branches for them.

What is expected?

The version on main should not depend on whether a branch named in a
merge message still exists. The tag 1.0.0 on main should always be the
version source, so the result is the same with and without part1.

Workaround: setting track-merge-message: false on the main branch gives
the same version (1.0.9 in the repro) whether or not part1 exists.

Steps to Reproduce

Run this script with GitVersion.Tool 6.8.2 (dotnet tool install -g GitVersion.Tool --version 6.8.2). It works in bash on Linux and Git Bash on
Windows; set GV to the path of dotnet-gitversion if it is not on PATH.

#!/usr/bin/env bash
# GitVersion 6.8.2, Mainline strategy: the version on main changes when a
# branch named in a merge message on main still exists.
set -e
GV=${GV:-dotnet-gitversion}
rm -rf repro && mkdir repro && cd repro
git init -q -b main
git config user.name test; git config user.email [email protected]
cat > GitVersion.yml <<'YML'
workflow: GitFlow/v1
strategies:
- Mainline
branches:
  main:
    mode: ContinuousDeployment
    increment: Patch
YML
git add GitVersion.yml; git commit -q -m "Initial commit"
git tag 1.0.0
pr() { # a short-lived branch with one commit, merged into main with --no-ff
  git checkout -q -b "pr$1" main; git commit -q --allow-empty -m "Change $1"
  git checkout -q main; git merge -q --no-ff "pr$1" -m "Merged PR $1"; git branch -q -D "pr$1"; }

pr 1
git checkout -q -b part1 main;  git commit -q --allow-empty -m "Part 1"
git checkout -q -b part2 part1; git commit -q --allow-empty -m "Part 2"   # part2 builds on part1
git checkout -q main; pr 2
git checkout -q part1; git merge -q --no-ff main  -m "Merge branch 'main' into part1"
git checkout -q part2; git merge -q --no-ff part1 -m "Merge branch 'part1' into part2"
git checkout -q main;  git merge -q --no-ff part2 -m "Merged PR 3"; git branch -q -D part2
pr 4

ver() { "$GV" "$(pwd -W 2>/dev/null || pwd)" /nocache | grep '"FullSemVer"' | tr -d ' ",'; }
echo "branch part1 exists:  $(ver)"
git branch -q -D part1
echo "branch part1 deleted: $(ver)"

Output:

branch part1 exists:  FullSemVer:1.0.0
branch part1 deleted: FullSemVer:1.0.7

Resulting history:

*   Merged PR 4 (HEAD -> main)
|\
| * Change 4
|/
*   Merged PR 3
|\
| *   Merge branch 'part1' into part2
| |\
| | *   Merge branch 'main' into part1 (part1)
| | |\
| |_|/
|/| |
* | |   Merged PR 2
|\ \ \
| * | | Change 2
|/ / /
| * / Part 2
| |/
| * Part 1
|/
*   Merged PR 1
|\
| * Change 1
|/
* Initial commit (tag: 1.0.0)

Each step is needed. The bug does not show when:

  • the message of the part1 → part2 merge does not name part1,
  • main is not merged into part1 first, or
  • the branch named in the message is deleted.
RepositoryFixture Test

No response

Output log or link to your CI build (if appropriate).
Mainline part of the log with branch `part1` present (`/verbosity Diagnostic`,
DEBUG lines removed):


INFO Running against branch: main ('0e121dd' - Merged PR 4)
INFO -< Begin: Fetching the base versions for version calculation... >-
  INFO -< Begin: Calculating base versions for 'main' >-
    INFO -< Begin: [Using 'MainlineVersionStrategy' strategy] >-
      INFO -< Begin: Getting tagged semantic versions on branch 'refs/heads/main'. TagPrefix: [vV]? and Format: Strict >-
      INFO -< End: Getting tagged semantic versions on branch 'refs/heads/main'. TagPrefix: [vV]? and Format: Strict (Took: 8.39ms) >-
      INFO -< Begin: Finding branches source of 'main' >-
      INFO -< End: Finding branches source of 'main' (Took: 17.55ms) >-
      INFO -< Begin: Finding branches source of 'part1' >-
        INFO -< Begin: Finding merge base between 'part1' and 'main'. >-
          INFO Found merge base of ''12eaa6b' - Merge branch 'main' into part1'
          INFO next merge base --> '13c2268' - Part 1
          INFO Merge base of 'part1' and 'main' is ''13c2268' - Part 1'
        INFO -< End: Finding merge base between 'part1' and 'main'. (Took: 18.85ms) >-
      INFO -< End: Finding branches source of 'part1' (Took: 26.90ms) >-
      INFO CommitOnTrunk: Force version increment '0.0.2-1' +semver 'Patch' with label '' based on commit '723c890'.
    INFO -< End: [Using 'MainlineVersionStrategy' strategy] (Took: 317.22ms) >-
  INFO -< End: Calculating base versions for 'main' (Took: 336.23ms) >-
INFO -< End: Fetching the base versions for version calculation... (Took: 344.75ms) >-
INFO -------------------------------------------------------
INFO Base version used: CommitOnTrunk: Take '0.0.2-1' based on commit '723c890'.


Possibly related: thomhurst/TUnit#7215 reports an `InvalidOperationException`
in the Mainline strategy (GitVersion 6.7.0) when a merge message names
another branch that exists on origin.
主要言語
C#
スター
3.1k
フォーク
661
平均マージ
7時間 4分
マージ済み PR(30日)
77

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

GitTools/GitVersion のほかの issue

GitTools/GitVersion の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。