diff --git a/commitizen/commands/commit.py b/commitizen/commands/commit.py index ecec7f3f6..970a92450 100644 --- a/commitizen/commands/commit.py +++ b/commitizen/commands/commit.py @@ -38,7 +38,7 @@ class CommitArgs(TypedDict, total=False): edit: bool extra_cli_args: list[str] message_length_limit: int - body_length_limit: int + body_length_limit: int | None no_retry: bool signoff: bool write_message_to_file: Path | None @@ -109,9 +109,9 @@ def _wrap_body(self, message: str) -> str: Wrap the body of the commit message to the --body-length-limit length. """ - body_length_limit = self.arguments.get( - "body_length_limit", self.config.settings["body_length_limit"] - ) + body_length_limit = self.arguments.get("body_length_limit") + if body_length_limit is None: + body_length_limit = self.config.settings["body_length_limit"] # By the contract, body_length_limit is set to 0 for no limit if not body_length_limit or body_length_limit <= 0: return message diff --git a/tests/commands/test_commit_command.py b/tests/commands/test_commit_command.py index ed64a211f..867c7d28a 100644 --- a/tests/commands/test_commit_command.py +++ b/tests/commands/test_commit_command.py @@ -448,6 +448,35 @@ def test_commit_command_body_length_limit( ) +@pytest.mark.usefixtures("staging_is_clean") +def test_commit_command_uses_configured_body_length_limit_when_cli_option_is_omitted( + config, + commit_mock, + mocker: MockFixture, +): + config.settings["body_length_limit"] = 20 + mocker.patch( + "questionary.prompt", + return_value={ + "prefix": "feat", + "subject": "add feature", + "scope": "", + "is_breaking_change": False, + "body": "This body line should wrap at the configured limit", + "footer": "", + }, + ) + + commands.Commit(config, {"body_length_limit": None})() + + committed_message = commit_mock.call_args[0][0] + assert committed_message.split("\n")[2:] == [ + "This body line", + "should wrap at the", + "configured limit", + ] + + @pytest.mark.usefixtures("staging_is_clean") def test_commit_command_body_length_limit_preserves_whitespace_only_lines( config,