From 4ff44eff7bb789cdde9db254f24feb92a8250c66 Mon Sep 17 00:00:00 2001 From: Jay Kamat Date: Sat, 14 Oct 2017 11:32:23 -0400 Subject: [PATCH] Clean up logic for finding git hash Also add implementation for release scripts as well --- qutebrowser/utils/version.py | 8 ++------ scripts/setupcommon.py | 7 ++++--- tests/unit/utils/test_version.py | 4 +--- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/qutebrowser/utils/version.py b/qutebrowser/utils/version.py index 9cb770710..4c31aa60d 100644 --- a/qutebrowser/utils/version.py +++ b/qutebrowser/utils/version.py @@ -148,13 +148,9 @@ def _git_str_subprocess(gitpath): if not os.path.isdir(os.path.join(gitpath, ".git")): return None try: + # https://stackoverflow.com/questions/21017300/21017394#21017394 commit_hash = subprocess.check_output( - ['git', - 'describe', - '--match=NeVeRmAtCh', - '--always', - '--abbrev=40', - '--dirty'], + ['git', 'describe', '--match=NeVeRmAtCh', '--always', '--dirty'], cwd=gitpath).decode('UTF-8').strip() date = subprocess.check_output( ['git', 'show', '-s', '--format=%ci', 'HEAD'], diff --git a/scripts/setupcommon.py b/scripts/setupcommon.py index a2e4dfca9..1f85b225f 100644 --- a/scripts/setupcommon.py +++ b/scripts/setupcommon.py @@ -50,13 +50,14 @@ def _git_str(): if not os.path.isdir(os.path.join(BASEDIR, ".git")): return None try: - cid = subprocess.check_output( - ['git', 'describe', '--tags', '--dirty', '--always'], + # https://stackoverflow.com/questions/21017300/21017394#21017394 + commit_hash = subprocess.check_output( + ['git', 'describe', '--match=NeVeRmAtCh', '--always', '--dirty'], cwd=BASEDIR).decode('UTF-8').strip() date = subprocess.check_output( ['git', 'show', '-s', '--format=%ci', 'HEAD'], cwd=BASEDIR).decode('UTF-8').strip() - return '{} ({})'.format(cid, date) + return '{} ({})'.format(commit_hash, date) except (subprocess.CalledProcessError, OSError): return None diff --git a/tests/unit/utils/test_version.py b/tests/unit/utils/test_version.py index cfd8c06a6..9db7603e3 100644 --- a/tests/unit/utils/test_version.py +++ b/tests/unit/utils/test_version.py @@ -356,9 +356,7 @@ class TestGitStrSubprocess: def test_real_git(self, git_repo): """Test with a real git repository.""" ret = version._git_str_subprocess(str(git_repo)) - assert ret == \ - '6e4b65a529c0ab78fb370c1527d5809f7436b8f3 ' \ - + '(1970-01-01 01:00:00 +0100)' + assert ret == '6e4b65a (1970-01-01 01:00:00 +0100)' def test_missing_dir(self, tmpdir): """Test with a directory which doesn't exist."""