From 822bd7b6a5f3c55e3468c237fbf14eccd98ee672 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Thu, 20 Aug 2026 19:14:49 +0200 Subject: [PATCH] Move whole-patch destination tests onto the commit diff Moving a complete patch must preserve each file operation whether its destination is a new commit before or after the source, or an existing commit earlier or later in history. Build those patches as ranges over the focused diff so the coverage survives removal of directory toggling in the patch builder. Co-Authored-By: GitHub Copilot --- .../move_patch_to_earlier_commit.go} | 25 ++++++++++-------- .../move_patch_to_later_commit.go} | 25 ++++++++++-------- .../move_patch_to_new_commit.go} | 26 +++++++++---------- .../move_patch_to_new_commit_before.go} | 22 ++++++++++------ pkg/integration/tests/test_list.go | 8 +++--- 5 files changed, 59 insertions(+), 47 deletions(-) rename pkg/integration/tests/{patch_building/move_to_earlier_commit.go => main_view/move_patch_to_earlier_commit.go} (80%) rename pkg/integration/tests/{patch_building/move_to_later_commit.go => main_view/move_patch_to_later_commit.go} (80%) rename pkg/integration/tests/{patch_building/move_to_new_commit.go => main_view/move_patch_to_new_commit.go} (82%) rename pkg/integration/tests/{patch_building/move_to_new_commit_before.go => main_view/move_patch_to_new_commit_before.go} (81%) diff --git a/pkg/integration/tests/patch_building/move_to_earlier_commit.go b/pkg/integration/tests/main_view/move_patch_to_earlier_commit.go similarity index 80% rename from pkg/integration/tests/patch_building/move_to_earlier_commit.go rename to pkg/integration/tests/main_view/move_patch_to_earlier_commit.go index 0c5e60f35..fb8614ac0 100644 --- a/pkg/integration/tests/patch_building/move_to_earlier_commit.go +++ b/pkg/integration/tests/main_view/move_patch_to_earlier_commit.go @@ -1,15 +1,17 @@ -package patch_building +package main_view import ( "github.com/jesseduffield/lazygit/pkg/config" . "github.com/jesseduffield/lazygit/pkg/integration/components" ) -var MoveToEarlierCommit = NewIntegrationTest(NewIntegrationTestArgs{ +var MovePatchToEarlierCommit = NewIntegrationTest(NewIntegrationTestArgs{ Description: "Move a patch from a commit to an earlier commit", ExtraCmdArgs: []string{}, Skip: false, - SetupConfig: func(config *config.AppConfig) {}, + SetupConfig: func(config *config.AppConfig) { + config.GetUserConfig().Gui.UseHunkModeInStagingView = false + }, SetupRepo: func(shell *Shell) { shell.CreateDir("dir") shell.CreateFileAndAdd("dir/file1", "file1 content") @@ -42,15 +44,17 @@ var MoveToEarlierCommit = NewIntegrationTest(NewIntegrationTestArgs{ Contains(" D file2"), Contains(" A file3"), ). - PressPrimaryAction(). - PressEscape() + Press(keys.Universal.FocusMainView) + + t.Views().Main(). + IsFocused(). + SelectedLines(Contains("-file1 content")). + Press(keys.Universal.ToggleRangeSelect). + NavigateToLine(Contains("+file3 content")). + PressPrimaryAction() t.Views().Information().Content(Contains("Building patch")) - - t.Views().Commits(). - IsFocused(). - SelectNextItem() - + t.Views().Commits().Focus().SelectNextItem() t.Common().SelectPatchOption(Contains("Move patch to selected commit")) t.Views().Commits(). @@ -79,7 +83,6 @@ var MoveToEarlierCommit = NewIntegrationTest(NewIntegrationTestArgs{ SelectPreviousItem(). PressEnter() - // the original commit has no more files in it t.Views().CommitFiles(). IsFocused(). Lines( diff --git a/pkg/integration/tests/patch_building/move_to_later_commit.go b/pkg/integration/tests/main_view/move_patch_to_later_commit.go similarity index 80% rename from pkg/integration/tests/patch_building/move_to_later_commit.go rename to pkg/integration/tests/main_view/move_patch_to_later_commit.go index aa97a9504..1dd746878 100644 --- a/pkg/integration/tests/patch_building/move_to_later_commit.go +++ b/pkg/integration/tests/main_view/move_patch_to_later_commit.go @@ -1,15 +1,17 @@ -package patch_building +package main_view import ( "github.com/jesseduffield/lazygit/pkg/config" . "github.com/jesseduffield/lazygit/pkg/integration/components" ) -var MoveToLaterCommit = NewIntegrationTest(NewIntegrationTestArgs{ +var MovePatchToLaterCommit = NewIntegrationTest(NewIntegrationTestArgs{ Description: "Move a patch from a commit to a later commit", ExtraCmdArgs: []string{}, Skip: false, - SetupConfig: func(config *config.AppConfig) {}, + SetupConfig: func(config *config.AppConfig) { + config.GetUserConfig().Gui.UseHunkModeInStagingView = false + }, SetupRepo: func(shell *Shell) { shell.CreateDir("dir") shell.CreateFileAndAdd("dir/file1", "file1 content") @@ -43,15 +45,17 @@ var MoveToLaterCommit = NewIntegrationTest(NewIntegrationTestArgs{ Contains(" D file2"), Contains(" A file3"), ). - PressPrimaryAction(). - PressEscape() + Press(keys.Universal.FocusMainView) + + t.Views().Main(). + IsFocused(). + SelectedLines(Contains("-file1 content")). + Press(keys.Universal.ToggleRangeSelect). + NavigateToLine(Contains("+file3 content")). + PressPrimaryAction() t.Views().Information().Content(Contains("Building patch")) - - t.Views().Commits(). - IsFocused(). - SelectPreviousItem() - + t.Views().Commits().Focus().SelectPreviousItem() t.Common().SelectPatchOption(Contains("Move patch to selected commit")) t.Views().Commits(). @@ -80,7 +84,6 @@ var MoveToLaterCommit = NewIntegrationTest(NewIntegrationTestArgs{ SelectNextItem(). PressEnter() - // the original commit has no more files in it t.Views().CommitFiles(). IsFocused(). Lines( diff --git a/pkg/integration/tests/patch_building/move_to_new_commit.go b/pkg/integration/tests/main_view/move_patch_to_new_commit.go similarity index 82% rename from pkg/integration/tests/patch_building/move_to_new_commit.go rename to pkg/integration/tests/main_view/move_patch_to_new_commit.go index 8f1c77376..d3b29efdf 100644 --- a/pkg/integration/tests/patch_building/move_to_new_commit.go +++ b/pkg/integration/tests/main_view/move_patch_to_new_commit.go @@ -1,15 +1,17 @@ -package patch_building +package main_view import ( "github.com/jesseduffield/lazygit/pkg/config" . "github.com/jesseduffield/lazygit/pkg/integration/components" ) -var MoveToNewCommit = NewIntegrationTest(NewIntegrationTestArgs{ +var MovePatchToNewCommit = NewIntegrationTest(NewIntegrationTestArgs{ Description: "Move a patch from a commit to a new commit", ExtraCmdArgs: []string{}, Skip: false, - SetupConfig: func(config *config.AppConfig) {}, + SetupConfig: func(config *config.AppConfig) { + config.GetUserConfig().Gui.UseHunkModeInStagingView = false + }, SetupRepo: func(shell *Shell) { shell.CreateDir("dir") shell.CreateFileAndAdd("dir/file1", "file1 content") @@ -43,11 +45,16 @@ var MoveToNewCommit = NewIntegrationTest(NewIntegrationTestArgs{ Contains(" D file2"), Contains(" A file3"), ). - PressPrimaryAction(). - PressEscape() + Press(keys.Universal.FocusMainView) + + t.Views().Main(). + IsFocused(). + SelectedLines(Contains("-file1 content")). + Press(keys.Universal.ToggleRangeSelect). + NavigateToLine(Contains("+file3 content")). + PressPrimaryAction() t.Views().Information().Content(Contains("Building patch")) - t.Common().SelectPatchOption(Contains("Move patch into new commit after the original commit")) t.ExpectPopup().CommitMessagePanel(). @@ -76,16 +83,9 @@ var MoveToNewCommit = NewIntegrationTest(NewIntegrationTestArgs{ t.Views().Commits(). IsFocused(). - Lines( - Contains("third commit"), - Contains("new commit").IsSelected(), - Contains("commit to move from"), - Contains("first commit"), - ). SelectNextItem(). PressEnter() - // the original commit has no more files in it t.Views().CommitFiles(). IsFocused(). Lines( diff --git a/pkg/integration/tests/patch_building/move_to_new_commit_before.go b/pkg/integration/tests/main_view/move_patch_to_new_commit_before.go similarity index 81% rename from pkg/integration/tests/patch_building/move_to_new_commit_before.go rename to pkg/integration/tests/main_view/move_patch_to_new_commit_before.go index 41e59d5b0..b22342c45 100644 --- a/pkg/integration/tests/patch_building/move_to_new_commit_before.go +++ b/pkg/integration/tests/main_view/move_patch_to_new_commit_before.go @@ -1,15 +1,17 @@ -package patch_building +package main_view import ( "github.com/jesseduffield/lazygit/pkg/config" . "github.com/jesseduffield/lazygit/pkg/integration/components" ) -var MoveToNewCommitBefore = NewIntegrationTest(NewIntegrationTestArgs{ - Description: "Move a patch from a commit to a new commit before the original one", +var MovePatchToNewCommitBefore = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Move a patch from a commit to a new commit before the source", ExtraCmdArgs: []string{}, Skip: false, - SetupConfig: func(config *config.AppConfig) {}, + SetupConfig: func(config *config.AppConfig) { + config.GetUserConfig().Gui.UseHunkModeInStagingView = false + }, SetupRepo: func(shell *Shell) { shell.CreateDir("dir") shell.CreateFileAndAdd("dir/file1", "file1 content") @@ -43,11 +45,16 @@ var MoveToNewCommitBefore = NewIntegrationTest(NewIntegrationTestArgs{ Contains(" D file2"), Contains(" A file3"), ). - PressPrimaryAction(). - PressEscape() + Press(keys.Universal.FocusMainView) + + t.Views().Main(). + IsFocused(). + SelectedLines(Contains("-file1 content")). + Press(keys.Universal.ToggleRangeSelect). + NavigateToLine(Contains("+file3 content")). + PressPrimaryAction() t.Views().Information().Content(Contains("Building patch")) - t.Common().SelectPatchOption(Contains("Move patch into new commit before the original commit")) t.ExpectPopup().CommitMessagePanel(). @@ -80,7 +87,6 @@ var MoveToNewCommitBefore = NewIntegrationTest(NewIntegrationTestArgs{ SelectPreviousItem(). PressEnter() - // the original commit has no more files in it t.Views().CommitFiles(). IsFocused(). Lines( diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index 11e2a7abd..ca8897907 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -414,10 +414,14 @@ var tests = []*components.IntegrationTest{ main_view.MovePartOfAdjacentAddedLinesToIndex, main_view.MovePartialPatchToIndex, main_view.MovePatchFromAddedFileToIndexWithConflict, + main_view.MovePatchToEarlierCommit, main_view.MovePatchToIndex, main_view.MovePatchToIndexWithConflict, main_view.MovePatchToIndexWithCustomDiffConfig, main_view.MovePatchToIndexWithModifiedFile, + main_view.MovePatchToLaterCommit, + main_view.MovePatchToNewCommit, + main_view.MovePatchToNewCommitBefore, main_view.NavigateByHunkAndFile, main_view.NoSelectionOverABinaryDiff, main_view.NoSelectionOverACommitLog, @@ -482,12 +486,8 @@ var tests = []*components.IntegrationTest{ patch_building.CopyRenamedFileDiff, patch_building.DiscardLinesFromCommit, patch_building.EditLineInPatchBuildingPanel, - patch_building.MoveToEarlierCommit, patch_building.MoveToEarlierCommitFromAddedFile, - patch_building.MoveToLaterCommit, patch_building.MoveToLaterCommitPartialHunk, - patch_building.MoveToNewCommit, - patch_building.MoveToNewCommitBefore, patch_building.MoveToNewCommitFromAddedFile, patch_building.MoveToNewCommitFromDeletedFile, patch_building.MoveToNewCommitInLastCommitOfStackedBranch,