Skip to content

Commit 77a3278

Browse files
authored
Merge pull request #136 from native-api/find_version_topic_branches
Fix git describe --tags on topic branches
2 parents 2b31b7f + 7e5a380 commit 77a3278

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Diff for: find_version.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,15 @@
2525
# used in local dev releases
2626
git_hash = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).splitlines()[0].decode()
2727
# this outputs the annotated tag if we are exactly on a tag, otherwise <tag>-<n>-g<shortened sha-1>
28-
tag = subprocess.check_output(['git', 'describe', '--tags']).splitlines()[0].decode().split('-')
28+
try:
29+
tag = subprocess.check_output(['git', 'describe', '--tags'], stderr = subprocess.STDOUT).splitlines()[0].decode().split('-')
30+
except subprocess.CalledProcessError as e:
31+
# no tags reachable (e.g. on a topic branch in a fork), see
32+
# https://stackoverflow.com/questions/4916492/git-describe-fails-with-fatal-no-names-found-cannot-describe-anything
33+
if e.output.rstrip() == b"fatal: No names found, cannot describe anything.":
34+
tag=[]
35+
else:
36+
print(e.output); raise
2937

3038
if len(tag) == 1:
3139
# tag identifies the build and should be a sequential revision number

0 commit comments

Comments
 (0)