[ISSUE]: Mainline: version on main falls back to 0.0.x when a branch named in a merge message still exists
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.0while branchpart1exists. The base version is0.0.2-1, and the
result looks like it is then raised to the tag.1.0.7aftergit branch -D part1.
The history is the usual "update a stacked feature branch, then complete the
pull request" flow:
part2is branched offpart1.mainis merged intopart1.part1is merged intopart2("Merge branch 'part1' into part2").part2is merged intomain.
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→part2merge does not namepart1, mainis not merged intopart1first, 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.
- Ngôn ngữ chính
- C#
- Star
- 3.1k
- Fork
- 661
- Merge trung bình
- 7 giờ 4 phút
- Pull request đã merge (30 ngày)
- 77
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của GitTools/GitVersion
-
feature
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
GitTools/GitVersion#5398 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
GitTools/GitVersion#5267 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 30/100
GitTools/GitVersion#5188 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
breaking change pinned
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
GitTools/GitVersion#5137 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
breaking change configuration
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
GitTools/GitVersion#5136 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của GitTools/GitVersion
Issue tương tự
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
-
area/backend type/bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
umbraco/Umbraco-CMS#24668 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Pri3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
MicrosoftDocs/windows-dev-docs#6205 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày