mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-03 04:34:24 -07:00
Updated version info to include submodule information
`ansible --version` etc. now include information about submodules
```
ansible 1.8 (submodule_ansible_version ffee9a8fe0
) last updated 2014/09/28 11:03:14 (GMT +1000)
lib/ansible/modules/core: (ec2_snapshot_remove 3a77c31ecb) last updated 2014/09/27 18:23:31 (GMT +1000)
lib/ansible/modules/extras: (detached HEAD 110250d344) last updated 2014/09/27 14:33:42 (GMT +1000)
```
Also improved handling of detached HEAD when printing out version
information.
This commit is contained in:
parent
4f44a8ab75
commit
d1476aeb01
1 changed files with 31 additions and 10 deletions
|
@ -832,11 +832,10 @@ def default(value, function):
|
||||||
return function()
|
return function()
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def _gitinfo():
|
|
||||||
|
def _gitrepoinfo(repo_path):
|
||||||
''' 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')
|
|
||||||
|
|
||||||
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):
|
||||||
|
@ -857,6 +856,12 @@ def _gitinfo():
|
||||||
f = open(branch_path)
|
f = open(branch_path)
|
||||||
commit = f.readline()[:10]
|
commit = f.readline()[:10]
|
||||||
f.close()
|
f.close()
|
||||||
|
else:
|
||||||
|
# detached HEAD
|
||||||
|
commit = branch[:10]
|
||||||
|
branch = 'detached HEAD'
|
||||||
|
branch_path = os.path.join(repo_path, "HEAD")
|
||||||
|
|
||||||
date = time.localtime(os.stat(branch_path).st_mtime)
|
date = time.localtime(os.stat(branch_path).st_mtime)
|
||||||
if time.daylight == 0:
|
if time.daylight == 0:
|
||||||
offset = time.timezone
|
offset = time.timezone
|
||||||
|
@ -868,6 +873,22 @@ def _gitinfo():
|
||||||
result = ''
|
result = ''
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def _gitinfo():
|
||||||
|
basedir = os.path.join(os.path.dirname(__file__), '..', '..', '..')
|
||||||
|
repo_path = os.path.join(basedir, '.git')
|
||||||
|
result = _gitrepoinfo(repo_path)
|
||||||
|
submodules = os.path.join(basedir, '.gitmodules')
|
||||||
|
f = open(submodules)
|
||||||
|
for line in f:
|
||||||
|
tokens = line.strip().split(' ')
|
||||||
|
if tokens[0] == 'path':
|
||||||
|
repo_path = tokens[2]
|
||||||
|
result += "\n {0}: {1}".format(repo_path, _gitrepoinfo(os.path.join(basedir, repo_path, '.git')))
|
||||||
|
f.close()
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
def version(prog):
|
def version(prog):
|
||||||
result = "{0} {1}".format(prog, __version__)
|
result = "{0} {1}".format(prog, __version__)
|
||||||
gitinfo = _gitinfo()
|
gitinfo = _gitinfo()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue