diff --git a/commitizen/tags.py b/commitizen/tags.py index b3bcbe7a0..5c751f745 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 24ec3df97..ee0d97226 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"),