Skip to content

fix: preserve blank lines with body length limit - #2080

Open
schlotter wants to merge 1 commit into
commitizen-tools:masterfrom
ZEISS:fix/body-length-limit-do-not-remove-empty-lines
Open

fix: preserve blank lines with body length limit#2080
schlotter wants to merge 1 commit into
commitizen-tools:masterfrom
ZEISS:fix/body-length-limit-do-not-remove-empty-lines

Conversation

@schlotter

@schlotter schlotter commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Description

Fix body_length_limit so 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?

  • Yes (please specify the tool below)

Generated-by: GitHub Copilot CLI following the guidelines

Code Changes

  • Add test cases to all the changes you introduce
  • Run uv run poe all locally to ensure this change passes linter check and tests
  • Manually test the changes:
    • Verify the feature/bug fix works as expected in real-world scenarios
    • Test edge cases and error conditions
    • Ensure backward compatibility is maintained
    • Document any manual testing steps performed
  • Update the documentation for the changes — not required, just a fix

Documentation Changes

  • Run uv run poe doc locally to ensure the documentation pages renders correctly — no documentation changes
  • Check and fix any broken links (internal or external) — no documentation changes

Expected Behavior

With body_length_limit enabled, Commitizen should preserve blank lines in the commit body and only wrap long non-empty lines.

Steps to Test This Pull Request

  1. Configure body_length_limit = 80 or run cz commit --body-length-limit 80.

  2. Create a commit message body with a paragraph break, for example:

    First paragraph line
    
    Second paragraph line
    
  3. Confirm the generated commit message still contains the blank separator line.

  4. Run uv run pytest tests/commands/test_commit_command.py -k body_length_limit.

  5. Run uv run ruff check commitizen/commands/commit.py tests/commands/test_commit_command.py.

  6. 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 when body_length_limit was enabled (#2079).

@schlotter schlotter changed the title Pleasfix: preserve blank lines with body length limit fix: preserve blank lines with body length limit Aug 25, 2026
@codecov

codecov Bot commented Aug 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.26%. Comparing base (d914b4d) to head (171a234).
⚠️ Report is 1 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

@schlotter
schlotter marked this pull request as ready for review August 25, 2026 14:51

@Manny7717 Manny7717 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread commitizen/commands/commit.py Outdated
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

commitizen-tools#2079
@schlotter
schlotter force-pushed the fix/body-length-limit-do-not-remove-empty-lines branch from 8efb89a to 171a234 比较 August 29, 2026 12:27
注册 for free to join this conversation on GitHub. Already have an account? 登录 to comment

项目

None yet

Development

Successfully merging this pull request may close these issues.

2 participants