Title: Out-of-tree builds always report a "-dirty" git tag in sys.version · Issue #159440 · python/cpython · GitHub
Open Graph Title: Out-of-tree builds always report a "-dirty" git tag in sys.version · Issue #159440 · python/cpython
X Title: Out-of-tree builds always report a "-dirty" git tag in sys.version · Issue #159440 · python/cpython
Description: Bug report sys.version embeds the output of git describe --all --always --dirty, which is compiled into the interpreter via -DGITTAG (Modules/getbuildinfo.o recipe in Makefile.pre.in). When CPython is built out-of-tree, that tag is alway...
Open Graph Description: Bug report sys.version embeds the output of git describe --all --always --dirty, which is compiled into the interpreter via -DGITTAG (Modules/getbuildinfo.o recipe in Makefile.pre.in). When CPython...
X Description: Bug report sys.version embeds the output of git describe --all --always --dirty, which is compiled into the interpreter via -DGITTAG (Modules/getbuildinfo.o recipe in Makefile.pre.in). When CPython...
Opengraph URL: https://github.com/python/cpython/issues/159440
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Out-of-tree builds always report a \"-dirty\" git tag in sys.version","articleBody":"### Bug report\n\n`sys.version` embeds the output of `git describe --all --always --dirty`, which is compiled into the interpreter via `-DGITTAG` (`Modules/getbuildinfo.o` recipe in `Makefile.pre.in`). When CPython is built **out-of-tree**, that tag is always reported as `-dirty`, even when the source checkout has no local modifications, because `configure.ac` passes `--git-dir` without `--work-tree`.\n\n#### Reproduction\n\n```console\n$ git -C ~/git/cpython status --short # clean checkout, no output\n$ mkdir -p ~/build/cpython && cd ~/build/cpython\n$ bash ~/git/cpython/configure --prefix=$HOME/opt/cpython > /dev/null\n$ make -j && make install -j\n$ ~/opt/cpython/bin/python3 -VV\nPython 3.16.0a1+dev (heads/main-dirty:25883627946, Oct 14 2026, 22:17:06) [GCC 11.4.0]\n ^^^^^\n```\n\nThe -dirty suffix is bogus: the checkout is at 25883627946b7cbcf7286acfe2a2019382375325 with an unmodified work tree.\n\n#### Root cause\nconfigure.ac defines the git commands used for the build stamp:\n\n```bash\nGITVERSION=\"git --git-dir \\$(srcdir)/.git rev-parse --short HEAD\"\nGITTAG=\"git --git-dir \\$(srcdir)/.git describe --all --always --dirty\"\nGITBRANCH=\"git --git-dir \\$(srcdir)/.git name-rev --name-only HEAD\"\n```\n--git-dir only says where the repository is; it does not set the work tree, which therefore defaults to the current directory. In an out-of-tree build, make runs in the build directory, so the internal diff-index HEAD that implements git describe --dirty resolves every tracked path against the build directory, where none of them exist. Every tracked file is treated as deleted, and the tree is reported as dirty.\n\nRun from the build directory against a clean source tree:\n\n```\n$ cd ~/build/cpython\n$ git --git-dir=$HOME/git/cpython/.git diff-index --name-only HEAD | wc -l\n5490 # all tracked files appear deleted\n$ git --git-dir=$HOME/git/cpython/.git describe --all --always --dirty\nheads/main-dirty\n$ git --git-dir=$HOME/git/cpython/.git --work-tree=$HOME/git/cpython describe --all --always --dirty\nheads/main\n$ strings ~/build/cpython/Modules/getbuildinfo.o | grep heads/\nheads/main-dirty # the string that ends up in the binary\n```\nGITVERSION (rev-parse --short HEAD) and GITBRANCH (name-rev --name-only HEAD) are unaffected because they never touch the work tree — only the --dirty check is. In-tree builds are unaffected too, which is presumably why this went unnoticed.\n\n#### Proposed fix\nPass the work tree explicitly (equivalently, run git with -C $(srcdir)):\n\n```bash\nGITVERSION=\"git --git-dir \\$(srcdir)/.git --work-tree \\$(srcdir) rev-parse --short HEAD\"\nGITTAG=\"git --git-dir \\$(srcdir)/.git --work-tree \\$(srcdir) describe --all --always --dirty\"\nGITBRANCH=\"git --git-dir \\$(srcdir)/.git --work-tree \\$(srcdir) name-rev --name-only HEAD\"\n```\nThe suffix keeps its intended meaning: local modifications to the source tree are still reported, while an out-of-tree build of a clean checkout now reports a clean tag. In-tree builds are byte-for-byte unaffected since $(srcdir) is ..\n\n#### Workaround\nUntil this is fixed, an out-of-tree build can be nudged into reporting the right tag by overriding GITTAG and forcing Modules/getbuildinfo.o to be recompiled (it does not depend on Makefile, so reconfiguring alone will not rebuild it):\n\n```bash\n$ rm -f Modules/getbuildinfo.o\n$ make -j GITTAG=\"git --git-dir=$PWD/../cpython/.git --work-tree=$PWD/../cpython describe --all --always --dirty\"\n$ make install\n```\n\n#### Affected versions\n3.7 and later: --dirty was added by bpo-27593 (554626ada76, 2017-03-20) and first shipped in 3.7.0a1. Only out-of-tree builds are affected.\n\n\n\n\n\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-159442\n* gh-159443\n* gh-159444\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/sendaoYan","@type":"Person","name":"sendaoYan"},"datePublished":"2026-10-15T02:22:36Z","url":"https://github.com/python/cpython/issues/159440"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:21a17f18-6f08-6acb-1fd7-af9765c8acfa |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9218:28831:50BBCD:705DA1:6AFEA441 |
| html-safe-nonce | 9f20347655722932c225246647b801b25f26bc33a834eca2f2ea375e523aeb4a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MjE4OjI4ODMxOjUwQkJDRDo3MDVEQTE6NkFGRUE0NDEiLCJ2aXNpdG9yX2lkIjoiNTQ1MjMwNzU5MzYwNTA2Mzc0NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 7a2fccdba738439a0f5b8501544b9d7e651fede43ba08351a3e33a4b94646a06 |
| hovercard-subject-tag | issue:5858966873 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/159440/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9a39d413e465594cd675d188b6818b088134662082cec2aeb71e8126940bb33d/python/cpython/issues/159440 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9a39d413e465594cd675d188b6818b088134662082cec2aeb71e8126940bb33d/python/cpython/issues/159440 |
| og:image:alt | Bug report sys.version embeds the output of git describe --all --always --dirty, which is compiled into the interpreter via -DGITTAG (Modules/getbuildinfo.o recipe in Makefile.pre.in). When CPython... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sendaoYan |
| hostname | github.com |
| expected-hostname | github.com |
| None | 95b2753c978240785d6cca00783c00a371b2d7d9879bb32e305170a1b19bd28e |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 3f25273206cd841171bca0002261ae4c9757d934 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width