Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 7a0dd2a

Browse files
robertschweizerLee-W
authored andcommitted
docs: Document where tag_format config value is used
I was very confused about these different usages. Documenting them might be a good basis for future simplification.
1 parent 9de03f5 commit 7a0dd2a

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

docs/bump.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,17 @@ cz -nr 21 bump
317317
318318
### `tag_format`
319319
320-
It is used to read the format from the git tags, and also to generate the tags.
320+
`tag_format` and `version_scheme` are combined to make Git tag names from versions.
321+
322+
These are used in:
323+
324+
* `cz bump`: Find previous release tag (exact match) and generate new tag.
325+
* Find previous release tags in `cz changelog`.
326+
* If `--incremental`: Using latest version found in the changelog, scan existing Git tags with 89\% similarity match.
327+
* `--rev-range` is converted to Git tag names with `tag_format` before searching Git history.
328+
* 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)
330+
* If `tag_format` is set: Custom regex similar to SemVer (not as lenient as PEP440 e.g. on dev-releases)
321331
322332
Commitizen supports 2 types of formats, a simple and a more complex.
323333

tests/test_version_providers.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,22 @@ def test_file_providers(
173173

174174

175175
@pytest.mark.parametrize(
176-
"tag_format,tag,version",
176+
"tag_format,tag,expected_version",
177177
(
178+
# If tag_format is None, version_scheme.parser is used.
179+
# Its DEFAULT_VERSION_PARSER allows a v prefix, but matches PEP440 otherwise.
178180
(None, "0.1.0", "0.1.0"),
179181
(None, "v0.1.0", "0.1.0"),
182+
(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"),
186+
("$version", "0.1.0", "0.1.0"),
187+
("$version", "v0.1.0", "0.1.0"),
188+
("$version", "v-0.1.0", "0.1.0"),
180189
("v$version", "v0.1.0", "0.1.0"),
190+
("v$version", "no-match-because-no-v-prefix", "0.0.0"),
191+
("v$version", "v-match-TAG_FORMAT_REGEXS", "-match-TAG_FORMAT_REGEXS"),
181192
("version-$version", "version-0.1.0", "0.1.0"),
182193
("version-$version", "version-0.1", "0.1"),
183194
("version-$version", "version-0.1.0rc1", "0.1.0rc1"),
@@ -191,7 +202,7 @@ def test_file_providers(
191202
)
192203
@pytest.mark.usefixtures("tmp_git_project")
193204
def test_scm_provider(
194-
config: BaseConfig, tag_format: str | None, tag: str, version: str
205+
config: BaseConfig, tag_format: str | None, tag: str, expected_version: str
195206
):
196207
create_file_and_commit("test: fake commit")
197208
create_tag(tag)
@@ -203,25 +214,13 @@ def test_scm_provider(
203214

204215
provider = get_provider(config)
205216
assert isinstance(provider, ScmProvider)
206-
assert provider.get_version() == version
217+
actual_version = provider.get_version()
218+
assert actual_version == expected_version
207219

208220
# Should not fail on set_version()
209221
provider.set_version("43.1")
210222

211223

212-
@pytest.mark.usefixtures("tmp_git_project")
213-
def test_scm_provider_default_without_matching_tag(config: BaseConfig):
214-
create_file_and_commit("test: fake commit")
215-
create_tag("should-not-match")
216-
create_file_and_commit("test: fake commit")
217-
218-
config.settings["version_provider"] = "scm"
219-
220-
provider = get_provider(config)
221-
assert isinstance(provider, ScmProvider)
222-
assert provider.get_version() == "0.0.0"
223-
224-
225224
@pytest.mark.usefixtures("tmp_git_project")
226225
def test_scm_provider_default_without_commits_and_tags(config: BaseConfig):
227226
config.settings["version_provider"] = "scm"

0 commit comments

Comments
 (0)