Skip to content

feat(commit): add a tag(--body-length-limit) and a function for command commit - #1849

Merged
Lee-W merged 7 commits into
commitizen-tools:masterfrom
yjaw:feature/commit-line-limt
Aug 19, 2026
Merged

feat(commit): add a tag(--body-length-limit) and a function for command commit#1849
Lee-W merged 7 commits into
commitizen-tools:masterfrom
yjaw:feature/commit-line-limt

Conversation

@yjaw

@yjaw yjaw commented Feb 5, 2026

Copy link
Copy Markdown
Contributor

Description

I added a tag (—body-length-limit) for command commit. This tag utilizes Python’s built-in library, textwrap, to rewrap the body. It also respects the user’s |(\n) signal. This tag will affect the footer as well.
The flow is as follows:

  1. Split the body into separate lines using the \n character.
  2. Start from the third line, where the body begins. Use textwrap to rewrap that line.
  3. Reconstruct the entire body message from those rewrapped lines.

Checklist

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

  • Yes (please specify the tool below)

Generated-by: [Gemini] 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

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

  1. This option should modify the line length for your message if its length exceeds the limit you’ve set.
  2. Adding this tag or setting it to 0 should have no effect.
  3. If the message body is empty, it will be fine.
  4. This option will affect the text in both the body and footer sections.

Steps to Test This Pull Request

  1. When using the commit command, you can add the —body-length-limit [int] option to set a limit on the length of the commit message. If you don’t want to set a limit, you can set the option to 0.

Additional Context

close #1597

@codecov

codecov Bot commented Feb 5, 2026

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1849   +/-   ##
=======================================
  Coverage   98.25%   98.26%           
=======================================
  Files          61       61           
  Lines        2815     2829   +14     
=======================================
+ Hits         2766     2780   +14     
  Misses         49       49           

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

@bearomorphism bearomorphism left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks!

Comment thread tests/commands/test_commit_command.py Outdated
Comment thread tests/commands/test_commit_command.py Outdated
Comment thread tests/commands/test_commit_command.py Outdated
Comment thread tests/commands/test_commit_command.py Outdated
Comment thread tests/commands/test_commit_command.py Outdated
Comment thread tests/commands/test_commit_command.py Outdated
Comment thread commitizen/commands/commit.py Outdated
Comment thread commitizen/commands/commit.py Outdated
Comment thread commitizen/commands/commit.py Outdated
Comment thread commitizen/commands/commit.py Outdated
Comment thread commitizen/commands/commit.py Outdated
Comment thread tests/commands/test_commit_command.py Outdated
Comment thread commitizen/commands/commit.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds support for limiting/wrapping commit message body line length during cz commit, via a new --body-length-limit CLI option and a corresponding body_length_limit config/default setting.

Changes:

  • Add body_length_limit to default settings/config schema and expose it as --body-length-limit for cz commit.
  • Implement body rewrapping logic in the commit command using textwrap.
  • Add/adjust regression snapshots for cz commit --help and add commit-command tests around the new wrapping behavior.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
commitizen/commands/commit.py Adds body rewrapping logic (_rewrap_body) during interactive commit message creation.
commitizen/cli.py Adds --body-length-limit argument to the commit subcommand.
commitizen/defaults.py Introduces body_length_limit in Settings and DEFAULT_SETTINGS.
tests/test_conf.py Updates expected default config dictionaries to include body_length_limit.
tests/commands/test_commit_command.py Adds tests for body wrapping and config/CLI precedence.
tests/commands/test_common_command/test_command_shows_description_when_use_help_option_py_3_10_commit_.txt Updates CLI help snapshot to include --body-length-limit.
tests/commands/test_common_command/test_command_shows_description_when_use_help_option_py_3_11_commit_.txt Updates CLI help snapshot to include --body-length-limit.
tests/commands/test_common_command/test_command_shows_description_when_use_help_option_py_3_12_commit_.txt Updates CLI help snapshot to include --body-length-limit.
tests/commands/test_common_command/test_command_shows_description_when_use_help_option_py_3_13_commit_.txt Updates CLI help snapshot to include --body-length-limit.
tests/commands/test_common_command/test_command_shows_description_when_use_help_option_py_3_14_commit_.txt Updates CLI help snapshot to include --body-length-limit.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread commitizen/commands/commit.py Outdated
Comment thread tests/commands/test_commit_command.py Outdated
Comment thread tests/commands/test_commit_command.py
Comment thread commitizen/commands/commit.py Outdated
Comment thread commitizen/commands/commit.py
Comment thread commitizen/commands/commit.py Outdated
Comment thread commitizen/cli.py
Comment thread tests/commands/test_commit_command.py Outdated
Comment thread tests/commands/test_commit_command.py Outdated
Comment thread commitizen/commands/commit.py Outdated
Comment thread tests/commands/test_commit_command.py Outdated
Comment thread commitizen/commands/commit.py
Comment thread commitizen/cli.py
Comment thread commitizen/commands/commit.py Outdated
@bearomorphism

Copy link
Copy Markdown
Collaborator

There are conflicts. Turning this PR to draft

@bearomorphism
bearomorphism marked this pull request as draft February 9, 2026 11:59
@bearomorphism
bearomorphism marked this pull request as draft February 9, 2026 11:59
@yjaw
yjaw marked this pull request as ready for review February 9, 2026 23:16
@schlotter

Copy link
Copy Markdown
Contributor

Many thanks for this PR, exactly what I'm looking for 😊

Any help needed to move this over the finish line?

@bearomorphism

Copy link
Copy Markdown
Collaborator

Thanks for the reminder. I believe the maintainers barely have bandwidth to review PRs. I'll take a quick look.

@bearomorphism bearomorphism left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM.

@bearomorphism
bearomorphism requested review from Lee-W and woile August 6, 2026 08:00
@Lee-W
Lee-W enabled auto-merge (squash) August 19, 2026 03:29
@Lee-W Lee-W changed the title Feature/ add a tag(--body-length-limit) for command commit feat(commit): add a tag(--body-length-limit) and a function for command commit Aug 19, 2026
@woile

woile commented Aug 19, 2026

Copy link
Copy Markdown
Member

Could you rebase? 🙏🏻

yjaw added 7 commits August 19, 2026 15:13
…d use tuple argument in pytest.mark.parametrize
The test was previously passing even if the code accidentally skipped
the argument setting, which was incorrect. I realized I was always
overriding the configuration in the test. Now, I pass the argument
setting during mocking, and it behaves as expected.
@Lee-W
Lee-W force-pushed the feature/commit-line-limt branch from f17a654 to eea3bb8 Compare August 19, 2026 07:16
@Lee-W
Lee-W disabled auto-merge August 19, 2026 14:45
@Lee-W
Lee-W merged commit 363508d into commitizen-tools:master Aug 19, 2026
21 checks passed
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.

Add option for body line length

6 participants