Merge pull request #3118 from jgkamat/jay/git-version

Change qute:version git commit to display hash
This commit is contained in:
Florian Bruhin 2017-10-16 07:59:52 +02:00 committed by GitHub
commit 3d02feac2b
3 changed files with 9 additions and 7 deletions

View File

@ -150,13 +150,14 @@ def _git_str_subprocess(gitpath):
if not os.path.isdir(os.path.join(gitpath, ".git")): if not os.path.isdir(os.path.join(gitpath, ".git")):
return None return None
try: try:
cid = subprocess.check_output( # https://stackoverflow.com/questions/21017300/21017394#21017394
['git', 'describe', '--tags', '--dirty', '--always'], commit_hash = subprocess.check_output(
['git', 'describe', '--match=NeVeRmAtCh', '--always', '--dirty'],
cwd=gitpath).decode('UTF-8').strip() cwd=gitpath).decode('UTF-8').strip()
date = subprocess.check_output( date = subprocess.check_output(
['git', 'show', '-s', '--format=%ci', 'HEAD'], ['git', 'show', '-s', '--format=%ci', 'HEAD'],
cwd=gitpath).decode('UTF-8').strip() cwd=gitpath).decode('UTF-8').strip()
return '{} ({})'.format(cid, date) return '{} ({})'.format(commit_hash, date)
except (subprocess.CalledProcessError, OSError): except (subprocess.CalledProcessError, OSError):
return None return None

View File

@ -50,13 +50,14 @@ def _git_str():
if not os.path.isdir(os.path.join(BASEDIR, ".git")): if not os.path.isdir(os.path.join(BASEDIR, ".git")):
return None return None
try: try:
cid = subprocess.check_output( # https://stackoverflow.com/questions/21017300/21017394#21017394
['git', 'describe', '--tags', '--dirty', '--always'], commit_hash = subprocess.check_output(
['git', 'describe', '--match=NeVeRmAtCh', '--always', '--dirty'],
cwd=BASEDIR).decode('UTF-8').strip() cwd=BASEDIR).decode('UTF-8').strip()
date = subprocess.check_output( date = subprocess.check_output(
['git', 'show', '-s', '--format=%ci', 'HEAD'], ['git', 'show', '-s', '--format=%ci', 'HEAD'],
cwd=BASEDIR).decode('UTF-8').strip() cwd=BASEDIR).decode('UTF-8').strip()
return '{} ({})'.format(cid, date) return '{} ({})'.format(commit_hash, date)
except (subprocess.CalledProcessError, OSError): except (subprocess.CalledProcessError, OSError):
return None return None

View File

@ -356,7 +356,7 @@ class TestGitStrSubprocess:
def test_real_git(self, git_repo): def test_real_git(self, git_repo):
"""Test with a real git repository.""" """Test with a real git repository."""
ret = version._git_str_subprocess(str(git_repo)) ret = version._git_str_subprocess(str(git_repo))
assert ret == 'foobar (1970-01-01 01:00:00 +0100)' assert ret == '6e4b65a (1970-01-01 01:00:00 +0100)'
def test_missing_dir(self, tmpdir): def test_missing_dir(self, tmpdir):
"""Test with a directory which doesn't exist.""" """Test with a directory which doesn't exist."""