jesseduffield.lazygit/pkg/integration/tests/commit
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
..
add_co_author.go Extract functions AddCoAuthorToMessage and AddCoAuthorToDescription 2024-03-11 09:18:40 +01:00
add_co_author_range.go feat: support range selection for commit attributes amend 2024-06-07 23:09:52 +02:00
add_co_author_while_committing.go Add integration test 2024-03-11 09:19:11 +01:00
amend.go Use sentence case everywhere 2023-05-25 23:52:19 +10:00
amend_when_there_are_conflicts_and_amend.go Add section headers for rebase todos, cherry-picks, reverts, and actual commits 2025-04-20 16:06:15 +02:00
amend_when_there_are_conflicts_and_cancel.go Add section headers for rebase todos, cherry-picks, reverts, and actual commits 2025-04-20 16:06:15 +02:00
amend_when_there_are_conflicts_and_continue.go Show confirmation menu when trying to amend changes while there are conflicts 2025-01-30 08:53:34 +01:00
auto_wrap_message.go Use getters for AppState and UserConfig instead of accessing the fields directly 2024-08-18 10:24:52 +02:00
checkout.go Switch to branches view when checking out a commit 2025-11-16 21:23:40 +01:00
checkout_file_from_commit.go Add test for checking out a file from a commit 2025-03-25 09:56:01 +01:00
checkout_file_from_range_selection_of_commits.go Fix the bug mentioned in the previous commit 2025-03-25 09:56:01 +01:00
checkout_file_with_local_modifications.go Show an error when checking out a file would overwrite local modifications 2026-01-03 20:09:55 +01:00
commit.go Add a root item ("/") if files at top level have changed 2025-03-21 08:04:58 +01:00
commit_multiline.go Construct arg vector manually rather than parse string 2023-05-23 19:49:19 +10:00
commit_skip_hooks.go Commit without pre-commit hooks is independent on prefix 2025-03-22 11:04:28 +01:00
commit_switch_to_editor.go Add a root item ("/") if files at top level have changed 2025-03-21 08:04:58 +01:00
commit_switch_to_editor_skip_hooks.go Commit without pre-commit hooks is independent on prefix 2025-03-22 11:04:28 +01:00
commit_wip_with_prefix.go Prefill the commit subject with the skipHook prefix when pressing w 2025-04-10 08:53:11 +02:00
commit_with_fallthrough_prefix.go feat: Support multiple commit prefixes 2025-02-17 19:58:31 +01:00
commit_with_global_prefix.go feat: Support multiple commit prefixes 2025-02-17 19:58:31 +01:00
commit_with_non_matching_branch_name.go feat: Support multiple commit prefixes 2025-02-17 19:58:31 +01:00
commit_with_prefix.go feat: Support multiple commit prefixes 2025-02-17 19:58:31 +01:00
copy_author_to_clipboard.go Cleanup: simplify and tighten test expectations related to clipboard 2025-02-19 18:50:12 +01:00
copy_message_body_to_clipboard.go Add option to copy commit message body 2025-02-17 18:43:39 +01:00
copy_tag_to_clipboard.go Cleanup: simplify and tighten test expectations related to clipboard 2025-02-19 18:50:12 +01:00
create_amend_commit.go Remove git version specific code for versions we no longer support 2025-07-09 12:18:58 +02:00
create_fixup_commit_in_branch_stack.go Create fixup commit at end of its branch when there's a stack of branches 2024-09-15 11:19:39 +02:00
create_tag.go Better tag creation UX 2023-07-22 14:36:35 +10:00
disable_copy_commit_message_body.go Add option to copy commit message body 2025-02-17 18:43:39 +01:00
discard_old_file_changes.go Make file sort order and case sensitivity configurable 2026-03-30 17:53:25 +02:00
discard_submodule_changes.go Say "discard" instead of "remove" when discard changes from a commit 2026-03-07 20:47:19 +11:00
do_not_show_branch_marker_for_head_commit.go Un-deprecate UserConfig.Git.Log.Order and ShowGraph 2025-07-09 13:15:03 +02:00
fail_hooks_then_commit_no_hooks.go Commit without pre-commit hooks is independent on prefix 2025-03-22 11:04:28 +01:00
find_base_commit_for_fixup.go Fix order of fixup base commits shown in ctrl-f error message 2025-11-30 14:06:31 +01:00
find_base_commit_for_fixup_disregard_fixups_for_same_base_commit.go Ignore fixup commits for a found base commit when doing ctrl-f 2026-01-24 16:04:35 +01:00
find_base_commit_for_fixup_disregard_main_branch.go Disregard master commits when finding base commit for fixup 2024-06-10 12:00:24 +02:00
find_base_commit_for_fixup_only_added_lines.go Make find_base_commit_for_fixup tests more specific 2025-11-30 14:06:31 +01:00
find_base_commit_for_fixup_warning_for_added_lines.go Warn when there are hunks with only added lines 2024-01-10 09:11:40 +01:00
highlight.go Un-deprecate UserConfig.Git.Log.Order and ShowGraph 2025-07-09 13:15:03 +02:00
history.go Construct arg vector manually rather than parse string 2023-05-23 19:49:19 +10:00
history_complex.go Construct arg vector manually rather than parse string 2023-05-23 19:49:19 +10:00
new_branch.go Use sentence case everywhere 2023-05-25 23:52:19 +10:00
paste_commit_message.go Cleanup: simplify and tighten test expectations related to clipboard 2025-02-19 18:50:12 +01:00
paste_commit_message_over_existing.go Cleanup: simplify and tighten test expectations related to clipboard 2025-02-19 18:50:12 +01:00
preserve_commit_message.go Improve and adapt commit persistence test-cases 2025-02-07 09:28:27 +01:00
preserve_commit_message_whitespace.go Preserve whitespace when remembering a commit message 2026-04-21 18:51:17 +02:00
reset_author.go Use sentence case everywhere 2023-05-25 23:52:19 +10:00
reset_author_range.go feat: support range selection for commit attributes amend 2024-06-07 23:09:52 +02:00
revert.go Fix the main view display after reverting a commit 2025-12-23 14:55:58 +01:00
revert_merge.go Remove the "Select parent commit" prompt when reverting a merge commit 2025-04-20 16:03:06 +02:00
revert_with_conflict_multiple_commits.go Add section headers for rebase todos, cherry-picks, reverts, and actual commits 2025-04-20 16:06:15 +02:00
revert_with_conflict_single_commit.go Add section headers for rebase todos, cherry-picks, reverts, and actual commits 2025-04-20 16:06:15 +02:00
reword.go Add a root item ("/") if files at top level have changed 2025-03-21 08:04:58 +01:00
search.go Update search position (match x of y) when changing the selection in a list view 2026-01-04 18:51:45 +01:00
set_author.go Keep track of authors across local commits and branch commits for suggestions 2023-07-22 10:47:04 +10:00
set_author_range.go feat: support range selection for commit attributes amend 2024-06-07 23:09:52 +02:00
shared.go Add section headers for rebase todos, cherry-picks, reverts, and actual commits 2025-04-20 16:06:15 +02:00
stage_range_of_lines.go Enable hunk staging mode by default 2025-08-01 10:35:16 +02:00
staged.go Add a root item ("/") if files at top level have changed 2025-03-21 08:04:58 +01:00
staged_without_hooks.go Commit without pre-commit hooks is independent on prefix 2025-03-22 11:04:28 +01:00
unstaged.go Add a root item ("/") if files at top level have changed 2025-03-21 08:04:58 +01:00