From 3b5bfe4529a3fcedff03243ce7a65c239c307e7f Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Thu, 20 Aug 2026 19:18:22 +0200 Subject: [PATCH] Move partial-patch destination tests onto the commit diff Line-level patch moves must keep their behavior for added and deleted files, adjacent additions, stacked branches, and conflicting earlier destinations. Select those lines directly in the focused diff so only the intended changes move and file-level metadata stays with the source when appropriate. Co-Authored-By: GitHub Copilot --- .../move_partial_patch_to_later_commit.go} | 35 +++++++------------ .../move_partial_patch_to_new_commit.go} | 29 ++++++--------- ...atch_from_added_file_to_earlier_commit.go} | 27 +++++++------- ...ve_patch_from_added_file_to_new_commit.go} | 17 ++++----- ..._patch_from_deleted_file_to_new_commit.go} | 18 +++++----- ..._patch_to_new_commit_in_stacked_branch.go} | 17 +++++---- pkg/integration/tests/test_list.go | 12 +++---- 7 files changed, 70 insertions(+), 85 deletions(-) rename pkg/integration/tests/{patch_building/move_to_later_commit_partial_hunk.go => main_view/move_partial_patch_to_later_commit.go} (71%) rename pkg/integration/tests/{patch_building/move_to_new_commit_partial_hunk.go => main_view/move_partial_patch_to_new_commit.go} (73%) rename pkg/integration/tests/{patch_building/move_to_earlier_commit_from_added_file.go => main_view/move_patch_from_added_file_to_earlier_commit.go} (79%) rename pkg/integration/tests/{patch_building/move_to_new_commit_from_added_file.go => main_view/move_patch_from_added_file_to_new_commit.go} (81%) rename pkg/integration/tests/{patch_building/move_to_new_commit_from_deleted_file.go => main_view/move_patch_from_deleted_file_to_new_commit.go} (81%) rename pkg/integration/tests/{patch_building/move_to_new_commit_in_last_commit_of_stacked_branch.go => main_view/move_patch_to_new_commit_in_stacked_branch.go} (79%) diff --git a/pkg/integration/tests/patch_building/move_to_later_commit_partial_hunk.go b/pkg/integration/tests/main_view/move_partial_patch_to_later_commit.go similarity index 71% rename from pkg/integration/tests/patch_building/move_to_later_commit_partial_hunk.go rename to pkg/integration/tests/main_view/move_partial_patch_to_later_commit.go index 974dd4ec6..556f85969 100644 --- a/pkg/integration/tests/patch_building/move_to_later_commit_partial_hunk.go +++ b/pkg/integration/tests/main_view/move_partial_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 MoveToLaterCommitPartialHunk = NewIntegrationTest(NewIntegrationTestArgs{ - Description: "Move a patch from a commit to a later commit, with only parts of a hunk in the patch", +var MovePartialPatchToLaterCommit = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Move one of two adjacent additions 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.CreateFileAndAdd("file1", "") shell.Commit("first commit") @@ -36,23 +38,15 @@ var MoveToLaterCommitPartialHunk = NewIntegrationTest(NewIntegrationTestArgs{ Lines( Contains("file1").IsSelected(), ). - PressEnter() + Press(keys.Universal.FocusMainView) - t.Views().PatchBuilding(). + t.Views().Main(). IsFocused(). - PressPrimaryAction(). - PressEscape() + SelectedLines(Contains("+1st line")). + PressPrimaryAction() t.Views().Information().Content(Contains("Building patch")) - - t.Views().CommitFiles(). - IsFocused(). - PressEscape() - - t.Views().Commits(). - IsFocused(). - SelectPreviousItem() - + t.Views().Commits().Focus().SelectPreviousItem() t.Common().SelectPatchOption(Contains("Move patch to selected commit")) t.Views().Commits(). @@ -73,8 +67,7 @@ var MoveToLaterCommitPartialHunk = NewIntegrationTest(NewIntegrationTestArgs{ ). SelectNextItem(). Tap(func() { - t.Views().Main(). - Content(Contains("+1st line\n 2nd line")) + t.Views().Main().Content(Contains("+1st line\n 2nd line")) }). PressEscape() @@ -89,9 +82,7 @@ var MoveToLaterCommitPartialHunk = NewIntegrationTest(NewIntegrationTestArgs{ Contains("file1").IsSelected(), ). Tap(func() { - t.Views().Main(). - Content(Contains("+2nd line"). - DoesNotContain("1st line")) + t.Views().Main().Content(Contains("+2nd line").DoesNotContain("1st line")) }) }, }) diff --git a/pkg/integration/tests/patch_building/move_to_new_commit_partial_hunk.go b/pkg/integration/tests/main_view/move_partial_patch_to_new_commit.go similarity index 73% rename from pkg/integration/tests/patch_building/move_to_new_commit_partial_hunk.go rename to pkg/integration/tests/main_view/move_partial_patch_to_new_commit.go index 4d12e0f90..914157c75 100644 --- a/pkg/integration/tests/patch_building/move_to_new_commit_partial_hunk.go +++ b/pkg/integration/tests/main_view/move_partial_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 MoveToNewCommitPartialHunk = NewIntegrationTest(NewIntegrationTestArgs{ - Description: "Move a patch from a commit to a new commit, with only parts of a hunk in the patch", +var MovePartialPatchToNewCommit = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Move one of two adjacent additions 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.CreateFileAndAdd("file1", "") shell.Commit("first commit") @@ -36,14 +38,14 @@ var MoveToNewCommitPartialHunk = NewIntegrationTest(NewIntegrationTestArgs{ Lines( Contains("file1").IsSelected(), ). - PressEnter() + Press(keys.Universal.FocusMainView) - t.Views().PatchBuilding(). + t.Views().Main(). IsFocused(). + SelectedLines(Contains("+1st line")). PressPrimaryAction() t.Views().Information().Content(Contains("Building patch")) - t.Common().SelectPatchOption(Contains("Move patch into new commit after the original commit")) t.ExpectPopup().CommitMessagePanel(). @@ -66,19 +68,12 @@ var MoveToNewCommitPartialHunk = NewIntegrationTest(NewIntegrationTestArgs{ Contains("file1").IsSelected(), ). Tap(func() { - t.Views().Main(). - Content(Contains("+1st line\n 2nd line")) + t.Views().Main().Content(Contains("+1st line\n 2nd line")) }). PressEscape() t.Views().Commits(). IsFocused(). - Lines( - Contains("third commit"), - Contains("new commit").IsSelected(), - Contains("commit to move from"), - Contains("first commit"), - ). SelectNextItem(). PressEnter() @@ -88,9 +83,7 @@ var MoveToNewCommitPartialHunk = NewIntegrationTest(NewIntegrationTestArgs{ Contains("file1").IsSelected(), ). Tap(func() { - t.Views().Main(). - Content(Contains("+2nd line"). - DoesNotContain("1st line")) + t.Views().Main().Content(Contains("+2nd line").DoesNotContain("1st line")) }) }, }) diff --git a/pkg/integration/tests/patch_building/move_to_earlier_commit_from_added_file.go b/pkg/integration/tests/main_view/move_patch_from_added_file_to_earlier_commit.go similarity index 79% rename from pkg/integration/tests/patch_building/move_to_earlier_commit_from_added_file.go rename to pkg/integration/tests/main_view/move_patch_from_added_file_to_earlier_commit.go index 7f0d3584f..316259b0c 100644 --- a/pkg/integration/tests/patch_building/move_to_earlier_commit_from_added_file.go +++ b/pkg/integration/tests/main_view/move_patch_from_added_file_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 MoveToEarlierCommitFromAddedFile = NewIntegrationTest(NewIntegrationTestArgs{ - Description: "Move a patch from a file that was added in a commit to an earlier commit", +var MovePatchFromAddedFileToEarlierCommit = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Move part of an added file 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.EmptyCommit("first commit") shell.EmptyCommit("destination commit") @@ -31,23 +33,18 @@ var MoveToEarlierCommitFromAddedFile = NewIntegrationTest(NewIntegrationTestArgs Lines( Contains("A file").IsSelected(), ). - PressEnter() + Press(keys.Universal.FocusMainView) - t.Views().PatchBuilding(). + t.Views().Main(). IsFocused(). - SelectNextItem(). + NavigateToLine(Contains("+2nd line")). PressPrimaryAction() t.Views().Information().Content(Contains("Building patch")) - - t.Views().Commits(). - Focus(). - SelectNextItem() - + t.Views().Commits().Focus().SelectNextItem() t.Common().SelectPatchOption(Contains("Move patch to selected commit")) - // This results in a conflict at the commit we're moving from, because - // it tries to add a file that already exists + // The source commit tries to add a file that the moved line now causes to exist. t.Common().AcknowledgeConflicts() t.Views().Files(). @@ -69,7 +66,7 @@ var MoveToEarlierCommitFromAddedFile = NewIntegrationTest(NewIntegrationTestArgs Contains(">>>>>>>"), ). SelectNextItem(). - PressPrimaryAction() // choose the version with all three lines + PressPrimaryAction() t.Common().ContinueOnConflictsResolved("rebase") diff --git a/pkg/integration/tests/patch_building/move_to_new_commit_from_added_file.go b/pkg/integration/tests/main_view/move_patch_from_added_file_to_new_commit.go similarity index 81% rename from pkg/integration/tests/patch_building/move_to_new_commit_from_added_file.go rename to pkg/integration/tests/main_view/move_patch_from_added_file_to_new_commit.go index 11abe23f4..614c74305 100644 --- a/pkg/integration/tests/patch_building/move_to_new_commit_from_added_file.go +++ b/pkg/integration/tests/main_view/move_patch_from_added_file_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 MoveToNewCommitFromAddedFile = NewIntegrationTest(NewIntegrationTestArgs{ - Description: "Move a patch from a file that was added in a commit to a new commit", +var MovePatchFromAddedFileToNewCommit = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Move part of an added file 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.EmptyCommit("first commit") @@ -30,15 +32,14 @@ var MoveToNewCommitFromAddedFile = NewIntegrationTest(NewIntegrationTestArgs{ Lines( Contains("file1").IsSelected(), ). - PressEnter() + Press(keys.Universal.FocusMainView) - t.Views().PatchBuilding(). + t.Views().Main(). IsFocused(). - SelectNextItem(). + NavigateToLine(Contains("+2nd line")). PressPrimaryAction() t.Views().Information().Content(Contains("Building patch")) - t.Common().SelectPatchOption(Contains("Move patch into new commit after the original commit")) t.ExpectPopup().CommitMessagePanel(). diff --git a/pkg/integration/tests/patch_building/move_to_new_commit_from_deleted_file.go b/pkg/integration/tests/main_view/move_patch_from_deleted_file_to_new_commit.go similarity index 81% rename from pkg/integration/tests/patch_building/move_to_new_commit_from_deleted_file.go rename to pkg/integration/tests/main_view/move_patch_from_deleted_file_to_new_commit.go index 9edc06fb2..a4c65829b 100644 --- a/pkg/integration/tests/patch_building/move_to_new_commit_from_deleted_file.go +++ b/pkg/integration/tests/main_view/move_patch_from_deleted_file_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 MoveToNewCommitFromDeletedFile = NewIntegrationTest(NewIntegrationTestArgs{ - Description: "Move a patch from a file that was deleted in a commit to a new commit", +var MovePatchFromDeletedFileToNewCommit = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Move part of a deleted file 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.CreateFileAndAdd("file1", "1st line\n2nd line\n3rd line\n") shell.Commit("first commit") @@ -30,15 +32,14 @@ var MoveToNewCommitFromDeletedFile = NewIntegrationTest(NewIntegrationTestArgs{ Lines( Contains("D file1").IsSelected(), ). - PressEnter() + Press(keys.Universal.FocusMainView) - t.Views().PatchBuilding(). + t.Views().Main(). IsFocused(). - SelectNextItem(). + NavigateToLine(Contains("-2nd line")). PressPrimaryAction() t.Views().Information().Content(Contains("Building patch")) - t.Common().SelectPatchOption(Contains("Move patch into new commit after the original commit")) t.ExpectPopup().CommitMessagePanel(). @@ -74,7 +75,6 @@ var MoveToNewCommitFromDeletedFile = NewIntegrationTest(NewIntegrationTestArgs{ t.Views().CommitFiles(). IsFocused(). Lines( - // In the original commit the file is no longer deleted, but modified Contains("M file1").IsSelected(), ). Tap(func() { diff --git a/pkg/integration/tests/patch_building/move_to_new_commit_in_last_commit_of_stacked_branch.go b/pkg/integration/tests/main_view/move_patch_to_new_commit_in_stacked_branch.go similarity index 79% rename from pkg/integration/tests/patch_building/move_to_new_commit_in_last_commit_of_stacked_branch.go rename to pkg/integration/tests/main_view/move_patch_to_new_commit_in_stacked_branch.go index 67170b35a..0e8250c26 100644 --- a/pkg/integration/tests/patch_building/move_to_new_commit_in_last_commit_of_stacked_branch.go +++ b/pkg/integration/tests/main_view/move_patch_to_new_commit_in_stacked_branch.go @@ -1,17 +1,18 @@ -package patch_building +package main_view import ( "github.com/jesseduffield/lazygit/pkg/config" . "github.com/jesseduffield/lazygit/pkg/integration/components" ) -var MoveToNewCommitInLastCommitOfStackedBranch = NewIntegrationTest(NewIntegrationTestArgs{ - Description: "Move a patch from a commit to a new commit, in the last commit of a branch in the middle of a stack", +var MovePatchToNewCommitInStackedBranch = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Move a patch to a new commit after the last commit of a branch in the middle of a stack", ExtraCmdArgs: []string{}, Skip: false, GitVersion: AtLeast("2.38.0"), SetupConfig: func(config *config.AppConfig) { config.GetUserConfig().Git.Log.ShowGraph = "never" + config.GetUserConfig().Gui.UseHunkModeInStagingView = false }, SetupRepo: func(shell *Shell) { shell. @@ -46,12 +47,14 @@ var MoveToNewCommitInLastCommitOfStackedBranch = NewIntegrationTest(NewIntegrati Equals(" A file1"), Equals(" A file2"), ). - SelectNextItem(). - PressPrimaryAction(). - PressEscape() + Press(keys.Universal.FocusMainView) + + t.Views().Main(). + IsFocused(). + SelectedLines(Contains("+file1 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(). diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index 20b499b55..ee00af31a 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -411,7 +411,12 @@ var tests = []*components.IntegrationTest{ main_view.MoveMultiFileRangeToIndex, main_view.MovePartOfAdjacentAddedLinesToIndex, main_view.MovePartialPatchToIndex, + main_view.MovePartialPatchToLaterCommit, + main_view.MovePartialPatchToNewCommit, + main_view.MovePatchFromAddedFileToEarlierCommit, main_view.MovePatchFromAddedFileToIndexWithConflict, + main_view.MovePatchFromAddedFileToNewCommit, + main_view.MovePatchFromDeletedFileToNewCommit, main_view.MovePatchToEarlierCommit, main_view.MovePatchToIndex, main_view.MovePatchToIndexWithConflict, @@ -420,6 +425,7 @@ var tests = []*components.IntegrationTest{ main_view.MovePatchToLaterCommit, main_view.MovePatchToNewCommit, main_view.MovePatchToNewCommitBefore, + main_view.MovePatchToNewCommitInStackedBranch, main_view.NavigateByHunkAndFile, main_view.NoSelectionOverABinaryDiff, main_view.NoSelectionOverACommitLog, @@ -483,12 +489,6 @@ var tests = []*components.IntegrationTest{ patch_building.CopyRenamedFileDiff, patch_building.DiscardLinesFromCommit, patch_building.EditLineInPatchBuildingPanel, - patch_building.MoveToEarlierCommitFromAddedFile, - patch_building.MoveToLaterCommitPartialHunk, - patch_building.MoveToNewCommitFromAddedFile, - patch_building.MoveToNewCommitFromDeletedFile, - patch_building.MoveToNewCommitInLastCommitOfStackedBranch, - patch_building.MoveToNewCommitPartialHunk, patch_building.RemoveFromCommit, patch_building.RemovePartsOfAddedFile, patch_building.RenameSimilarityThresholdChange,