Skip to content

Conversation

anasalaqeel
Copy link

Description

This PR implements multiline input functionality for the commit command - a completely new feature
that enables users to create detailed, well-formatted commit messages with multiline support.

Fixes #346

New Multiline Feature:

  • Smart Enter behavior for optional fields: Press Enter on empty line to skip optional fields (scope,

body, footer)

  • Required field validation: Shows helpful error messages when trying to skip required fields
    (subject)
  • Full multiline support: Use Enter for new lines and Alt+Enter to finish multiline input
  • Clear user guidance: Context-aware help messages and error handling with Ctrl+C abort option

Before This PR:

  • No multiline input support - all fields were single-line only
  • Users were limited to basic commit messages
  • No way to add detailed descriptions or multiline commit bodies
  • No intelligent handling of optional vs required fields

After This PR:

  • Full multiline support for all input fields
  • Intuitive Enter-to-skip behavior for optional fields
  • Proper validation and error handling for required fields
  • Enhanced user experience with clear guidance

Checklist

Code Changes

  • Add test cases to all the changes you introduce
  • Run poetry all locally to ensure this change passes linter check and tests
  • Manually test the changes:
    • Verify the feature works as expected in real-world scenarios
    • Test edge cases and error conditions
    • Ensure backward compatibility is maintained
    • Document manual testing steps performed
  • Update the documentation for the changes

Documentation Changes

  • Run poetry doc locally to ensure the documentation pages render correctly
  • Check and fix any broken links (internal or external) in the documentation

Expected Behavior

For Optional Fields (scope, body, footer):

  • Pressing Enter on empty line skips the field
  • Pressing Enter after typing content adds a new line for multiline input
  • Alt+Enter finishes and submits the input

For Required Fields (subject):

  • Pressing Enter on empty line shows error with guidance
  • Pressing Enter after typing content adds a new line for multiline input
  • Alt+Enter finishes and submits the input
  • Ctrl+C aborts the commit session

@bearomorphism
Copy link
Contributor

Hi @anasalaqeel ,
Thanks for contribution. The pipeline failed because some of your commit messages doesn't follow conventional commit.
Could you help to rebase your branch and amend the commit messages? Thanks.

@bearomorphism
Copy link
Contributor

bearomorphism commented Sep 25, 2025

But isn't #346 already fixed by #348?

@anasalaqeel anasalaqeel force-pushed the feature/multiline-edit branch from 0f11842 to f9c3a69 Compare September 27, 2025 12:17
@anasalaqeel
Copy link
Author

@bearomorphism I've rebased and updated the commit messages to follow Conventional Commit format, but it seems you committed on this branch as well so It keeps failing. I think you are committed to the wrong branch

@anasalaqeel
Copy link
Author

But isn't #346 already fixed by #348?

The proposed fix doesn't work, and it's not even documented anywhere.
My solution is a complete game-changer

@bearomorphism
Copy link
Contributor

I didn't commit on your branch...
The commit which confused you is from the master branch, and it appears on your branch because you merged / rebased the branch
If you check the current master branch then you'll find the same commit

@bearomorphism
Copy link
Contributor

But isn't #346 already fixed by #348?

The proposed fix doesn't work, and it's not even documented anywhere.

My solution is a complete game-changer

Got it.

Just note that since you're removing an existing cli argument, this PR will be a breaking change. It would be better to deprecate the old argument first, and then completely remove it in the next major release.

- Add ability to the answer inputs to aacept multilines.
- No more accidental Enter key, now Enter key only breaks the line into a new line and it can be removed/undo using backspace key normally.
- Now the user can submit the commit only when he is sure by pressing combination of Alt + Enter.

BREAKING CHANGE:
Fix required and optional inputs skipping behaveioiur:

    For optional fields (scope, body, footer):
    - Press Enter on empty line  skips the field
    - Press Enter after typing text  adds new line for multiline input
    - Alt+Enter  finishes multiline input

    For required fields (subject):
    - Press Enter on empty line  shows red error message " This field is required. Please enter some
    content." and prevents newline
    - Press Enter after typing text  adds new line for multiline input
    - Alt+Enter  finishes input
@anasalaqeel anasalaqeel force-pushed the feature/multiline-edit branch from 6a542fa to 2cc9ad8 Compare September 27, 2025 14:46
…feature

- Replace assert_called_once() with assert called for prompt mocks
- Tests now work with new multiline behavior that calls questionary.prompt multiple times
Copy link

codecov bot commented Sep 28, 2025

Codecov Report

❌ Patch coverage is 74.60317% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.74%. Comparing base (120d514) to head (8d0a92a).
⚠️ Report is 807 commits behind head on master.

Files with missing lines Patch % Lines
commitizen/commands/commit.py 73.33% 16 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1630      +/-   ##
==========================================
+ Coverage   97.33%   97.74%   +0.40%     
==========================================
  Files          42       58      +16     
  Lines        2104     2744     +640     
==========================================
+ Hits         2048     2682     +634     
- Misses         56       62       +6     
Flag Coverage Δ
unittests 97.74% <74.60%> (+0.40%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

- Use internal out module for colored prompts instead of ANSI codes
  - Extract all duplicated questionary prompt handling into helper functions
  - Remove outdated backslash continuation reference from commit message
  - Add comprehensive tests for edge cases and error scenarios
  - Fix type annotations and import organization

Addresses feedback from @bearomorphism in PR commitizen-tools#1630:
  - Lines 95-102: Replace ANSI colors with out.info/out.error
  - Lines 88-97, 200-209: Extract duplicated try/catch blocks
  - Clean up breaking change references
Consolidate multiline input logic into dedicated _handle_multiline_question function, removing duplicated code from the main prompt loop. Improve type hints by using Style instead of Any, and refactor error message formatting for consistency.
…mit feature

Refactored test files to improve maintainability and clarity:

**test_commit_command.py:**
- Created reusable mock_prompt fixture to eliminate duplicated mocking code
- Updated all tests to use the new fixture pattern with _handle_questionary_prompt
- Improved test for message length limit to properly test both success and failure cases
- Simplified test logic by removing unnecessary variable assignments

**test_commit_multiline.py:**
- Restructured tests into focused test classes by functionality
- Simplified test logic to directly test _handle_multiline_question function
- Added parameterized tests for optional field detection
- Improved test coverage for filter errors with proper retry behavior
- Removed redundant implementation-level tests in favor of behavior tests
- Enhanced test documentation and clarity
@bearomorphism
Copy link
Contributor

Thanks, now it is more readable and easier to be reviewed.

Let's wait for the maintainer's input. (They have quite limited bandwidth recently)

…est cases to cover previously untested code paths in the commit command:

- Test ValueError with CzException context in _handle_questionary_prompt
- Test manual_edit when editor executable is not found
- Test multiline question handling when result is None with/without default values
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Breaking change should support multiline
2 participants