Merge pull request #71118 from RandomShaper/git_worktrees

Support Git worktrees in generation of hash header
This commit is contained in:
Rémi Verschelde 2023-01-09 17:51:27 +01:00
commit be753a40a7
No known key found for this signature in database
GPG Key ID: C3336907360768E1
1 changed files with 4 additions and 0 deletions

View File

@ -111,6 +111,10 @@ def get_version_info(module_version_string="", silent=False):
head = open(os.path.join(gitfolder, "HEAD"), "r", encoding="utf8").readline().strip()
if head.startswith("ref: "):
ref = head[5:]
# If this directory is a Git worktree instead of a root clone.
parts = gitfolder.split("/")
if len(parts) > 2 and parts[-2] == "worktrees":
gitfolder = "/".join(parts[0:-2])
head = os.path.join(gitfolder, ref)
packedrefs = os.path.join(gitfolder, "packed-refs")
if os.path.isfile(head):