Skip to content

gh-159440: Pass --work-tree to the git commands used for the version tag - #159442

Merged
itamaro merged 1 commit into
python:mainfrom
sendaoYan:issue-159440-dirty
Oct 15, 2026
Merged

itamaro merged 1 commit into
python:mainfrom
sendaoYan:issue-159440-dirty

Conversation

@sendaoYan

@sendaoYan sendaoYan commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The GITTAG build stamp uses git --git-dir $(srcdir)/.git describe --all --always --dirty. --git-dir does not imply a work tree, so git falls back to the current directory. In an out-of-tree build make runs in the build tree, where none of the tracked files exist, so the internal diff-index HEAD of --dirty reports every tracked file as deleted and the tag always comes out as heads/<branch>-dirty — even for a pristine checkout. In-tree builds never hit this, and GITVERSION/GITBRANCH don't touch the work tree, so only the dirty check was wrong.

Pass --work-tree $(srcdir) for all three commands. The semantics of -dirty are preserved (a genuinely modified source tree still reports -dirty), and in-tree builds are unchanged because $(srcdir) is ..

Reproduce

sys.version reports a spurious -dirty git tag for out-of-tree builds, even when the checkout is pristine:

$ mkdir -p ~/build/cpython && cd ~/build/cpython
$ bash ~/git/cpython/configure --prefix=$HOME/opt/cpython > /dev/null
$ make -j && make install -j
$ ~/opt/cpython/bin/python3 -VV
Python 3.16.0a1+dev (heads/main-dirty:25883627946, Oct 14 2026, 22:17:06) [GCC 11.4.0]

Root cause

GITTAG uses git --git-dir $(srcdir)/.git describe --all --always --dirty. --git-dir does not imply a work tree, so git falls back to the current directory. In an out-of-tree build make runs in the build directory, where none of the tracked files exist, and the internal diff-index HEAD behind --dirty reports every tracked file as deleted. GITVERSION and GITBRANCH never touch the work tree, so only the dirty check was wrong.

Change

All three git commands now get --work-tree $(srcdir):

-    GITTAG="git --git-dir \$(srcdir)/.git describe --all --always --dirty"
+    GITTAG="git --git-dir \$(srcdir)/.git --work-tree \$(srcdir) describe --all --always --dirty"

The semantics of -dirty are preserved: a genuinely modified source tree still reports -dirty, and in-tree builds are unchanged because $(srcdir) is ..

Testing

  • Out-of-tree build from a clean checkout: ./python -VV reports heads/main: instead of heads/main-dirty:.
  • With an uncommitted change to a tracked file in the source tree, the rebuild correctly reports heads/main-dirty: again.
  • In-tree build: the git commands resolve to the same values as before ($(srcdir) is .).
  • git state checks / make regen-configure produce no further diff in configure, pyconfig.h.in or aclocal.m4.

Issue

…rsion tag

--git-dir alone does not imply a work tree, so in an out-of-tree build
git checked the build directory, and every tracked file looked deleted:
sys.version always carried a spurious "-dirty" suffix.
@itamaro itamaro self-assigned this Oct 15, 2026
@itamaro itamaro added build The build process and cross-build needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Oct 15, 2026

@itamaro itamaro 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.

looks good to me, thank you for the fix!

@itamaro
itamaro merged commit 637fb36 into python:main Oct 15, 2026
61 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @sendaoYan for the PR, and @itamaro for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Oct 15, 2026

Copy link
Copy Markdown

GH-159443 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Oct 15, 2026
@bedevere-app

bedevere-app Bot commented Oct 15, 2026

Copy link
Copy Markdown

GH-159444 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Oct 15, 2026
itamaro pushed a commit that referenced this pull request Oct 15, 2026
…ersion tag (GH-159442) (#159444)

gh-159440: Pass --work-tree to the git commands used for the version tag (GH-159442)

`--git-dir` alone does not imply a work tree, so in an out-of-tree build
git checked the build directory, and every tracked file looked deleted:
`sys.version` always carried a spurious "-dirty" suffix.
(cherry picked from commit 637fb36)

Co-authored-by: sendaoYan <yansendao@hygon.cn>
itamaro pushed a commit that referenced this pull request Oct 15, 2026
…ersion tag (GH-159442) (#159443)

gh-159440: Pass --work-tree to the git commands used for the version tag (GH-159442)

`--git-dir` alone does not imply a work tree, so in an out-of-tree build
git checked the build directory, and every tracked file looked deleted:
`sys.version` always carried a spurious "-dirty" suffix.
(cherry picked from commit 637fb36)

Co-authored-by: sendaoYan <yansendao@hygon.cn>
@sendaoYan
sendaoYan deleted the issue-159440-dirty branch October 15, 2026 05:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build The build process and cross-build

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants