Skip to content

Commit fe7d589

Browse files
schlotterCopilot
andcommitted
fix(commit): honor configured body length limit
Treat an omitted CLI option as no override so project configuration controls body wrapping while an explicit zero continues to disable it. Fixes #2093 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 6eec06e commit fe7d589

2 files changed

Lines changed: 33 additions & 4 deletions

File tree

‎commitizen/commands/commit.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class CommitArgs(TypedDict, total=False):
3838
edit: bool
3939
extra_cli_args: list[str]
4040
message_length_limit: int
41-
body_length_limit: int
41+
body_length_limit: int | None
4242
no_retry: bool
4343
signoff: bool
4444
write_message_to_file: Path | None
@@ -109,9 +109,9 @@ def _wrap_body(self, message: str) -> str:
109109
Wrap the body of the commit message to the --body-length-limit length.
110110
"""
111111

112-
body_length_limit = self.arguments.get(
113-
"body_length_limit", self.config.settings["body_length_limit"]
114-
)
112+
body_length_limit = self.arguments.get("body_length_limit")
113+
if body_length_limit is None:
114+
body_length_limit = self.config.settings["body_length_limit"]
115115
# By the contract, body_length_limit is set to 0 for no limit
116116
if not body_length_limit or body_length_limit <= 0:
117117
return message

‎tests/commands/test_commit_command.py‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,35 @@ def test_commit_command_body_length_limit(
448448
)
449449

450450

451+
@pytest.mark.usefixtures("staging_is_clean")
452+
def test_commit_command_uses_configured_body_length_limit_when_cli_option_is_omitted(
453+
config,
454+
commit_mock,
455+
mocker: MockFixture,
456+
):
457+
config.settings["body_length_limit"] = 20
458+
mocker.patch(
459+
"questionary.prompt",
460+
return_value={
461+
"prefix": "feat",
462+
"subject": "add feature",
463+
"scope": "",
464+
"is_breaking_change": False,
465+
"body": "This body line should wrap at the configured limit",
466+
"footer": "",
467+
},
468+
)
469+
470+
commands.Commit(config, {"body_length_limit": None})()
471+
472+
committed_message = commit_mock.call_args[0][0]
473+
assert committed_message.split("\n")[2:] == [
474+
"This body line",
475+
"should wrap at the",
476+
"configured limit",
477+
]
478+
479+
451480
@pytest.mark.usefixtures("staging_is_clean")
452481
def test_commit_command_body_length_limit_preserves_whitespace_only_lines(
453482
config,

0 commit comments

Comments
 (0)