Skip to content
Open
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
8 changes: 4 additions & 4 deletions commitizen/commands/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions tests/commands/test_commit_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading