10000 BUG: handle git-describe failing to find a tag · jamestpp/python-control@a2cc0b3 · GitHub
[go: up one dir, main page]

Skip to content

Commit a2cc0b3

Browse files
committed
BUG: handle git-describe failing to find a tag
This can happen with shallow clones, e.g., on Travis-CI.
1 parent 55878a3 commit a2cc0b3

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

make_version.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,22 @@
33

44
def main():
55
cmd = 'git describe --always --long'
6-
output = check_output(cmd.split()).decode('utf-8').strip().split('-')
6+
# describe --long usually outputs "tag-numberofcommits-commitname"
7+
output = check_output(cmd.split()).decode('utf-8').strip().rsplit('-',2)
78
if len(output) == 3:
89
version, build, commit = output
910
else:
10-
raise Exception("Could not git describe, (got %s)" % output)
11+
# If the clone is shallow, describe's output won't have tag and
12+
# number of commits. This is a particular issue on Travis-CI,
13+
# which by default clones with a depth of 50.
14+
# This behaviour isn't well documented in git-describe docs,
15+
# but see, e.g., https://stackoverflow.com/a/36389573/1008142
16+
# and https://github.com/travis-ci/travis-ci/issues/3412
17+
version = 'unknown'
18+
build = 'unknown'
19+
# we don't ever expect just one dash from describe --long, but
20+
# just in case:
21+
commit = '-'.join(output)
1122

1223
print("Version: %s" % version)
1324
print("Build: %s" % build)

0 commit comments

Comments
 (0)
0