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

Commit c14e605

Browse files
committed
refactor(commit): simplify call
1 parent a0cc490 commit c14e605

File tree

1 file changed

+20
-30
lines changed

1 file changed

+20
-30
lines changed

commitizen/commands/commit.py

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -94,39 +94,32 @@ def manual_edit(self, message: str) -> str:
9494

9595
def __call__(self):
9696
extra_args: str = self.arguments.get("extra_cli_args", "")
97-
98-
allow_empty: bool = "--allow-empty" in extra_args
99-
10097
dry_run: bool = self.arguments.get("dry_run")
10198
write_message_to_file: bool = self.arguments.get("write_message_to_file")
102-
manual_edit: bool = self.arguments.get("edit")
99+
signoff: bool = self.arguments.get("signoff")
103100

104-
is_all: bool = self.arguments.get("all")
105-
if is_all:
106-
c = git.add("-u")
101+
if self.arguments.get("all"):
102+
git.add("-u")
107103

108-
if git.is_staging_clean() and not (dry_run or allow_empty):
104+
if git.is_staging_clean() and not (dry_run or "--allow-empty" in extra_args):
109105
raise NothingToCommitError("No files added to staging!")
110106

111107
if write_message_to_file is not None and write_message_to_file.is_dir():
112108
raise NotAllowed(f"{write_message_to_file} is a directory")
113109

114-
retry: bool = self.arguments.get("retry")
115-
no_retry: bool = self.arguments.get("no_retry")
116-
retry_after_failure: bool = self.config.settings.get("retry_after_failure")
117-
118-
if retry:
110+
if self.arguments.get("retry"):
119111
m = self.read_backup_message()
120112
if m is None:
121113
raise NoCommitBackupError()
122-
elif retry_after_failure and not no_retry:
114+
elif not self.config.settings.get("retry_after_failure") or self.arguments.get(
115+
"no_retry"
116+
):
123117
m = self.read_backup_message()
124-
if m is None:
125-
m = self.prompt_commit_questions()
126-
else:
118+
119+
if m is None:
127120
m = self.prompt_commit_questions()
128121

129-
if manual_edit:
122+
if self.arguments.get("edit"):
130123
m = self.manual_edit(m)
131124

132125
out.info(f"\n{m}\n")
@@ -138,19 +131,15 @@ def __call__(self):
138131
if dry_run:
139132
raise DryRunExit()
140133

141-
always_signoff: bool = self.config.settings["always_signoff"]
142-
signoff: bool = self.arguments.get("signoff")
143-
144134
if signoff:
145135
out.warn(
146136
"signoff mechanic is deprecated, please use `cz commit -- -s` instead."
147137
)
148138

149-
if always_signoff or signoff:
139+
if self.config.settings["always_signoff"] or signoff:
150140
extra_args = f"{extra_args} -s".strip()
151141

152142
c = git.commit(m, args=extra_args)
153-
154143
if c.return_code != 0:
155144
out.error(c.err)
156145

@@ -160,11 +149,12 @@ def __call__(self):
160149

161150
raise CommitError()
162151

163-
if "nothing added" in c.out or "no changes added to commit" in c.out:
152+
if any(s in c.out for s in ("nothing added", "no changes added to commit")):
164153
out.error(c.out)
165-
else:
166-
with contextlib.suppress(FileNotFoundError):
167-
os.remove(self.temp_file)
168-
out.write(c.err)
169-
out.write(c.out)
170-
out.success("Commit successful!")
154+
return
155+
156+
with contextlib.suppress(FileNotFoundError):
157+
os.remove(self.temp_file)
158+
out.write(c.err)
159+
out.write(c.out)
160+
out.success("Commit successful!")

0 commit comments

Comments
 (0)