Deal with .git being a file when getting the VCS commit hash during building

This commit is contained in:
Kovid Goyal 2019-06-23 07:36:03 +05:30
parent 2b78f5adad
commit 96703c23c8
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -308,9 +308,15 @@ def get_vcs_rev_defines():
try:
rev = subprocess.check_output(['git', 'rev-parse', 'HEAD']).decode('utf-8').strip()
except FileNotFoundError:
with open('.git/refs/heads/master') as f:
rev = f.read()
ans.append('KITTY_VCS_REV="{}"'.format(rev))
try:
with open('.git/refs/heads/master') as f:
rev = f.read()
except NotADirectoryError:
gitloc = open('.git').read()
with open(os.path.join(gitloc, '/refs/heads/master')) as f:
rev = f.read()
ans.append('KITTY_VCS_REV="{}"'.format(rev.strip()))
return ans