Skip to content

git: Preserve whitespaces in commit messages - #43478

Closed
tartarughina wants to merge 1 commit into
zed-industries:mainfrom
tartarughina:git-commit-rewrap-fix
Closed

git: Preserve whitespaces in commit messages#43478
tartarughina wants to merge 1 commit into
zed-industries:mainfrom
tartarughina:git-commit-rewrap-fix

Conversation

@tartarughina

@tartarughina tartarughina commented Nov 25, 2025

Copy link
Copy Markdown
Contributor

Closes #42476

Release Notes:

  • Preserve whitespaces in git commit messages

What Changed:

  • Modified commit message rewrapping behavior to preserve existing whitespace formatting
  • Added new commit_rewrap method to the Editor that maintains intentional spacing in commit messages

Technical Details:

  • Introduced commit_rewrap() method in editor.rs with preserve_existing_whitespace: true option
  • Updated Git panel to use commit_rewrap() instead of standard rewrap() when formatting commit messages
  • This ensures that deliberate formatting choices (like blank lines, indentation, and spacing) in commit messages are
    maintained during the rewrap operation

Impact:

  • Users can now format their commit messages with intentional whitespace without it being removed during the rewrap process
  • Improves commit message readability and preserves structured formatting (e.g., bullet points, paragraphs, code blocks)

Files Modified:

  • crates/editor/src/editor.rs - Added commit_rewrap() method
  • crates/git_ui/src/git_panel.rs - Updated to use new rewrap method

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Nov 25, 2025
@tartarughina tartarughina changed the title Preserve whitespaces in commit messages git: Preserve whitespaces in commit messages Nov 25, 2025
@cole-miller

Copy link
Copy Markdown
Member

Thanks for opening a PR! However, I think we might want to try a different approach to this. Note that re: #42476 we already have support for "rewrap prefixes" that support things like markdown lists (added in #33702). These prefixes should be respected by the normal editor rewrap, without that preserve_existing_whitespace option, and I believe we configure the same rewrap prefixes for the git commit language as for markdown. So it would be good to figure out why that configuration is not being respected.

@tartarughina

Copy link
Copy Markdown
Contributor Author

Likely the buffer for the commit is not getting recognized neither as Markdown nor as Git Commit. Before creating this PR, I've tried playing around with the settings for Git Commit language without any success.

@tartarughina

Copy link
Copy Markdown
Contributor Author

I've further tried to play around with the settings. A very foolproof setting I tried was to enable display whitespaces, but nothing happened in the git commit buffer. This proves that the language settings, as for git commit language as for markdown, are not even getting applied, as the buffer is not recognized at all as a language.

Furthermore, the whitespaces are preserved yes, but only in instances where multiple \n are present:

For example

This is my commit
message as I see it
in the buffer

as soon as I press the commit button becomes

This is my commit message as I see it in the buffer

but if I introduce multiple \n

This is my commit

message as I see it

in the buffer

pressing commit maintains the format

This is my commit

message as I see it

in the buffer

It definitely deserves further investigation, as this bug undoubtedly disrupts the workflow of people accustomed to providing commit messages spanning multiple lines with bullet points/lists.

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

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

No open projects

Development

Successfully merging this pull request may close these issues.

Git: newlines in commit message gets removed when using bullet points

3 participants