diff --git a/pkg/integration/tests/patch_building/remove_parts_of_added_file.go b/pkg/integration/tests/main_view/remove_part_of_added_file_from_commit.go similarity index 63% rename from pkg/integration/tests/patch_building/remove_parts_of_added_file.go rename to pkg/integration/tests/main_view/remove_part_of_added_file_from_commit.go index 9a0b9a951..56734fd3c 100644 --- a/pkg/integration/tests/patch_building/remove_parts_of_added_file.go +++ b/pkg/integration/tests/main_view/remove_part_of_added_file_from_commit.go @@ -1,18 +1,19 @@ -package patch_building +package main_view import ( "github.com/jesseduffield/lazygit/pkg/config" . "github.com/jesseduffield/lazygit/pkg/integration/components" ) -var RemovePartsOfAddedFile = NewIntegrationTest(NewIntegrationTestArgs{ - Description: "Remove a custom patch from a file that was added in a commit", +var RemovePartOfAddedFileFromCommit = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Remove a custom patch containing one line of an added file from its 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.CreateFileAndAdd("file1", "1st line\n2nd line\n3rd line\n") shell.Commit("commit to remove from") }, @@ -30,27 +31,21 @@ var RemovePartsOfAddedFile = NewIntegrationTest(NewIntegrationTestArgs{ Lines( Contains("A 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("Remove patch from original commit")) - t.Views().CommitFiles(). + t.Views().Main(). IsFocused(). - Lines( - Contains("A file1").IsSelected(), - ). - PressEscape() - - t.Views().Main().ContainsLines( - Equals("+1st line"), - Equals("+3rd line"), - ) + ContainsLines( + Equals("+1st line"), + Equals("+3rd line"), + ) }, }) diff --git a/pkg/integration/tests/patch_building/remove_from_commit.go b/pkg/integration/tests/main_view/remove_patch_from_commit.go similarity index 67% rename from pkg/integration/tests/patch_building/remove_from_commit.go rename to pkg/integration/tests/main_view/remove_patch_from_commit.go index fbd78fcf7..f721625d7 100644 --- a/pkg/integration/tests/patch_building/remove_from_commit.go +++ b/pkg/integration/tests/main_view/remove_patch_from_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 RemoveFromCommit = NewIntegrationTest(NewIntegrationTestArgs{ - Description: "Remove a custom patch from a commit", +var RemovePatchFromCommit = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Remove a whole-file custom patch from its original 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", "file1 content\n") shell.CreateFileAndAdd("file2", "file2 content\n") @@ -30,30 +32,23 @@ var RemoveFromCommit = NewIntegrationTest(NewIntegrationTestArgs{ Contains("file1"), Contains("file2"), ). - SelectNextItem(). + Press(keys.Universal.FocusMainView) + + t.Views().Main(). + IsFocused(). + SelectedLines(Contains("+file1 content")). PressPrimaryAction() t.Views().Information().Content(Contains("Building patch")) - t.Views().Secondary().Content(Contains("+file1 content")) - t.Common().SelectPatchOption(Contains("Remove patch from original commit")) t.Views().Files().IsEmpty() - - t.Views().CommitFiles(). - IsFocused(). - Lines( - Contains("file2").IsSelected(), - ). - PressEscape() - t.Views().Main(). + IsFocused(). Content(Contains("+file2 content")) - - t.Views().Commits(). - Lines( - Contains("first commit").IsSelected(), - ) + t.Views().Commits().Lines( + Contains("first commit").IsSelected(), + ) }, }) diff --git a/pkg/integration/tests/main_view/start_patch_from_another_commit.go b/pkg/integration/tests/main_view/start_patch_from_another_commit.go new file mode 100644 index 000000000..24f77fa1b --- /dev/null +++ b/pkg/integration/tests/main_view/start_patch_from_another_commit.go @@ -0,0 +1,71 @@ +package main_view + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var StartPatchFromAnotherCommit = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Confirm replacing a custom patch when selecting lines from another commit", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) { + config.GetUserConfig().Gui.UseHunkModeInStagingView = false + }, + SetupRepo: func(shell *Shell) { + shell.CreateFileAndAdd("file1", "file1 content") + shell.Commit("first commit") + shell.CreateFileAndAdd("file2", "file2 content") + shell.Commit("second commit") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Commits(). + Focus(). + Lines( + Contains("second commit").IsSelected(), + Contains("first commit"), + ). + PressEnter() + + t.Views().CommitFiles(). + IsFocused(). + Lines( + Contains("file2").IsSelected(), + ). + Press(keys.Universal.FocusMainView) + + t.Views().Main(). + IsFocused(). + SelectedLines(Contains("+file2 content")). + PressPrimaryAction() + + t.Views().Information().Content(Contains("Building patch")) + t.Views().Secondary().Content(Contains("file2")) + + t.Views().Main().PressEscape() + t.Views().CommitFiles().IsFocused().PressEscape() + t.Views().Commits(). + IsFocused(). + NavigateToLine(Contains("first commit")). + PressEnter() + + t.Views().CommitFiles(). + IsFocused(). + Lines( + Contains("file1").IsSelected(), + ). + Press(keys.Universal.FocusMainView) + + t.Views().Main(). + IsFocused(). + SelectedLines(Contains("+file1 content")). + PressPrimaryAction() + + t.ExpectPopup().Confirmation(). + Title(Contains("Discard patch")). + Content(Contains("You can only build a patch from one commit/stash-entry at a time. Discard current patch?")). + Confirm() + + t.Views().Secondary().Content(Contains("file1").DoesNotContain("file2")) + }, +}) diff --git a/pkg/integration/tests/patch_building/start_new_patch.go b/pkg/integration/tests/patch_building/start_new_patch.go deleted file mode 100644 index 88402a953..000000000 --- a/pkg/integration/tests/patch_building/start_new_patch.go +++ /dev/null @@ -1,62 +0,0 @@ -package patch_building - -import ( - "github.com/jesseduffield/lazygit/pkg/config" - . "github.com/jesseduffield/lazygit/pkg/integration/components" -) - -var StartNewPatch = NewIntegrationTest(NewIntegrationTestArgs{ - Description: "Attempt to add a file from another commit to a patch, then agree to start a new patch", - ExtraCmdArgs: []string{}, - Skip: false, - SetupConfig: func(config *config.AppConfig) {}, - SetupRepo: func(shell *Shell) { - shell.CreateFileAndAdd("file1", "file1 content") - shell.Commit("first commit") - - shell.CreateFileAndAdd("file2", "file2 content") - shell.Commit("second commit") - }, - Run: func(t *TestDriver, keys config.KeybindingConfig) { - t.Views().Commits(). - Focus(). - Lines( - Contains("second commit").IsSelected(), - Contains("first commit"), - ). - PressEnter() - - t.Views().CommitFiles(). - IsFocused(). - Lines( - Contains("file2").IsSelected(), - ). - PressPrimaryAction(). - Tap(func() { - t.Views().Information().Content(Contains("Building patch")) - - t.Views().Secondary().Content(Contains("file2")) - }). - PressEscape() - - t.Views().Commits(). - IsFocused(). - NavigateToLine(Contains("first commit")). - PressEnter() - - t.Views().CommitFiles(). - IsFocused(). - Lines( - Contains("file1").IsSelected(), - ). - PressPrimaryAction(). - Tap(func() { - t.ExpectPopup().Confirmation(). - Title(Contains("Discard patch")). - Content(Contains("You can only build a patch from one commit/stash-entry at a time. Discard current patch?")). - Confirm() - - t.Views().Secondary().Content(Contains("file1").DoesNotContain("file2")) - }) - }, -}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index 04b6241da..01a5b0870 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -445,6 +445,8 @@ var tests = []*components.IntegrationTest{ main_view.RangeSelectDiffLines, main_view.RawFallbackUnderAnExternalDiff, main_view.RemoveLinesFromTheCustomPatch, + main_view.RemovePartOfAddedFileFromCommit, + main_view.RemovePatchFromCommit, main_view.RenderTheDiffBesideThePatchMarks, main_view.ResetAPatchBuiltFromACommitsDiff, main_view.ResetPatchWithEscape, @@ -477,6 +479,7 @@ var tests = []*components.IntegrationTest{ main_view.StageRangeSpanningFiles, main_view.StageUnderConformingDiffRenderer, main_view.StageUnderUnsupportedDiffRenderer, + main_view.StartPatchFromAnotherCommit, main_view.UnstageDiffLines, misc.ConfirmOnQuit, misc.CopyConfirmationMessageToClipboard, @@ -493,15 +496,12 @@ var tests = []*components.IntegrationTest{ misc.RecentReposWithLongNames, misc.StartInGitDir, patch_building.CopyRenamedFileDiff, - patch_building.RemoveFromCommit, - patch_building.RemovePartsOfAddedFile, patch_building.RenameSimilarityThresholdChange, patch_building.RenamedFilePartial, patch_building.RenamedFileWhole, patch_building.SelectAllFiles, patch_building.SelectDirecoriesSharingPrefix, patch_building.SpecificSelection, - patch_building.StartNewPatch, patch_building.ToggleDirectory, patch_building.ToggleRange, reflog.Checkout,