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
5 changes: 3 additions & 2 deletions commitizen/commands/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,10 @@ def _wrap_body(self, message: str) -> str:
if len(lines) < 3:
return message

# First line is subject, second is blank line, rest are body lines
# Preserve intentional blank lines while wrapping non-empty body lines.
wrapped_body_lines = chain.from_iterable(
textwrap.wrap(line, width=body_length_limit) for line in lines[2:]
textwrap.wrap(line, width=body_length_limit) if line else [line]
for line in lines[2:]
)
return "\n".join(chain(lines[:2], wrapped_body_lines))

Expand Down
5 changes: 5 additions & 0 deletions tests/commands/test_commit_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,11 @@ def test_commit_command_with_config_message_length_limit(
100,
id="preserves_line_breaks",
),
pytest.param(
"Line1 is shorter than the limit but has paragraph break\n\nLine2 stays in a separate paragraph",
100,
id="preserves_blank_lines",
),
pytest.param(
"This is a very long line that exceeds 72 characters and should NOT be wrapped when body_length_limit is set to 0",
0,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
feat: add feature

Line1 is shorter than the limit but has paragraph break

Line2 stays in a separate paragraph
Loading