Skip to content

Commit ab9b474

Browse files
committed
pythongh-159440: Pass --work-tree to the git commands used for the version tag
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 `.`.
1 parent a6b4aa6 commit ab9b474

3 files changed

Lines changed: 9 additions & 6 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The version string reported by ``sys.version`` no longer carries a spurious
2+
``-dirty`` suffix when CPython is built out-of-tree from a clean git checkout:
3+
the build stamp now checks the source tree instead of the build directory.

‎configure‎

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎configure.ac‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ HAS_GIT=no-repository
128128
fi
129129
if test $HAS_GIT = found
130130
then
131-
GITVERSION="git --git-dir \$(srcdir)/.git rev-parse --short HEAD"
132-
GITTAG="git --git-dir \$(srcdir)/.git describe --all --always --dirty"
133-
GITBRANCH="git --git-dir \$(srcdir)/.git name-rev --name-only HEAD"
131+
GITVERSION="git --git-dir \$(srcdir)/.git --work-tree \$(srcdir) rev-parse --short HEAD"
132+
GITTAG="git --git-dir \$(srcdir)/.git --work-tree \$(srcdir) describe --all --always --dirty"
133+
GITBRANCH="git --git-dir \$(srcdir)/.git --work-tree \$(srcdir) name-rev --name-only HEAD"
134134
else
135135
GITVERSION=""
136136
GITTAG=""

0 commit comments

Comments
 (0)