From 29fda5543b6e5beaa3b5f515e66a179005c93211 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20J=2E=20Est=C3=A9banez?= Date: Mon, 9 Jan 2023 17:36:22 +0100 Subject: [PATCH] Support Git worktrees in generation of hash header (cherry picked from commit 078ab7fe05dcf139b7f943937c602b2c9dbdc8e2) --- methods.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/methods.py b/methods.py index 0ba86697a..2dea89882 100644 --- a/methods.py +++ b/methods.py @@ -119,6 +119,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):