Skip to content

Commit a0d85e8

Browse files
committed
Fix current git commit hash detection when on a detached head
1 parent 09a5b62 commit a0d85e8

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

randomizer.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,18 @@
4040
git_commit_head_file = os.path.join(RANDO_ROOT_PATH, ".git", "HEAD")
4141
if os.path.isfile(git_commit_head_file):
4242
with open(git_commit_head_file, "r") as f:
43-
head_file_contents = f.read()
43+
head_file_contents = f.read().strip()
4444
if head_file_contents.startswith("ref: "):
45-
relative_path_to_hash_file = head_file_contents[len("ref: "):].strip()
45+
# Normal head, HEAD file has a reference to a branch which contains the commit hash
46+
relative_path_to_hash_file = head_file_contents[len("ref: "):]
4647
path_to_hash_file = os.path.join(RANDO_ROOT_PATH, ".git", relative_path_to_hash_file)
4748
if os.path.isfile(path_to_hash_file):
4849
with open(path_to_hash_file, "r") as f:
4950
hash_file_contents = f.read()
5051
version_suffix = "_" + hash_file_contents[:7]
52+
elif re.search(r"^[0-9a-f]{40}$", head_file_contents):
53+
# Detached head, commit hash directly in the HEAD file
54+
version_suffix = "_" + head_file_contents[:7]
5155

5256
VERSION += version_suffix
5357

0 commit comments

Comments
 (0)