Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions commitizen/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ def __call__(
"default": 0,
"help": "length limit of the commit message; 0 for no limit",
},
{
"name": ["--"],
"action": "store_true",
"dest": "double_dash",
"help": "Positional arguments separator (recommended)",
},
],
},
{
Expand Down
13 changes: 7 additions & 6 deletions commitizen/commands/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,18 @@ def __call__(self):
if dry_run:
raise DryRunExit()

signoff: bool = (
self.arguments.get("signoff") or self.config.settings["always_signoff"]
)
always_signoff: bool = self.config.settings["always_signoff"]
signoff: bool = self.arguments.get("signoff")

extra_args = self.arguments.get("extra_cli_args", "")

if signoff:
out.warn(
"signoff mechanic is deprecated, please use `cz commit -- -s` instead."
)
extra_args = self.arguments.get("extra_cli_args", "--") + " -s"
else:
extra_args = self.arguments.get("extra_cli_args", "")

if always_signoff or signoff:
extra_args = f"{extra_args} -s".strip()

c = git.commit(m, args=extra_args)

Expand Down
4 changes: 2 additions & 2 deletions docs/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ cz c
Run in the terminal

```bash
cz commit --signoff
cz commit -- --signoff
```

or the shortcut

```bash
cz commit -s
cz commit -- -s
```

### Get project version
Expand Down
29 changes: 27 additions & 2 deletions tests/commands/test_commit_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def test_commit_command_with_signoff_option(config, mocker: MockFixture):

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

commit_mock.assert_called_once_with(ANY, args="-- -s")
commit_mock.assert_called_once_with(ANY, args="-s")
success_mock.assert_called_once()


Expand All @@ -283,7 +283,32 @@ def test_commit_command_with_always_signoff_enabled(config, mocker: MockFixture)
config.settings["always_signoff"] = True
commands.Commit(config, {})()

commit_mock.assert_called_once_with(ANY, args="-- -s")
commit_mock.assert_called_once_with(ANY, args="-s")
success_mock.assert_called_once()


@pytest.mark.usefixtures("staging_is_clean")
def test_commit_command_with_gpgsign_and_always_signoff_enabled(
config, mocker: MockFixture
):
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", "", b"", b"", 0)
success_mock = mocker.patch("commitizen.out.success")

config.settings["always_signoff"] = True
commands.Commit(config, {"extra_cli_args": "-S"})()

commit_mock.assert_called_once_with(ANY, args="-S -s")
success_mock.assert_called_once()


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
usage: cz commit [-h] [--retry] [--no-retry] [--dry-run]
[--write-message-to-file FILE_PATH] [-s] [-a] [-e]
[-l MESSAGE_LENGTH_LIMIT]
[-l MESSAGE_LENGTH_LIMIT] [--]

create new commit

Expand All @@ -19,3 +19,4 @@ options:
-e, --edit edit the commit message before committing
-l, --message-length-limit MESSAGE_LENGTH_LIMIT
length limit of the commit message; 0 for no limit
-- Positional arguments separator (recommended)
9 changes: 8 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,19 @@ def git_sandbox(monkeypatch: pytest.MonkeyPatch, tmp_path: Path):
gitconfig = tmp_path / ".git" / "config"
if not gitconfig.parent.exists():
gitconfig.parent.mkdir()

monkeypatch.setenv("GIT_CONFIG_GLOBAL", str(gitconfig))

r = cmd.run(f"git config --file {gitconfig} user.name {SIGNER}")
assert r.return_code == 0, r.err
r = cmd.run(f"git config --file {gitconfig} user.email {SIGNER_MAIL}")
assert r.return_code == 0, r.err
cmd.run("git config --global init.defaultBranch master")

r = cmd.run(f"git config --file {gitconfig} safe.directory '*'")
assert r.return_code == 0, r.err

r = cmd.run("git config --global init.defaultBranch master")
assert r.return_code == 0, r.err


@pytest.fixture
Expand Down
Loading