mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 03:41:25 -07:00
remove duplicate code path as few will have git python installed
This commit is contained in:
parent
fde329fb9e
commit
51083e48e9
1 changed files with 5 additions and 17 deletions
|
@ -39,12 +39,6 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from md5 import md5 as _md5
|
from md5 import md5 as _md5
|
||||||
|
|
||||||
try:
|
|
||||||
import git
|
|
||||||
HAS_GIT = True
|
|
||||||
except ImportError:
|
|
||||||
HAS_GIT = False
|
|
||||||
|
|
||||||
###############################################################
|
###############################################################
|
||||||
# UTILITY FUNCTIONS FOR COMMAND LINE TOOLS
|
# UTILITY FUNCTIONS FOR COMMAND LINE TOOLS
|
||||||
###############################################################
|
###############################################################
|
||||||
|
@ -299,17 +293,11 @@ def _gitinfo():
|
||||||
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):
|
||||||
if HAS_GIT:
|
with open(os.path.join(repo_path, "HEAD")) as f:
|
||||||
repo = git.Repo(repo_path)
|
branch = f.readline().split('/')[-1].rstrip("\n")
|
||||||
head = repo.head
|
with open(os.path.join(repo_path, "refs", "heads", branch)) as f:
|
||||||
branch = head.reference.name
|
commit = f.readline()[:10]
|
||||||
commit = head.commit.hexsha[:10]
|
result = "({0} {1})".format(branch, commit)
|
||||||
else:
|
|
||||||
with open(os.path.join(repo_path, "HEAD")) as f:
|
|
||||||
branch = f.readline().split('/')[-1].rstrip("\n")
|
|
||||||
with open(os.path.join(repo_path, "refs", "heads", branch)) as f:
|
|
||||||
commit = f.readline()[:10]
|
|
||||||
result = "({0}) [{1}]".format(branch, commit)
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def version(prog):
|
def version(prog):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue