Skip to content

Commit aece9a5

Browse files
committed
refactor(git): simplify tag logic
1 parent 59fd3f5 commit aece9a5

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

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)