Preserve whitespace when remembering commit message#5528
Conversation
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
| Duplication | 4 |
🟢 Coverage 100.00% diff coverage
Metric Results Coverage variation Report missing for 2ad6e1a1 Diff coverage ✅ 100.00% diff coverage Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (2ad6e1a) Report Missing Report Missing Report Missing Head commit (227081f) 62025 53997 87.06% Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch:
<coverage of head commit> - <coverage of common ancestor commit>Diff coverage details
Coverable lines Covered lines Diff coverage Pull request (#5528) 66 66 100.00% Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified:
<covered lines added or modified>/<coverable lines added or modified> * 100%1 Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes. Give us feedback
Git's --grep option uses Basic Regular Expression syntax by default, which means that the `[^\n]*` didn't do what was intended; it means "any character except `\` or the literal letter `n`" — not "any character except newline." Besides, `^` matched any line start, not only the start of the entire message, so "any character except newline" would have been wrong anyway. Given this, the script matched commits that have WIP or DROPME in the body, which is not what we want. (The last commit of this branch is an example for that.) Fix this by listing only the subject lines and grepping them outside of git; this also lets us use a slightly simpler regex (we want to match WIP anywhere in the subject).
Callers currently hand this function a trimmed description, so the output is always clean. An upcoming change to the commit-panel getters will stop trimming at the callsite (so that whitespace typed by the user round-trips through the preservation file exactly), at which point the description can end with one or more newlines. Without this change, a user who presses Enter after their description body and then invokes "Add co-author" would end up with two blank lines between the body and the trailer instead of the expected one.
…t messages Typing a description with leading blank lines, canceling the commit panel, and reopening it currently drops leading blank lines.
This is useful when cancelling out of the commit panel mid-sentence (after
having typed the space for the next word); when entering the commit message
panel again, the space was gone and you had to type it again. Small thing, but
it just seems better to resume the panel in exactly the state that you left it
in. (Which we actually don't do; we don't remember the cursor position, or which
of the subject/description panels was active. That would be a separate
improvement.)
The save path and the load path used to be asymmetric. On save, the textarea
getters applied strings.TrimSpace, which stripped any leading blank lines, a
trailing newline after the cursor, or indentation on the very first line of the
description — all of which are legitimate user content. On load,
SplitCommitMessageAndDescription did TrimSpace on the description as well, and
the preserved message was routed through that same git-format split because
HandleCommitPress passed it as OpenCommitMessagePanel's InitialMessage. The
result: every round-trip through "escape and reopen" silently mutated the
message.
The fix is to treat our own preservation file as its own format, distinct from
git's canonical "summary\n\nbody" format:
- The textarea getters return raw content. strings.TrimSpace moves to the one
place that still needs it: the empty-summary check in HandleCommitConfirm (git
itself strips trailing whitespace and blank lines, so no pre-trim is needed
before -m).
- SplitPreservedCommitMessage / SetPreservedMessageInView split on the single
"\n" our Join uses, without any trimming — truly lossless.
- SplitCommitMessageAndDescription keeps its git-format behavior but replaces
TrimSpace with TrimPrefix("\n"), so it strips only the blank-line separator
and leaves body indentation intact.
- HandleCommitPress now mirrors HandleWIPCommitPress: it no longer passes the
preserved message as InitialMessage. OpenCommitMessagePanel resolves the
preserved content itself, uses it for display via the preservation-format
setter, and stores it as the initial message so the close-time "did the user
change anything?" check still correctly detects a cleared panel.
- GetInitialMessage no longer trims. With raw getters on both sides of the
comparison, trimming here caused spurious non-matches (e.g. for preserved
content with trailing whitespace). The original motivation — matching a
"WIP: " prefix with trailing space — works unchanged.
- UpdateCommitPanelView becomes dead code and is removed; its one remaining
caller (history cycling, always git-format) goes directly through
SetMessageAndDescriptionInView.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
6f989a9 to
227081f
Compare
This is useful when cancelling out of the commit panel mid-sentence (after having typed the space for the next word); when entering the commit message panel again, the space was gone and you had to type it again. Small thing, but it just seems better to resume the panel in exactly the state that you left it in. (Which we actually don't do; we don't remember the cursor position, or which of the subject/description panels was active. That would be a separate improvement.)
Fixes #5519.