From 0db14f9805bcb04522be8e3c76ec545fc21169fd Mon Sep 17 00:00:00 2001 From: Mathis Logemann <13556116+mathisloge@users.noreply.github.com> Date: Wed, 7 Oct 2026 08:11:44 +0200 Subject: [PATCH] fix(tags): give ignored tag formats precedence over version formats A tag matching both an ignored format and a version format was accepted as a version tag. Ignored formats only suppressed the warning. Ignored formats now always exclude the tag. Ignored formats are now matched against the whole tag (fullmatch) instead of by prefix, so patterns like `*-${major}.${minor}` no longer swallow legacy tags such as `project-0.9.3`. --- commitizen/tags.py | 7 +++++-- tests/test_changelog.py | 10 ++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/commitizen/tags.py b/commitizen/tags.py index b3bcbe7a07..5c751f7454 100644 --- a/commitizen/tags.py +++ b/commitizen/tags.py @@ -127,15 +127,18 @@ def is_version_tag(self, tag: str | GitTag, warn: bool = False) -> bool: if `warn` is `True`, it will print a warning message if the tag is not a version tag. """ tag = tag.name if isinstance(tag, GitTag) else tag + if self.is_ignored_tag(tag): + return False + is_legit = any(regex.fullmatch(tag) for regex in self.version_regexes) - if warn and not is_legit and not self.is_ignored_tag(tag): + if warn and not is_legit: out.warn(self._version_tag_error(tag)) return is_legit def is_ignored_tag(self, tag: str | GitTag) -> bool: """True if a given tag can be ignored""" tag = tag.name if isinstance(tag, GitTag) else tag - return any(regex.match(tag) for regex in self.ignored_regexes) + return any(regex.fullmatch(tag) for regex in self.ignored_regexes) def get_version_tags( self, tags: Iterable[GitTag], warn: bool = False diff --git a/tests/test_changelog.py b/tests/test_changelog.py index 24ec3df979..ee0d972262 100644 --- a/tests/test_changelog.py +++ b/tests/test_changelog.py @@ -1591,6 +1591,16 @@ def test_tag_rules_with_ignored_tags(tag: TagDef): assert rules.is_ignored_tag(tag.name) is tag.is_ignored +def test_ignored_version_tag_is_not_version_tag(capsys: pytest.CaptureFixture): + rules = changelog.TagRules( + scheme=Pep440, tag_format="$version", ignored_tag_formats=["$version-hotfix-1"] + ) + + assert rules.is_version_tag("1.2.3-hotfix-1", warn=True) is False + assert rules.is_version_tag("1.2.3", warn=True) is True + assert capsys.readouterr().err == "" + + def test_tags_rules_get_version_tags(capsys: pytest.CaptureFixture): tags = [ git.GitTag("v1.1.0", "17efb44d2cd16f6621413691a543e467c7d2dda6", "2019-04-14"),