Skip to content

Commit

Permalink
refactor(extra_args): Fixed broken code due to rebase and finalized t…
Browse files Browse the repository at this point in the history
…ests
  • Loading branch information
Scrocky committed Sep 24, 2023
1 parent d37f254 commit 0bf5c8a
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 35 deletions.
8 changes: 5 additions & 3 deletions commitizen/commands/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,12 @@ def __call__(self):
)

if signoff:
out.warn("signoff mechanic is deprecated, please use `cz commit -- -s` instead.")
extra_args = "-s " + self.arguments.get("extra_cli_args")
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")
extra_args = self.arguments.get("extra_cli_args", "")

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

Expand Down
7 changes: 5 additions & 2 deletions commitizen/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,16 @@ def add(args: str = "") -> cmd.Command:


def commit(
message: str, args: str = "", extra_args: str = "", committer_date: str | None = None
message: str,
args: str = "",
extra_args: str = "",
committer_date: str | None = None,
) -> cmd.Command:
f = NamedTemporaryFile("wb", delete=False)
f.write(message.encode("utf-8"))
f.close()

command = cmd.run(f"git commit {args} {extra_args} -F {f.name}")
command = f"git commit {args} {extra_args} -F {f.name}"

if committer_date and os.name == "nt": # pragma: no cover
# Using `cmd /v /c "{command}"` sets environment variables only for that command
Expand Down
2 changes: 1 addition & 1 deletion docs/bump.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ These are used in:
* `cz bump`: Find previous release tag (exact match) and generate new tag.
* Find previous release tags in `cz changelog`.
* If `--incremental`: Using latest version found in the changelog, scan existing Git tags with 89\% similarity match.
* If `--incremental`: Using latest version found in the changelog, scan existing Git tags with 89\% similarity match.
* `--rev-range` is converted to Git tag names with `tag_format` before searching Git history.
* If the `scm` `version_provider` is used, it uses different regexes to find the previous version tags:
* If `tag_format` is set to `$version` (default): `VersionProtocol.parser` (allows `v` prefix)
Expand Down
2 changes: 1 addition & 1 deletion docs/commit.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ For example, using the `-S` option on `git commit` to sign a commit is now commi

!!! note
Deprecation warning: A commit can be signed off using `cz commit --signoff` or the shortcut `cz commit -s`.
This syntax is now deprecated in favor of the new `cz commit -- -s` syntax.
This syntax is now deprecated in favor of the new `cz commit -- -s` syntax.
26 changes: 23 additions & 3 deletions tests/commands/test_commit_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def test_commit_retry_works(config, mocker: MockFixture):

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

commit_mock.assert_called_with("feat: user created\n\ncloses #21")
commit_mock.assert_called_with("feat: user created\n\ncloses #21", extra_args="")
prompt_mock.assert_called_once()
success_mock.assert_called_once()
assert not os.path.isfile(temp_file)
Expand Down Expand Up @@ -174,7 +174,7 @@ def test_commit_command_with_signoff_option(config, mocker: MockFixture):

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

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


Expand All @@ -197,7 +197,7 @@ 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, "-s")
commit_mock.assert_called_once_with(ANY, extra_args="-- -s")
success_mock.assert_called_once()


Expand Down Expand Up @@ -276,3 +276,23 @@ def test_commit_command_with_all_option(config, mocker: MockFixture):
commands.Commit(config, {"all": True})()
add_mock.assert_called()
success_mock.assert_called_once()


@pytest.mark.usefixtures("staging_is_clean")
def test_commit_command_with_extra_args(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")
commands.Commit(config, {"extra_cli_args": "-- -extra-args1 -extra-arg2"})()
commit_mock.assert_called_once_with(ANY, extra_args="-- -extra-args1 -extra-arg2")
success_mock.assert_called_once()
10 changes: 7 additions & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

from commitizen import cli
from commitizen.exceptions import (
ExpectedExit, NoCommandFoundError, NotAGitProjectError, InvalidCommandArgumentError, NothingToCommitError
ExpectedExit,
NoCommandFoundError,
NotAGitProjectError,
InvalidCommandArgumentError,
)


Expand Down Expand Up @@ -166,5 +169,6 @@ def test_unknown_args_before_double_dash_raises(mocker: MockFixture):
mocker.patch.object(sys, "argv", testargs)
with pytest.raises(InvalidCommandArgumentError) as excinfo:
cli.main()
assert "Invalid commitizen arguments were found before -- separator" in str(excinfo.value)

assert "Invalid commitizen arguments were found before -- separator" in str(
excinfo.value
)
22 changes: 0 additions & 22 deletions tests/test_command_commit.py

This file was deleted.

0 comments on commit 0bf5c8a

Please sign in to comment.