From ba707f56c1a89eb915d13b1590abfc2411924a9c Mon Sep 17 00:00:00 2001 From: Anastasis Andronidis Date: Wed, 5 Sep 2012 12:40:14 +0300 Subject: [PATCH] except now returns a 'n/a' version. Some changes in comments --- lib/ansible/utils.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/ansible/utils.py b/lib/ansible/utils.py index 3374510e13..c2bbaaed47 100644 --- a/lib/ansible/utils.py +++ b/lib/ansible/utils.py @@ -325,17 +325,15 @@ def _gitinfo(): repo_path = os.path.join(os.path.dirname(__file__), '..', '..', '.git') if os.path.exists(repo_path): - ''' Check if the .git is a file. If it is a file, it means that we are in a submodule structure. ''' + # Check if the .git is a file. If it is a file, it means that we are in a submodule structure. if os.path.isfile(repo_path): try: central_gitdir = yaml.load(open(repo_path)).get('gitdir').split('.git')[0] repo_path = repo_path.split('.git')[0] - ''' There is a posibility the .git file to have an absolute path. ''' + # There is a posibility the .git file to have an absolute path. repo_path = os.path.join(repo_path, os.path.relpath(central_gitdir), '.git') - except IOError: - exit("Could not load .git file.") - except AttributeError: - exit("There is no gitdir attribute in .git file.") + except (IOError, AttributeError): + return 'n/a' f = open(os.path.join(repo_path, "HEAD")) branch = f.readline().split('/')[-1].rstrip("\n") f.close()