Skip to content

Commit 6ef4a34

Browse files
mathislogewoile
authored andcommitted
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`.
1 parent 2bcb46f commit 6ef4a34

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

‎commitizen/tags.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,18 @@ def is_version_tag(self, tag: str | GitTag, warn: bool = False) -> bool:
127127
if `warn` is `True`, it will print a warning message if the tag is not a version tag.
128128
"""
129129
tag = tag.name if isinstance(tag, GitTag) else tag
130+
if self.is_ignored_tag(tag):
131+
return False
132+
130133
is_legit = any(regex.fullmatch(tag) for regex in self.version_regexes)
131-
if warn and not is_legit and not self.is_ignored_tag(tag):
134+
if warn and not is_legit:
132135
out.warn(self._version_tag_error(tag))
133136
return is_legit
134137

135138
def is_ignored_tag(self, tag: str | GitTag) -> bool:
136139
"""True if a given tag can be ignored"""
137140
tag = tag.name if isinstance(tag, GitTag) else tag
138-
return any(regex.match(tag) for regex in self.ignored_regexes)
141+
return any(regex.fullmatch(tag) for regex in self.ignored_regexes)
139142

140143
def get_version_tags(
141144
self, tags: Iterable[GitTag], warn: bool = False

‎tests/test_changelog.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,6 +1591,16 @@ def test_tag_rules_with_ignored_tags(tag: TagDef):
15911591
assert rules.is_ignored_tag(tag.name) is tag.is_ignored
15921592

15931593

1594+
def test_ignored_version_tag_is_not_version_tag(capsys: pytest.CaptureFixture):
1595+
rules = changelog.TagRules(
1596+
scheme=Pep440, tag_format="$version", ignored_tag_formats=["$version-hotfix-1"]
1597+
)
1598+
1599+
assert rules.is_version_tag("1.2.3-hotfix-1", warn=True) is False
1600+
assert rules.is_version_tag("1.2.3", warn=True) is True
1601+
assert capsys.readouterr().err == ""
1602+
1603+
15941604
def test_tags_rules_get_version_tags(capsys: pytest.CaptureFixture):
15951605
tags = [
15961606
git.GitTag("v1.1.0", "17efb44d2cd16f6621413691a543e467c7d2dda6", "2019-04-14"),

0 commit comments

Comments
 (0)