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

Commit c26e5bd

Browse files
refactor: Make tag_format properly default to $version
We've been using this default already in `normalize_tag`, but setting this value in the settings dict is cleaner.
1 parent 672ff94 commit c26e5bd

File tree

7 files changed

+14
-15
lines changed

7 files changed

+14
-15
lines changed

commitizen/bump.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def _version_to_regex(version: str) -> str:
219219

220220
def normalize_tag(
221221
version: Union[VersionProtocol, str],
222-
tag_format: Optional[str] = None,
222+
tag_format: str,
223223
version_type_cls: Optional[Type[VersionProtocol]] = None,
224224
) -> str:
225225
"""The tag and the software version might be different.
@@ -238,9 +238,6 @@ def normalize_tag(
238238
if isinstance(version, str):
239239
version = version_type_cls(version)
240240

241-
if not tag_format:
242-
return str(version)
243-
244241
major, minor, patch = version.release
245242
prerelease = ""
246243
# version.pre is needed for mypy check

commitizen/commands/changelog.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from commitizen import bump, changelog, defaults, factory, git, out, version_types
99
from commitizen.config import BaseConfig
10+
from commitizen.defaults import DEFAULT_SETTINGS
1011
from commitizen.exceptions import (
1112
DryRunExit,
1213
NoCommitsFoundError,
@@ -55,8 +56,8 @@ def __init__(self, config: BaseConfig, args):
5556
or defaults.change_type_order
5657
)
5758
self.rev_range = args.get("rev_range")
58-
self.tag_format = args.get("tag_format") or self.config.settings.get(
59-
"tag_format"
59+
self.tag_format: str = args.get("tag_format") or self.config.settings.get(
60+
"tag_format", DEFAULT_SETTINGS["tag_format"]
6061
)
6162
self.merge_prerelease = args.get(
6263
"merge_prerelease"

commitizen/commands/init.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from commitizen.__version__ import __version__
1111
from commitizen.config import BaseConfig, JsonConfig, TomlConfig, YAMLConfig
1212
from commitizen.cz import registry
13-
from commitizen.defaults import config_files
13+
from commitizen.defaults import DEFAULT_SETTINGS, config_files
1414
from commitizen.exceptions import InitFailedError, NoAnswersError
1515
from commitizen.git import get_latest_tag_name, get_tag_names, smart_open
1616
from commitizen.version_types import VERSION_TYPES
@@ -203,14 +203,15 @@ def _ask_tag_format(self, latest_tag) -> str:
203203
f'Is "{tag_format}" the correct tag format?', style=self.cz.style
204204
).unsafe_ask()
205205

206+
default_format = DEFAULT_SETTINGS["tag_format"]
206207
if not is_correct_format:
207208
tag_format = questionary.text(
208-
'Please enter the correct version format: (default: "$version")',
209+
f'Please enter the correct version format: (default: "{default_format}")',
209210
style=self.cz.style,
210211
).unsafe_ask()
211212

212213
if not tag_format:
213-
tag_format = "$version"
214+
tag_format = default_format
214215
return tag_format
215216

216217
def _ask_version_provider(self) -> str:

commitizen/defaults.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Settings(TypedDict, total=False):
3535
version: Optional[str]
3636
version_files: List[str]
3737
version_provider: Optional[str]
38-
tag_format: Optional[str]
38+
tag_format: str
3939
bump_message: Optional[str]
4040
allow_abort: bool
4141
changelog_file: str
@@ -68,7 +68,7 @@ class Settings(TypedDict, total=False):
6868
"version": None,
6969
"version_files": [],
7070
"version_provider": "commitizen",
71-
"tag_format": None, # example v$version
71+
"tag_format": "$version", # example v$version
7272
"bump_message": None, # bumped v$current_version to $new_version
7373
"allow_abort": False,
7474
"changelog_file": "CHANGELOG.md",

docs/bump.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ In your `pyproject.toml` or `.cz.toml`
327327
tag_format = "v$major.$minor.$patch$prerelease"
328328
```
329329
330-
The variables must be preceded by a `$` sign.
330+
The variables must be preceded by a `$` sign. Default is `$version`.
331331
332332
Supported variables:
333333

docs/config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Version provider used to read and write version [Read more](#version-providers)
3838

3939
Type: `str`
4040

41-
Default: `None`
41+
Default: `$version`
4242

4343
Format for the git tag, useful for old projects, that use a convention like `"v1.2.1"`. [Read more][tag_format]
4444

tests/test_conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"name": "cz_jira",
4646
"version": "1.0.0",
4747
"version_provider": "commitizen",
48-
"tag_format": None,
48+
"tag_format": "$version",
4949
"bump_message": None,
5050
"allow_abort": False,
5151
"version_files": ["commitizen/__version__.py", "pyproject.toml"],
@@ -67,7 +67,7 @@
6767
"name": "cz_jira",
6868
"version": "2.0.0",
6969
"version_provider": "commitizen",
70-
"tag_format": None,
70+
"tag_format": "$version",
7171
"bump_message": None,
7272
"allow_abort": False,
7373
"version_files": ["commitizen/__version__.py", "pyproject.toml"],

0 commit comments

Comments
 (0)