mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
except now returns a 'n/a' version. Some changes in comments
This commit is contained in:
parent
63b4f8dd80
commit
ba707f56c1
1 changed files with 4 additions and 6 deletions
|
@ -325,17 +325,15 @@ def _gitinfo():
|
||||||
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. '''
|
# 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):
|
if os.path.isfile(repo_path):
|
||||||
try:
|
try:
|
||||||
central_gitdir = yaml.load(open(repo_path)).get('gitdir').split('.git')[0]
|
central_gitdir = yaml.load(open(repo_path)).get('gitdir').split('.git')[0]
|
||||||
repo_path = repo_path.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')
|
repo_path = os.path.join(repo_path, os.path.relpath(central_gitdir), '.git')
|
||||||
except IOError:
|
except (IOError, AttributeError):
|
||||||
exit("Could not load .git file.")
|
return 'n/a'
|
||||||
except AttributeError:
|
|
||||||
exit("There is no gitdir attribute in .git file.")
|
|
||||||
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()
|
||||||
|
|
Loading…
Reference in a new issue