Skip to content

Commit b52da70

Browse files
committed
fix: ignore empty, "v" and "ver" tags
1 parent e8a1480 commit b52da70

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

version_query/git_query.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,30 @@
1414

1515
def preprocess_git_version_tag(tag: str):
1616
"""Remove a prefix from a version tag."""
17-
if tag.startswith('ver'):
17+
if tag.startswith('ver') and len(tag) > 3:
1818
return tag[3:]
19-
if tag.startswith('v'):
19+
if tag.startswith('v') and len(tag) > 1:
2020
return tag[1:]
2121
if tag and tag[0] in ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'):
2222
return tag
23-
raise ValueError(f'given tag "{tag}" does not appear to be a version tag')
23+
raise ValueError(f'the tag "{tag}" does not appear to be a version tag')
2424

2525

2626
def _git_version_tags(repo: git.Repo) -> t.Mapping[git.Tag, Version]:
2727
versions = {}
2828
for tag in repo.tags:
29+
if tag.name is None or not tag.name:
30+
continue
2931
try:
30-
tag_str = preprocess_git_version_tag(str(tag))
32+
tag_str = preprocess_git_version_tag(tag.name)
3133
except ValueError:
3234
_LOG.debug('%s: ignoring non-version tag %s', repo, tag)
3335
continue
3436
try:
3537
versions[tag] = Version.from_str(tag_str)
3638
except ValueError:
3739
# except packaging.version.InvalidVersion:
38-
_LOG.warning('%s: failed to convert %s to version', repo, tag_str)
40+
_LOG.warning('%s: failed to convert %s (%r) to version', repo, tag.name, tag_str)
3941
continue
4042
return versions
4143

0 commit comments

Comments
 (0)