From 6f3e5c77b78709ac0ca3e501fd1170c6ce669677 Mon Sep 17 00:00:00 2001 From: KongQun Yang Date: Tue, 9 Feb 2016 16:21:55 -0800 Subject: [PATCH] Fix generate_version_string errors with old versions of git Change-Id: I870bc65849906a52a94f8e562e780c8bf7924118 --- packager/version/generate_version_string.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/packager/version/generate_version_string.py b/packager/version/generate_version_string.py index 028b3a6af1..214a7e36ee 100755 --- a/packager/version/generate_version_string.py +++ b/packager/version/generate_version_string.py @@ -30,10 +30,22 @@ if 'check_output' not in dir(subprocess): subprocess.check_output = check_output_implementation if __name__ == '__main__': - version_tag = subprocess.check_output(['git', 'tag', '--points-at', 'HEAD' - ]).rstrip() - version_hash = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD' - ]).rstrip() + try: + version_tag = subprocess.check_output( + ['git', 'tag', '--points-at', 'HEAD'], + stderr=subprocess.STDOUT).rstrip() + except subprocess.CalledProcessError as e: + # git tag --points-at is not supported in old versions of git. Just ignore + # version_tag in this case. + version_tag = None + + try: + version_hash = subprocess.check_output( + ['git', 'rev-parse', '--short', 'HEAD'], + stderr=subprocess.STDOUT).rstrip() + except subprocess.CalledProcessError as e: + version_hash = 'unknown-version' + if version_tag: print '{0}-{1}'.format(version_tag, version_hash) else: