From a505d5bdc5484fdc8e179c4f19efbd87a3cdcc4a Mon Sep 17 00:00:00 2001 From: Yu-Ting Hsiung Date: Fri, 6 Jun 2025 02:03:32 +0800 Subject: [PATCH] refactor(git): simplify tag logic --- commitizen/git.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/commitizen/git.py b/commitizen/git.py index fb59750ea..0f5f820eb 100644 --- a/commitizen/git.py +++ b/commitizen/git.py @@ -160,16 +160,14 @@ def from_line(cls, line: str, inner_delimiter: str) -> GitTag: def tag( tag: str, annotated: bool = False, signed: bool = False, msg: str | None = None ) -> cmd.Command: - _opt = "" - if annotated: - _opt = f"-a {tag} -m" - if signed: - _opt = f"-s {tag} -m" + if not annotated and not signed: + return cmd.run(f"git tag {tag}") # according to https://git-scm.com/book/en/v2/Git-Basics-Tagging, # we're not able to create lightweight tag with message. # by adding message, we make it a annotated tags - return cmd.run(f'git tag {_opt} "{tag if _opt == "" or msg is None else msg}"') + option = "-s" if signed else "-a" # The else case is for annotated tags + return cmd.run(f'git tag {option} {tag} -m "{msg or tag}"') def add(*args: str) -> cmd.Command: