From 7e5a3802ba3ecb77bf482ee82e6df34536a19589 Mon Sep 17 00:00:00 2001 From: Ivan Pozdeev Date: Sat, 27 Oct 2018 22:48:03 +0300 Subject: [PATCH] git describe --tags produces "fatal: No names found, cannot describe anything." on topic branches --- find_version.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/find_version.py b/find_version.py index 438a5411..519542e4 100644 --- a/find_version.py +++ b/find_version.py @@ -25,7 +25,15 @@ # used in local dev releases git_hash = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).splitlines()[0].decode() # this outputs the annotated tag if we are exactly on a tag, otherwise --g -tag = subprocess.check_output(['git', 'describe', '--tags']).splitlines()[0].decode().split('-') +try: + tag = subprocess.check_output(['git', 'describe', '--tags'], stderr = subprocess.STDOUT).splitlines()[0].decode().split('-') +except subprocess.CalledProcessError as e: + # no tags reachable (e.g. on a topic branch in a fork), see + # https://stackoverflow.com/questions/4916492/git-describe-fails-with-fatal-no-names-found-cannot-describe-anything + if e.output.rstrip() == b"fatal: No names found, cannot describe anything.": + tag=[] + else: + print(e.output); raise if len(tag) == 1: # tag identifies the build and should be a sequential revision number