MCPcopy Create free account
hub / github.com/commitizen-tools/commitizen / __call__

Method __call__

commitizen/commands/commit.py:184–242  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

182 return self._get_message_by_prompt_commit_questions()
183
184 def __call__(self) -> None:
185 extra_args: list[str] = self.arguments.get("extra_cli_args", [])
186 dry_run = bool(self.arguments.get("dry_run"))
187 write_message_to_file = self.arguments.get("write_message_to_file")
188 signoff = bool(self.arguments.get("signoff"))
189
190 if signoff:
191 out.warn(
192 "Deprecated warning: `cz commit -s` is deprecated and will be removed in v5, please use `cz commit -- -s` instead."
193 )
194
195 if self.arguments.get("all"):
196 git.add("-u")
197
198 if git.is_staging_clean() and not (dry_run or "--allow-empty" in extra_args):
199 raise NothingToCommitError("No files added to staging!")
200
201 if write_message_to_file is not None and write_message_to_file.is_dir():
202 raise NotAllowed(f"{write_message_to_file} is a directory")
203
204 commit_message = self._get_message()
205 if self.arguments.get("edit"):
206 commit_message = self.manual_edit(commit_message)
207
208 out.info(f"\n{commit_message}\n")
209
210 if write_message_to_file:
211 with smart_open(
212 write_message_to_file, "w", encoding=self._get_commit_encoding()
213 ) as file:
214 file.write(commit_message)
215
216 if dry_run:
217 raise DryRunExit()
218
219 if self.config.settings["always_signoff"] or signoff:
220 extra_args = [*extra_args, "-s"]
221
222 c = git.commit(commit_message, args=extra_args)
223 if c.return_code != 0:
224 out.error(c.err)
225
226 # Create commit backup
227 with smart_open(
228 self.backup_file_path, "w", encoding=self._get_commit_encoding()
229 ) as f:
230 f.write(commit_message)
231
232 raise CommitError()
233
234 if any(s in c.out for s in ("nothing added", "no changes added to commit")):
235 out.error(c.out)
236 return
237
238 with contextlib.suppress(FileNotFoundError):
239 self.backup_file_path.unlink()
240 out.write(c.err)
241 out.write(c.out)

Callers

nothing calls this directly

Calls 10

_get_messageMethod · 0.95
manual_editMethod · 0.95
_get_commit_encodingMethod · 0.95
NotAllowedClass · 0.90
smart_openFunction · 0.90
DryRunExitClass · 0.90
CommitErrorClass · 0.90
getMethod · 0.45
infoMethod · 0.45

Tested by

no test coverage detected