Commit 0c386b05 by Michael DeHaan

Merge pull request #993 from andronat/repo-as-submodule

Fixed a parsing HEAD problem, when ansible is checked out as a submodule
parents ca7b5cc5 ba707f56
...@@ -323,7 +323,17 @@ def _gitinfo(): ...@@ -323,7 +323,17 @@ def _gitinfo():
''' returns a string containing git branch, commit id and commit date ''' ''' returns a string containing git branch, commit id and commit date '''
result = None result = None
repo_path = os.path.join(os.path.dirname(__file__), '..', '..', '.git') repo_path = os.path.join(os.path.dirname(__file__), '..', '..', '.git')
if os.path.exists(repo_path): 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.
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.
repo_path = os.path.join(repo_path, os.path.relpath(central_gitdir), '.git')
except (IOError, AttributeError):
return 'n/a'
f = open(os.path.join(repo_path, "HEAD")) f = open(os.path.join(repo_path, "HEAD"))
branch = f.readline().split('/')[-1].rstrip("\n") branch = f.readline().split('/')[-1].rstrip("\n")
f.close() f.close()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment