MCPcopy Index your code
hub / github.com/commitizen-tools/commitizen / __call__

Method __call__

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

Source from the content-addressed store, hash-verified

132 return self._get_message_by_prompt_commit_questions()
133
134 def __call__(self) -> None:
135 extra_args: list[str] = self.arguments.get("extra_cli_args", [])
136 dry_run = bool(self.arguments.get("dry_run"))
137 write_message_to_file = self.arguments.get("write_message_to_file")
138 signoff = bool(self.arguments.get("signoff"))
139
140 if signoff:
141 out.warn(
142 "Deprecated warning: `cz commit -s` is deprecated and will be removed in v5, please use `cz commit -- -s` instead."
143 )
144
145 if self.arguments.get("all"):
146 git.add("-u")
147
148 if git.is_staging_clean() and not (dry_run or "--allow-empty" in extra_args):
149 raise NothingToCommitError("No files added to staging!")
150
151 if write_message_to_file is not None and write_message_to_file.is_dir():
152 raise NotAllowed(f"{write_message_to_file} is a directory")
153
154 commit_message = self._get_message()
155 if self.arguments.get("edit"):
156 commit_message = self.manual_edit(commit_message)
157
158 out.info(f"\n{commit_message}\n")
159
160 if write_message_to_file:
161 with smart_open(
162 write_message_to_file, "w", encoding=self.config.settings["encoding"]
163 ) as file:
164 file.write(commit_message)
165
166 if dry_run:
167 raise DryRunExit()
168
169 if self.config.settings["always_signoff"] or signoff:
170 extra_args = [*extra_args, "-s"]
171
172 c = git.commit(commit_message, args=extra_args)
173 if c.return_code != 0:
174 out.error(c.err)
175
176 # Create commit backup
177 with smart_open(
178 self.backup_file_path, "w", encoding=self.config.settings["encoding"]
179 ) as f:
180 f.write(commit_message)
181
182 raise CommitError()
183
184 if any(s in c.out for s in ("nothing added", "no changes added to commit")):
185 out.error(c.out)
186 return
187
188 with contextlib.suppress(FileNotFoundError):
189 self.backup_file_path.unlink()
190 out.write(c.err)
191 out.write(c.out)

Callers

nothing calls this directly

Calls 9

_get_messageMethod · 0.95
manual_editMethod · 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