fix: preserve blank lines with body length limit - #2080
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2080 +/- ##
==========================================
+ Coverage 98.19% 98.26% +0.07%
==========================================
Files 61 61
Lines 2829 2829
==========================================
+ Hits 2778 2780 +2
+ Misses 51 49 -2 ☔ View full report in Codecov by Harness. |
Manny7717
left a comment
There was a problem hiding this comment.
Review — Approved
Verified locally on head: 6/6 tests pass (body-length-limit and message-length-limit params, including the new preserves_blank_lines case).
The fix is correct and minimal: textwrap.wrap returns [] for empty input, which is why blank lines were silently dropped; short-circuiting with [line] preserves paragraph breaks exactly as intended.
One optional, non-blocking suggestion (inline): the if line check only catches fully-empty strings — a whitespace-only body line still gets dropped because textwrap.wrap(' ') is []. if line.strip() else [line] would preserve those too, if the intent is to preserve any intentional blank-looking line.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> commitizen-tools#2079
8efb89a to
171a234
Compare
Description
Fix
body_length_limitso it preserves intentional blank lines in commit bodies while still wrapping non-empty lines to the configured width.Checklist
Was generative AI tooling used to co-author this PR?
Generated-by: GitHub Copilot CLI following the guidelines
Code Changes
uv run poe alllocally to ensure this change passes linter check and testsUpdate the documentation for the changes— not required, just a fixDocumentation Changes
Run— no documentation changesuv run poe doclocally to ensure the documentation pages renders correctlyCheck and fix any broken links (internal or external)— no documentation changesExpected Behavior
With
body_length_limitenabled, Commitizen should preserve blank lines in the commit body and only wrap long non-empty lines.Steps to Test This Pull Request
Configure
body_length_limit = 80or runcz commit --body-length-limit 80.Create a commit message body with a paragraph break, for example:
Confirm the generated commit message still contains the blank separator line.
Run
uv run pytest tests/commands/test_commit_command.py -k body_length_limit.Run
uv run ruff check commitizen/commands/commit.py tests/commands/test_commit_command.py.Run
uv run ruff format --check commitizen/commands/commit.py tests/commands/test_commit_command.py.Additional Context
This fixes a regression where
textwrap.wrap("")caused empty body lines to be dropped whenbody_length_limitwas enabled (#2079).