jesseduffield.lazygit/pkg/integration/tests
Stefan Haller 227081f1d1 Preserve whitespace when remembering a commit message
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>
2026-04-21 18:51:17 +02:00
..
bisect Un-deprecate UserConfig.Git.Log.Order and ShowGraph 2025-07-09 13:15:03 +02:00
branch Don't stage out-of-date submodules when asking user to auto-stage after resolving conflicts 2026-03-30 17:41:53 +02:00
cherry_pick Add tests 2025-10-14 12:27:32 +02:00
commit Preserve whitespace when remembering a commit message 2026-04-21 18:51:17 +02:00
config Remove obsolete git version restrictions 2025-07-09 12:18:57 +02:00
conflicts Add merge options menu 2025-10-09 08:45:58 +02:00
custom_commands Add condition field to custom command prompts 2026-04-06 19:14:51 +02:00
demo Enable hunk staging mode by default 2025-08-01 10:35:16 +02:00
diff Fix copying a file's absolute path when running in a linked worktree 2026-04-19 11:16:02 +02:00
file Fix copying a file's absolute path when running in a linked worktree 2026-04-19 11:16:02 +02:00
filter_and_search Filter file views rather than search 2026-03-07 20:04:31 +01:00
filter_by_author Un-deprecate UserConfig.Git.Log.Order and ShowGraph 2025-07-09 13:15:03 +02:00
filter_by_path When entering a commit in path filtering mode, select the filtered path 2025-10-09 09:58:15 +02:00
interactive_rebase Support using the selected commit's message in a fixup 2026-01-28 10:28:52 +01:00
misc Add "CopyToClipboard" command to ConfirmationController 2025-08-15 17:17:06 +02:00
patch_building Filter file views rather than search 2026-03-07 20:04:31 +01:00
reflog Un-deprecate UserConfig.Git.Log.Order and ShowGraph 2025-07-09 13:15:03 +02:00
remote feat: add fork remote command 2025-11-16 17:26:00 +01:00
shared Add merge options menu 2025-10-09 08:45:58 +02:00
shell_commands Rename "Custom Command" to "Shell Command" 2024-08-17 10:56:03 +02:00
staging Revert test workaround 2026-03-19 16:57:53 +01:00
stash Fix dropping a range of stashes in filtered mode 2025-08-25 18:41:06 +02:00
status Add backward cycling support for all branches log view 2026-03-08 17:06:17 +01:00
submodule Make file sort order and case sensitivity configurable 2026-03-30 17:53:25 +02:00
sync Show worktree name next to branch in branches list 2026-03-09 11:34:34 +01:00
tag Fix deleting a remote tag when a remote branch with the same name exists 2025-11-27 19:52:18 +01:00
ui Add no-ff merge option 2025-10-19 21:24:28 +02:00
undo Switch to branches view when checking out a commit 2025-11-16 21:23:40 +01:00
worktree Show worktree name next to branch in branches list 2026-03-09 11:34:34 +01:00
test_list.go Add integration test demonstrating whitespace loss in preserved commit messages 2026-04-21 18:51:17 +02:00
test_list_generator.go Fix typos 2025-01-03 10:50:36 +11:00
tests.go Set working directory in lazygit test command 2024-01-12 19:59:31 +11:00