Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions commitizen/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
"action": "store_true",
"help": "show output to stdout, no commit, no modified files",
},
{
"name": "--signoff",
"action": "store_true",
"help": "Sign off the commit",
},
],
},
{
Expand Down
7 changes: 6 additions & 1 deletion commitizen/commands/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ def __call__(self):
if dry_run:
raise DryRunExit()

c = git.commit(m)
signoff: bool = self.arguments.get("signoff")

if signoff:
c = git.commit(m, "-s")
else:
c = git.commit(m)

if c.return_code != 0:
out.error(c.err)
Expand Down
20 changes: 20 additions & 0 deletions tests/commands/test_commit_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,26 @@ def test_commit_command_with_dry_run_option(config, mocker):
commit_cmd()


@pytest.mark.usefixtures("staging_is_clean")
def test_commit_command_with_signoff_option(config, mocker):
prompt_mock = mocker.patch("questionary.prompt")
prompt_mock.return_value = {
"prefix": "feat",
"subject": "user created",
"scope": "",
"is_breaking_change": False,
"body": "",
"footer": "",
}

commit_mock = mocker.patch("commitizen.git.commit")
commit_mock.return_value = cmd.Command("success", "", "", "", 0)
success_mock = mocker.patch("commitizen.out.success")

commands.Commit(config, {"signoff": True})()
success_mock.assert_called_once()


def test_commit_when_nothing_to_commit(config, mocker):
is_staging_clean_mock = mocker.patch("commitizen.git.is_staging_clean")
is_staging_clean_mock.return_value = True
Expand Down