8000 feat: add signoff parameter to commit command · commitizen-tools/commitizen@7b7b0c9 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7b7b0c9

Browse files
committed
feat: add signoff parameter to commit command
command to sign off the commit, equivalent to git commit -s
1 parent 976d5d2 commit 7b7b0c9

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

commitizen/cli.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@
4949
"action": "store_true",
5050
"help": "show output to stdout, no commit, no modified files",
5151
},
52+
{
53+
"name": "--signoff",
54+
"action": "store_true",
55+
"help": "Sign off the commit",
56+
},
5257
],
5358
},
5459
{

commitizen/commands/commit.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,12 @@ def __call__(self):
7878
if dry_run:
7979
raise DryRunExit()
8080

81-
c = git.commit(m)
81+
signoff: bool = self.arguments.get("signoff")
82+
83+
if signoff:
84+
c = git.commit(m, "-s")
85+
else:
86+
c = git.commit(m)
8287

8388
if c.return_code != 0:
8489
out.error(c.err)

tests/commands/test_commit_command.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,26 @@ def test_commit_command_with_dry_run_option(config, mocker):
107107
commit_cmd()
108108

109109

110+
@pytest.mark.usefixtures("staging_is_clean")
111+
def test_commit_command_with_signoff_option(config, mocker):
112+
prompt_mock = mocker.patch("questionary.prompt")
113+
prompt_mock.return_value = {
114+
"prefix": "feat",
115+
"subject": "user created",
116+
"scope": "",
117+
"is_breaking_change": False,
118+
"body": "",
119+
"footer": "",
120+
}
121+
122+
commit_mock = mocker.patch("commitizen.git.commit")
123+
commit_mock.return_value = cmd.Command("success", "", "", "", 0)
124+
success_mock = mocker.patch("commitizen.out.success")
125+
126+
commands.Commit(config, {"signoff": True})()
127+
success_mock.assert_called_once()
128+
129+
110130
def test_commit_when_nothing_to_commit(config, mocker):
111131
is_staging_clean_mock = mocker.patch("commitizen.git.is_staging_clean")
112132
is_staging_clean_mock.return_value = True

0 commit comments

Comments
 (0)
0