Skip to content

Commit 7f86f15

Browse files
robertschweizerLee-W
authored andcommitted
fix: Treat $version the same as unset tag_format in ScmProvider
This should be non-breaking unless users rely on the looser version validation of TAG_FORMAT_REGEXS compared to their `version_scheme`.
1 parent 7a0dd2a commit 7f86f15

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

commitizen/providers.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@ class ScmProvider(VersionProvider):
195195

196196
def _tag_format_matcher(self) -> Callable[[str], str | None]:
197197
version_scheme = get_version_scheme(self.config)
198-
pattern = (
199-
self.config.settings.get("tag_format") or version_scheme.parser.pattern
200-
)
198+
pattern = self.config.settings.get("tag_format")
199+
if pattern in (None, "$version"):
200+
pattern = version_scheme.parser.pattern
201201
for var, tag_pattern in self.TAG_FORMAT_REGEXS.items():
202202
pattern = pattern.replace(var, tag_pattern)
203203

docs/bump.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ These are used in:
326326
* If `--incremental`: Using latest version found in the changelog, scan existing Git tags with 89\% similarity match.
327327
* `--rev-range` is converted to Git tag names with `tag_format` before searching Git history.
328328
* If the `scm` `version_provider` is used, it uses different regexes to find the previous version tags:
329-
* If no `tag_format` is set: `VersionProtocol.parser` (allows `v` prefix)
329+
* If `tag_format` is unset or set to `$version`: `VersionProtocol.parser` (allows `v` prefix)
330330
* If `tag_format` is set: Custom regex similar to SemVer (not as lenient as PEP440 e.g. on dev-releases)
331331
332332
Commitizen supports 2 types of formats, a simple and a more complex.

tests/test_version_providers.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -175,17 +175,17 @@ def test_file_providers(
175175
@pytest.mark.parametrize(
176176
"tag_format,tag,expected_version",
177177
(
178-
# If tag_format is None, version_scheme.parser is used.
178+
# If tag_format is None or $version, version_scheme.parser is used.
179179
# Its DEFAULT_VERSION_PARSER allows a v prefix, but matches PEP440 otherwise.
180180
(None, "0.1.0", "0.1.0"),
181181
(None, "v0.1.0", "0.1.0"),
182182
(None, "no-match-because-version-scheme-is-strict", "0.0.0"),
183-
# If tag_format is not None, TAG_FORMAT_REGEXS are used, which are much more
184-
# lenient.
185-
("$version", "match-TAG_FORMAT_REGEXS", "match-TAG_FORMAT_REGEXS"),
183+
("$version", "no-match-because-version-scheme-is-strict", "0.0.0"),
186184
("$version", "0.1.0", "0.1.0"),
187185
("$version", "v0.1.0", "0.1.0"),
188-
("$version", "v-0.1.0", "0.1.0"),
186+
("$version", "v-0.1.0", "0.0.0"),
187+
# If tag_format is not None or $version, TAG_FORMAT_REGEXS are used, which are
188+
# much more lenient but require a v prefix.
189189
("v$version", "v0.1.0", "0.1.0"),
190190
("v$version", "no-match-because-no-v-prefix", "0.0.0"),
191191
("v$version", "v-match-TAG_FORMAT_REGEXS", "-match-TAG_FORMAT_REGEXS"),

0 commit comments

Comments
 (0)