Skip to content

Support multi-line commit body input#1919

Open
axkoro wants to merge 4 commits intocommitizen-tools:masterfrom
axkoro:feature/multi-line-commit-body
Open

Support multi-line commit body input#1919
axkoro wants to merge 4 commits intocommitizen-tools:masterfrom
axkoro:feature/multi-line-commit-body

Conversation

@axkoro
Copy link
Copy Markdown

@axkoro axkoro commented Mar 31, 2026

Description

The interactive commit prompt had no way to enter multi-line commit bodies without resorting to --edit or using the newline separator | which is completely undocumented, from what I can tell.

This PR enables multi-line input for the commit body by setting multiline=True on the body question. This uses Questionary's native multi-line input. I also added a custom key binding, so that Enter submits on an empty buffer (skipping the field). Otherwise it now inserts a newline. Non-empty input can be submitted with Alt+Enter (Questionary's default).

Checklist

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

  • Yes (please specify the tool below)

Generated-by: Claude 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
    • No updating required, from what I can tell.

Steps to Test This Pull Request

Added: entering multi-line commit body

  1. Run cz commit and proceed to the body prompt
  2. Type something, press Enter → a newline should be inserted
  3. Type another line, press Alt+Enter → the input should be submitted with both lines preserved in the commit body

Kept: skipping the commit body

  1. Run cz commit and proceed to the body prompt
  2. (Enter nothing)
  3. Press Enter → the field should be skipped

Additional Context

The body prompt now displays a > prefix, which is prompt_toolkit's default multi-line indicator. This is slightly inconsistent with the other input fields. Remove it or keep this and maybe even add it to the other inputs as well?

Resolves #1917

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 31, 2026

Codecov Report

❌ Patch coverage is 82.35294% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.89%. Comparing base (7c21c21) to head (aa3c061).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
commitizen/question.py 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1919      +/-   ##
==========================================
- Coverage   97.99%   97.89%   -0.10%     
==========================================
  Files          60       60              
  Lines        2689     2705      +16     
==========================================
+ Hits         2635     2648      +13     
- Misses         54       57       +3     

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

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.

Enable multi-line commit body input

1 participant