gh-159440: Pass --work-tree to the git commands used for the version tag (#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.
3 files changed