Skip to content

Commit

Permalink
Fix current git commit hash detection when on a detached head
Browse files Browse the repository at this point in the history
  • Loading branch information
LagoLunatic committed Jan 31, 2019
1 parent 09a5b62 commit a0d85e8
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions randomizer.py
Expand Up @@ -40,14 +40,18 @@
git_commit_head_file = os.path.join(RANDO_ROOT_PATH, ".git", "HEAD")
if os.path.isfile(git_commit_head_file):
with open(git_commit_head_file, "r") as f:
head_file_contents = f.read()
head_file_contents = f.read().strip()
if head_file_contents.startswith("ref: "):
relative_path_to_hash_file = head_file_contents[len("ref: "):].strip()
# Normal head, HEAD file has a reference to a branch which contains the commit hash
relative_path_to_hash_file = head_file_contents[len("ref: "):]
path_to_hash_file = os.path.join(RANDO_ROOT_PATH, ".git", relative_path_to_hash_file)
if os.path.isfile(path_to_hash_file):
with open(path_to_hash_file, "r") as f:
hash_file_contents = f.read()
version_suffix = "_" + hash_file_contents[:7]
elif re.search(r"^[0-9a-f]{40}$", head_file_contents):
# Detached head, commit hash directly in the HEAD file
version_suffix = "_" + head_file_contents[:7]

VERSION += version_suffix

Expand Down

0 comments on commit a0d85e8

Please sign in to comment.