Skip to content

Commit c57b3bd

Browse files
committed
fix: ignore invalid tags
Starting in 4.4.0 due to #1297 when an invalid tag is present an exception is thrown This commit ignores the invalid tags Follow up from #1375
1 parent 617b610 commit c57b3bd

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

commitizen/providers/scm_provider.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from commitizen.git import get_tags
44
from commitizen.providers.base_provider import VersionProvider
55
from commitizen.tags import TagRules
6+
from packaging.version import InvalidVersion
67

78

89
class ScmProvider(VersionProvider):
@@ -18,7 +19,13 @@ def get_version(self) -> str:
1819
rules = TagRules.from_settings(self.config.settings)
1920
tags = get_tags(reachable_only=True)
2021
version_tags = rules.get_version_tags(tags)
21-
versions = sorted(rules.extract_version(t) for t in version_tags)
22+
versions = []
23+
for t in version_tags:
24+
try:
25+
versions.append(rules.extract_version(t))
26+
except InvalidVersion:
27+
continue
28+
versions = sorted(versions)
2229
if not versions:
2330
return "0.0.0"
2431
return str(versions[-1])

tests/providers/test_scm_provider.py

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
("$version", "0.1.0", "0.1.0"),
2424
("$version", "v0.1.0", "0.1.0"),
2525
("$version", "v-0.1.0", "0.0.0"),
26+
("$version", "1.0.0.xxxx", "0.0.0"),
2627
# If tag_format is not None or $version, TAG_FORMAT_REGEXS are used, which are
2728
# much more lenient but require a v prefix.
2829
("v$version", "v0.1.0", "0.1.0"),

0 commit comments

Comments
 (0)