Skip to content

fix: honor configured message length limit - #2124

Open
schlotter wants to merge 1 commit into
commitizen-tools:masterfrom
ZEISS:fix/configured-message-length-limit
Open

schlotter wants to merge 1 commit into
commitizen-tools:masterfrom
ZEISS:fix/configured-message-length-limit

Conversation

@schlotter

@schlotter schlotter commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Description

Make cz commit and cz check honor configured message_length_limit when the CLI option is omitted.

Treat argparse's None as no CLI override, using the same approach as #2094. Preserve explicit -l 0 to disable the limit. Add regression tests and clarify configuration precedence.

Fixes #1899.

Checklist

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

  • Yes (GitHub Copilot CLI)

Generated-by: GitHub Copilot CLI following the guidelines

Assisted By: AI

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

Documentation Changes

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

Expected Behavior

Both commands use CLI value > configured value > default (0, no limit). Omitting the CLI option must not disable the configured limit.

Steps to Test This Pull Request

  1. Configure message_length_limit = 10 under [tool.commitizen].
  2. Run cz check --message "feat: this is definitely too long" without -l; expect rejection.
  3. Repeat with -l 0; expect success.
  4. Run cz commit --dry-run and enter an oversized subject; expect rejection. Repeat with -l 0; expect a dry-run message.

Validation completed:

  • uv run pytest tests/commands/test_commit_command.py tests/commands/test_check_command.py — passed, 80 tests.
  • uv run poe lint — passed, Ruff and mypy.
  • uv run ruff format --check commitizen/commands/commit.py commitizen/commands/check.py tests/commands/test_commit_command.py tests/commands/test_check_command.py — passed.
  • uv run poe doc:build — passed.
  • git diff --check — passed.

Additional validation:

  • PYTEST_XDIST_AUTO_NUM_WORKERS=2 uv run poe all — passed: formatting, Ruff, mypy, commit validation, and coverage suite. Results: 1,334 passed, two skipped, two expected failures; total coverage 98%. Worker count limited for the shared environment.
  • uv run pytest -q /home/y5cstt/.copilot/session-state/1bdcb306-308c-4386-a20c-b1c743083974/files/test_cli_validation.py — passed, 14 real-CLI scenarios in temporary Git repositories, without mocks. check used subprocesses; commit --dry-run used terminal-driven prompts through pexpect. These were scripted CLI checks, not human keyboard entry.
  • uv run poe doc --dev-addr 127.0.0.1:8765 — passed: preview started, /commitizen/config/check/ returned HTTP 200, and the updated text was verified in the rendered HTML. Preview stopped after verification.
  • uv run mkdocs build --strict — passed, with no broken-link diagnostics.
  • uv run pytest -q /home/y5cstt/.copilot/session-state/1bdcb306-308c-4386-a20c-b1c743083974/files/test_docs_validation.py — passed, three checks covering all local link targets and fragments plus both external links on the changed rendered page. Links elsewhere in the site were not exhaustively checked.

CLI scenarios performed for each command:

  1. Configured limit of 10, CLI option omitted: oversized subject rejected with the expected exit code.
  2. Configured limit of 10, -l 0: accepted.
  3. Configured limit of 10, -l 72: accepted.
  4. Configured limit of 72, -l 10: oversized subject rejected.
  5. Subject exactly at the configured limit: accepted.
  6. Configured limit of zero: accepted.
  7. No configured limit or CLI override: accepted.

Each accepted message included a long body to verify that the limit applies only to the subject. Commit checks used --dry-run; no test commits were created. Validation scripts remained outside the repository. No source changes were needed.

Additional Context

This is the message-length equivalent of the body-length fix in #2094 for #2093.

Use the configured limit when commit and check receive no CLI override. Preserve explicit zero to disable the limit.

Assisted By: AI

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

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.29%. Comparing base (e153e14) to head (11d9e4e).
⚠️ Report is 1 commits behind head on master.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2124   +/-   ##
=======================================
  Coverage   98.29%   98.29%           
=======================================
  Files          61       61           
  Lines        2866     2870    +4     
=======================================
+ Hits         2817     2821    +4     
  Misses         49       49           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

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.

Fix: message_length_limit config is ignored when CLI flag is unset (commit/check)

1 participant