Skip to content

fix: ignore invalid tags #1410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion commitizen/providers/scm_provider.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from packaging.version import InvalidVersion

from commitizen.git import get_tags
from commitizen.providers.base_provider import VersionProvider
from commitizen.tags import TagRules
Expand All @@ -18,7 +20,13 @@ def get_version(self) -> str:
rules = TagRules.from_settings(self.config.settings)
tags = get_tags(reachable_only=True)
version_tags = rules.get_version_tags(tags)
versions = sorted(rules.extract_version(t) for t in version_tags)
versions = []
for t in version_tags:
try:
versions.append(rules.extract_version(t))
except InvalidVersion:
continue
versions = sorted(versions)
if not versions:
return "0.0.0"
return str(versions[-1])
Expand Down
1 change: 1 addition & 0 deletions tests/providers/test_scm_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
("$version", "0.1.0", "0.1.0"),
("$version", "v0.1.0", "0.1.0"),
("$version", "v-0.1.0", "0.0.0"),
("$version", "1.0.0.xxxx", "0.0.0"),
# If tag_format is not None or $version, TAG_FORMAT_REGEXS are used, which are
# much more lenient but require a v prefix.
("v$version", "v0.1.0", "0.1.0"),
Expand Down