mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Read git version from file as back up in make.py (#4247)
* Read git version from file rather than using Git client * Use git files reading only as fallback
This commit is contained in:
parent
1f8f463f32
commit
4d81a21e3f
@ -678,20 +678,47 @@ def get_commit_ID():
|
||||
# Get latest commit ID
|
||||
global make_root
|
||||
curDir = os.getcwd()
|
||||
commit_id = ""
|
||||
|
||||
try:
|
||||
# Verify if Git repository
|
||||
gitpath = os.path.join(os.path.dirname(make_root), ".git")
|
||||
assert os.path.exists(gitpath)
|
||||
os.chdir(make_root)
|
||||
|
||||
# Try to get commit ID through Git client
|
||||
os.chdir(make_root)
|
||||
commit_id = subprocess.check_output(["git", "rev-parse", "HEAD"])
|
||||
commit_id = str(commit_id, "utf-8")[:8]
|
||||
except FileNotFoundError:
|
||||
# Try to get commit ID from git files (subprocess failed - eg. no Git client)
|
||||
head_path = os.path.join(gitpath, "HEAD")
|
||||
if os.path.exists(head_path):
|
||||
with open(head_path, "r") as head_file:
|
||||
branch_path = head_file.readline().split(": ")
|
||||
|
||||
# Commit ID is written in HEAD file directly when in detached state
|
||||
if len(branch_path) == 1:
|
||||
commit_id = branch_path[0]
|
||||
else:
|
||||
branch_path = branch_path[-1].strip()
|
||||
ref_path = os.path.join(gitpath, branch_path)
|
||||
if os.path.exists(ref_path):
|
||||
with open(ref_path, "r") as ref_file:
|
||||
commit_id = ref_file.readline()
|
||||
|
||||
if commit_id != "":
|
||||
commit_id = commit_id.strip()[:8]
|
||||
else:
|
||||
raise
|
||||
except:
|
||||
print_error("FAILED TO DETERMINE COMMIT ID.")
|
||||
print_yellow("Verify that \GIT\BIN or \GIT\CMD is in your system path or user path.")
|
||||
commit_id = "NOGIT"
|
||||
raise
|
||||
# All other exceptions (eg. AssertionException)
|
||||
if commit_id == "":
|
||||
raise
|
||||
finally:
|
||||
pass
|
||||
if commit_id == "":
|
||||
print_error("Failed to determine commit ID - folder is not a Git repository.")
|
||||
commit_id = "NOGIT"
|
||||
os.chdir(curDir)
|
||||
|
||||
print_yellow("COMMIT ID set to {}".format(commit_id))
|
||||
|
Loading…
Reference in New Issue
Block a user