Support Git worktrees in generation of hash header

(cherry picked from commit 078ab7fe05)
This commit is contained in:
Pedro J. Estébanez 2023-01-09 17:36:22 +01:00 committed by Rémi Verschelde
parent 90132061f5
commit 5703cc861f
No known key found for this signature in database
GPG key ID: C3336907360768E1

View file

@ -121,6 +121,10 @@ def get_version_info(module_version_string="", silent=False):
head = open_utf8(os.path.join(gitfolder, "HEAD"), "r").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):