diff options
author | Andy Doan <andy.doan@linaro.org> | 2014-08-05 17:28:12 -0500 |
---|---|---|
committer | Andy Doan <andy.doan@linaro.org> | 2014-08-05 17:28:12 -0500 |
commit | 92e3a3cc1ac91708b109a79d32497c8381eac5da (patch) | |
tree | 47c228d9759d5212a4686f395ef3d74bed87cc53 | |
parent | 8ce1b19702e0f4c4949c8b7a60364f589d1aeab8 (diff) |
bug #322: fix version information for snapshots2014.07.2
There were 2 issues:
1) ensure git is run from the proper directory
2) ensure we can parse git-log returns for both Trusty and Precise
Change-Id: I9d7b59742e4e82f668de5bc57070ef9f8d4f198d
-rw-r--r-- | tests/test_version.py | 5 | ||||
-rw-r--r-- | version.py | 7 |
2 files changed, 11 insertions, 1 deletions
diff --git a/tests/test_version.py b/tests/test_version.py index af0ef1e..0fc050b 100644 --- a/tests/test_version.py +++ b/tests/test_version.py @@ -28,6 +28,11 @@ class TestVersion(unittest.TestCase): self.subprocess.return_value = 'fakehash (HEAD, tag: 2014.07.02, refs' self.assertEquals('2014.07.02', version._get_version()) + def test_precise_tag(self): + # older git versions on precise don't include "tag:" in the git-log + self.subprocess.return_value = 'fakehash (HEAD, 2014.07.2, origin' + self.assertEquals('2014.07.2', version._get_version()) + def test_invalid_tag(self): self.subprocess.return_value = 'fakehash (HEAD, tag: aaaa.bb, refs' self.assertEquals('fakehash', version._get_version()) @@ -1,3 +1,4 @@ +import os import re import subprocess @@ -6,9 +7,13 @@ VERSION = None def _get_version(): '''return either the tag on HEAD or the shortened commit id if not found''' - out = subprocess.check_output(['git', 'log', '--format=%h %d', '-1']) + out = subprocess.check_output(['git', 'log', '--format=%h %d', '-1'], + cwd=os.path.dirname(__file__)) version, ref_names = out.split('(') m = re.match(r'.*tag: (\d{4}\.\d{2}.*?),', ref_names) + if not m: + # might be an older version of git + m = re.match(r'.*HEAD, (\d{4}\.\d{2}.*?),', ref_names) if m: version = m.group(1) return version.strip() |