fix _gitinfo function to avoid ansible crashing in cases where the branch file is missing (e.g. after a gc)
This commit is contained in:
parent
bf92a9e4e0
commit
5c4a523148
1 changed files with 3 additions and 0 deletions
|
@ -317,6 +317,7 @@ def _gitinfo():
|
||||||
branch = f.readline().split('/')[-1].rstrip("\n")
|
branch = f.readline().split('/')[-1].rstrip("\n")
|
||||||
f.close()
|
f.close()
|
||||||
branch_path = os.path.join(repo_path, "refs", "heads", branch)
|
branch_path = os.path.join(repo_path, "refs", "heads", branch)
|
||||||
|
if os.path.exists(branch_path):
|
||||||
f = open(branch_path)
|
f = open(branch_path)
|
||||||
commit = f.readline()[:10]
|
commit = f.readline()[:10]
|
||||||
f.close()
|
f.close()
|
||||||
|
@ -327,6 +328,8 @@ def _gitinfo():
|
||||||
offset = time.altzone
|
offset = time.altzone
|
||||||
result = "({0} {1}) last updated {2} (GMT {3:+04d})".format(branch, commit,
|
result = "({0} {1}) last updated {2} (GMT {3:+04d})".format(branch, commit,
|
||||||
time.strftime("%Y/%m/%d %H:%M:%S", date), offset / -36)
|
time.strftime("%Y/%m/%d %H:%M:%S", date), offset / -36)
|
||||||
|
else:
|
||||||
|
result = 'n/a'
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def version(prog):
|
def version(prog):
|
||||||
|
|
Loading…
Reference in a new issue