From 5c4a5231480fc7bb70b3fd639a75c242a24d364f Mon Sep 17 00:00:00 2001 From: Pepe Barbe Date: Wed, 22 Aug 2012 13:54:25 -0500 Subject: [PATCH] fix _gitinfo function to avoid ansible crashing in cases where the branch file is missing (e.g. after a gc) --- lib/ansible/utils.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/ansible/utils.py b/lib/ansible/utils.py index 2b21ac0ec6..5a0fb46b5c 100644 --- a/lib/ansible/utils.py +++ b/lib/ansible/utils.py @@ -317,6 +317,7 @@ def _gitinfo(): branch = f.readline().split('/')[-1].rstrip("\n") f.close() branch_path = os.path.join(repo_path, "refs", "heads", branch) + if os.path.exists(branch_path): f = open(branch_path) commit = f.readline()[:10] f.close() @@ -327,6 +328,8 @@ def _gitinfo(): offset = time.altzone result = "({0} {1}) last updated {2} (GMT {3:+04d})".format(branch, commit, time.strftime("%Y/%m/%d %H:%M:%S", date), offset / -36) + else: + result = 'n/a' return result def version(prog):