Skip to content

Commit

Permalink
Get Git commit hash when Godot is a submodule
Browse files Browse the repository at this point in the history
Submodules don't have a .git folder in the same place, but a .git file
that points to the actual folder. This change take this into account.
  • Loading branch information
vnen committed Feb 8, 2019
1 parent 5e837b3 commit 874cbef
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,22 @@ def update_version(module_version_string=""):
# NOTE: It is safe to generate this file here, since this is still executed serially
fhash = open("core/version_hash.gen.h", "w")
githash = ""
if os.path.isfile(".git/HEAD"):
head = open(".git/HEAD", "r").readline().strip()
gitfolder = ".git"

if os.path.isfile(".git"):
module_folder = open(".git", "r").readline().strip()
if module_folder.startswith("gitdir: "):
gitfolder = module_folder[8:]

if os.path.isfile(os.path.join(gitfolder, "HEAD")):
head = open(os.path.join(gitfolder, "HEAD"), "r").readline().strip()
if head.startswith("ref: "):
head = ".git/" + head[5:]
head = os.path.join(gitfolder, head[5:])
if os.path.isfile(head):
githash = open(head, "r").readline().strip()
else:
githash = head

fhash.write("#define VERSION_HASH \"" + githash + "\"")
fhash.close()

Expand Down

0 comments on commit 874cbef

Please sign in to comment.