Skip to content

fix(commit): honor configured body length limit - #2094

Open
schlotter wants to merge 1 commit into
commitizen-tools:masterfrom
ZEISS:fix/body-length-limit-config-fallback
Open

schlotter wants to merge 1 commit into
commitizen-tools:masterfrom
ZEISS:fix/body-length-limit-config-fallback

Conversation

@schlotter

Copy link
Copy Markdown
Contributor

Description

Make cz commit honor body_length_limit from project configuration when
--body-length-limit is omitted.

The argument parser supplies None for an omitted option. That value previously
masked the configured limit because dict.get() only used its default when the
key was absent. The command now treats None as no CLI override while retaining
the existing behavior where an explicit --body-length-limit 0 disables
wrapping.

Fixes #2093.

Checklist

Was generative AI tooling used to co-author this PR?

  • Yes (GitHub Copilot CLI)

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
    • The run completed with 1,316 passing tests and two unrelated failures while
      the hook-integration tests attempted to install Prettier; npm and node
      rejected the local TLS issuer. Ruff, mypy, and all 35 commit-command tests
      pass.
  • 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 applicable; documented
    configuration and CLI semantics are unchanged

Documentation Changes

Not applicable.

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

Expected Behavior

cz commit wraps body lines at the configured body_length_limit when no CLI
override is provided. Passing --body-length-limit 0 still disables wrapping.

Steps to Test This Pull Request

  1. Configure body_length_limit = 20.
  2. Run cz commit without --body-length-limit and enter a body line longer
    than 20 characters.
  3. Verify that the resulting commit body is wrapped to 20 characters.
  4. Repeat with --body-length-limit 0 and verify that wrapping is disabled.
  5. Run uv run pytest tests/commands/test_commit_command.py.

Additional Context

The regression test exercises the same None value produced by argparse when
the CLI option is omitted. Collected coverage remains 98% overall and 99% for
commitizen/commands/commit.py; all newly added executable lines are covered.

Treat an omitted CLI option as no override so project configuration controls
body wrapping while an explicit zero continues to disable it.

Fixes commitizen-tools#2093

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@codecov

codecov Bot commented Sep 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.27%. Comparing base (3f5ccc8) to head (fe7d589).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2094   +/-   ##
=======================================
  Coverage   98.27%   98.27%           
=======================================
  Files          61       61           
  Lines        2836     2838    +2     
=======================================
+ Hits         2787     2789    +2     
  Misses         49       49           

☔ 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 September 23, 2026 08:22

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Configured body_length_limit is ignored by cz commit

1 participant