Skip to content

Commit 32de613

Browse files
committed
refactor(git): simplify tag logic
1 parent baee83e commit 32de613

File tree

4 files changed

+7
-9
lines changed

4 files changed

+7
-9
lines changed

commitizen/config/json_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class JsonConfig(BaseConfig):
1313
def __init__(self, *, data: bytes | str, path: Path | str):
1414
super().__init__()
1515
self.is_empty_config = False
16-
self.path = path # type: ignore
16+
self.path = path
1717
self._parse_setting(data)
1818

1919
def init_empty_config_content(self):

commitizen/config/toml_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class TomlConfig(BaseConfig):
1414
def __init__(self, *, data: bytes | str, path: Path | str):
1515
super().__init__()
1616
self.is_empty_config = False
17-
self.path = path # type: ignore
17+
self.path = path
1818
self._parse_setting(data)
1919

2020
def init_empty_config_content(self):

commitizen/config/yaml_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class YAMLConfig(BaseConfig):
1414
def __init__(self, *, data: bytes | str, path: Path | str):
1515
super().__init__()
1616
self.is_empty_config = False
17-
self.path = path # type: ignore
17+
self.path = path
1818
self._parse_setting(data)
1919

2020
def init_empty_config_content(self):

commitizen/git.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,14 @@ def from_line(cls, line: str, inner_delimiter: str) -> GitTag:
156156
def tag(
157157
tag: str, annotated: bool = False, signed: bool = False, msg: str | None = None
158158
) -> cmd.Command:
159-
_opt = ""
160-
if annotated:
161-
_opt = f"-a {tag} -m"
162-
if signed:
163-
_opt = f"-s {tag} -m"
159+
if not annotated and not signed:
160+
return cmd.run(f"git tag {tag}")
164161

165162
# according to https://git-scm.com/book/en/v2/Git-Basics-Tagging,
166163
# we're not able to create lightweight tag with message.
167164
# by adding message, we make it a annotated tags
168-
return cmd.run(f'git tag {_opt} "{tag if _opt == "" or msg is None else msg}"')
165+
option = "-s" if signed else "-a" # The else case is for annotated tags
166+
return cmd.run(f'git tag {option} {tag} -m "{msg or tag}"')
169167

170168

171169
def add(*args: str) -> cmd.Command:

0 commit comments

Comments
 (0)