get git hash 2

This commit is contained in:
Eren Golge 2018-04-06 03:55:44 -07:00
parent ddd3b9bb6e
commit a3f02b674a
1 changed files with 4 additions and 1 deletions

View File

@ -25,7 +25,10 @@ def load_config(config_path):
def get_commit_hash():
"""https://stackoverflow.com/questions/14989858/get-the-current-git-hash-in-a-python-script"""
subprocess.check_output(['git', 'diff-index', '--quiet', 'HEAD']) # Verify client is clean
try:
subprocess.check_output(['git', 'diff-index', '--quiet', 'HEAD']) # Verify client is clean
except:
raise RuntimeError(" !! Commit before training to get the commit hash.")
commit = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).decode().strip()
print(' > Git Hash: {}'.format(commit))
return commit