Skip to content

Commit 7b50f50

Browse files
authored
Merge pull request #439 from manang/signoff
feat: add signoff parameter to commit command
2 parents 7d2c3c2 + 5e22040 commit 7b50f50

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

commitizen/cli.py

+5
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": ["-s", "--signoff"],
54+
"action": "store_true",
55+
"help": "Sign off the commit",
56+
},
5257
],
5358
},
5459
{

commitizen/commands/commit.py

+6-1
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)

docs/README.md

+14
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,20 @@ or the shortcut
8686
cz c
8787
```
8888

89+
#### Sign off the commit
90+
91+
Run in the terminal
92+
93+
```bash
94+
cz commit --signoff
95+
```
96+
97+
or the shortcut
98+
99+
```bash
100+
cz commit -s
101+
```
102+
89103
### Integrating with Pre-commit
90104
Commitizen can lint your commit message for you with `cz check`.
91105
You can integrate this in your [pre-commit](https://pre-commit.com/) config with:

tests/commands/test_commit_command.py

+20
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)