From c95105b322ce15e917ba3af5c3074ecb1a574b60 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Thu, 20 Aug 2026 19:23:47 +0200 Subject: [PATCH] Keep historical diff actions off the explorers Editing a line whose working-tree position shifted, discarding part of an added file, and giving up a patch by escaping are all behavior worth retaining. Drive them through the focused commit diff so their coverage no longer depends on the patch-building panel. Co-Authored-By: GitHub Copilot --- ...discard_line_from_added_file_in_commit.go} | 38 ++++++-------- .../edit_historical_diff_line.go} | 11 +++-- .../main_view/reset_patch_with_escape.go | 49 +++++++++++++++++++ .../tests/patch_building/reset_with_escape.go | 43 ---------------- pkg/integration/tests/test_list.go | 6 +-- 5 files changed, 72 insertions(+), 75 deletions(-) rename pkg/integration/tests/{patch_building/discard_lines_from_commit.go => main_view/discard_line_from_added_file_in_commit.go} (55%) rename pkg/integration/tests/{patch_building/edit_line_in_patch_building_panel.go => main_view/edit_historical_diff_line.go} (78%) create mode 100644 pkg/integration/tests/main_view/reset_patch_with_escape.go delete mode 100644 pkg/integration/tests/patch_building/reset_with_escape.go diff --git a/pkg/integration/tests/patch_building/discard_lines_from_commit.go b/pkg/integration/tests/main_view/discard_line_from_added_file_in_commit.go similarity index 55% rename from pkg/integration/tests/patch_building/discard_lines_from_commit.go rename to pkg/integration/tests/main_view/discard_line_from_added_file_in_commit.go index ab1414053..e86ad51d7 100644 --- a/pkg/integration/tests/patch_building/discard_lines_from_commit.go +++ b/pkg/integration/tests/main_view/discard_line_from_added_file_in_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 DiscardLinesFromCommit = NewIntegrationTest(NewIntegrationTestArgs{ - Description: "Discard specific lines from a commit using the 'd' shortcut in the patch building view", +var DiscardLineFromAddedFileInCommit = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Discard one line from an added file in a 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,15 +31,11 @@ var DiscardLinesFromCommit = NewIntegrationTest(NewIntegrationTestArgs{ Lines( Contains("A file1").IsSelected(), ). - PressEnter() + Press(keys.Universal.FocusMainView) - // Select the second line (+2nd line) and press 'd' to remove it - t.Views().PatchBuilding(). + t.Views().Main(). IsFocused(). - SelectNextItem(). - SelectedLines( - Contains("+2nd line"), - ). + NavigateToLine(Contains("+2nd line")). Press(keys.Universal.Remove) t.ExpectPopup().Confirmation(). @@ -46,18 +43,11 @@ var DiscardLinesFromCommit = NewIntegrationTest(NewIntegrationTestArgs{ Content(Equals("Are you sure you want to discard the selected lines from this commit?")). Confirm() - // After the rebase, we should be back at the commit files view - // and the commit should now only contain the 1st and 3rd lines - 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/edit_line_in_patch_building_panel.go b/pkg/integration/tests/main_view/edit_historical_diff_line.go similarity index 78% rename from pkg/integration/tests/patch_building/edit_line_in_patch_building_panel.go rename to pkg/integration/tests/main_view/edit_historical_diff_line.go index 2be88b7b8..91c229ef2 100644 --- a/pkg/integration/tests/patch_building/edit_line_in_patch_building_panel.go +++ b/pkg/integration/tests/main_view/edit_historical_diff_line.go @@ -1,15 +1,16 @@ -package patch_building +package main_view import ( "github.com/jesseduffield/lazygit/pkg/config" . "github.com/jesseduffield/lazygit/pkg/integration/components" ) -var EditLineInPatchBuildingPanel = NewIntegrationTest(NewIntegrationTestArgs{ - Description: "Edit a line in the patch building panel; make sure we end up on the right line", +var EditHistoricalDiffLine = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Edit a historical diff line at its current working-tree line number", ExtraCmdArgs: []string{}, Skip: false, SetupConfig: func(config *config.AppConfig) { + config.GetUserConfig().Gui.UseHunkModeInStagingView = false config.GetUserConfig().OS.EditAtLine = "echo {{filename}}:{{line}} > edit-command" }, SetupRepo: func(shell *Shell) { @@ -34,9 +35,9 @@ var EditLineInPatchBuildingPanel = NewIntegrationTest(NewIntegrationTestArgs{ Lines( Contains("A file.txt").IsSelected(), ). - PressEnter() + Press(keys.Universal.FocusMainView) - t.Views().PatchBuilding(). + t.Views().Main(). IsFocused(). Content(Contains("+4\n+5\n+6")). NavigateToLine(Contains("+5")). diff --git a/pkg/integration/tests/main_view/reset_patch_with_escape.go b/pkg/integration/tests/main_view/reset_patch_with_escape.go new file mode 100644 index 000000000..22cd6f340 --- /dev/null +++ b/pkg/integration/tests/main_view/reset_patch_with_escape.go @@ -0,0 +1,49 @@ +package main_view + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var ResetPatchWithEscape = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Reset a custom patch after escaping from the focused commit diff", + 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") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Commits(). + Focus(). + Lines( + Contains("first commit").IsSelected(), + ). + PressEnter() + + t.Views().CommitFiles(). + IsFocused(). + Lines( + Contains("file1").IsSelected(), + ). + Press(keys.Universal.FocusMainView) + + t.Views().Main(). + IsFocused(). + SelectedLines(Contains("+file1 content")). + PressPrimaryAction() + + t.Views().Information().Content(Contains("Building patch")) + + // Leave the focused diff and then the commit files panel. Escape at the top + // level gives up the patch. + t.Views().Main().PressEscape() + t.Views().CommitFiles().IsFocused().PressEscape() + t.Views().Commits().IsFocused().PressEscape() + + t.Views().Information().Content(DoesNotContain("Building patch")) + }, +}) diff --git a/pkg/integration/tests/patch_building/reset_with_escape.go b/pkg/integration/tests/patch_building/reset_with_escape.go deleted file mode 100644 index 7046890d3..000000000 --- a/pkg/integration/tests/patch_building/reset_with_escape.go +++ /dev/null @@ -1,43 +0,0 @@ -package patch_building - -import ( - "github.com/jesseduffield/lazygit/pkg/config" - . "github.com/jesseduffield/lazygit/pkg/integration/components" -) - -var ResetWithEscape = NewIntegrationTest(NewIntegrationTestArgs{ - Description: "Reset a custom patch with the escape keybinding", - ExtraCmdArgs: []string{}, - Skip: false, - SetupConfig: func(config *config.AppConfig) {}, - SetupRepo: func(shell *Shell) { - shell.CreateFileAndAdd("file1", "file1 content") - shell.Commit("first commit") - }, - Run: func(t *TestDriver, keys config.KeybindingConfig) { - t.Views().Commits(). - Focus(). - Lines( - Contains("first commit").IsSelected(), - ). - PressEnter() - - t.Views().CommitFiles(). - IsFocused(). - Lines( - Contains("file1").IsSelected(), - ). - PressPrimaryAction(). - Tap(func() { - t.Views().Information().Content(Contains("Building patch")) - }). - PressEscape() - - // hitting escape at the top level will reset the patch - t.Views().Commits(). - IsFocused(). - PressEscape() - - t.Views().Information().Content(DoesNotContain("Building patch")) - }, -}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index 09868abc5..8cd39ae0f 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -380,9 +380,11 @@ var tests = []*components.IntegrationTest{ main_view.DiscardAllChanges, main_view.DiscardDiffLines, main_view.DiscardFromACommitOnlyWhereItCanBeRewritten, + main_view.DiscardLineFromAddedFileInCommit, main_view.DiscardLinesFromACommit, main_view.DragRangeWithAutoscroll, main_view.DragSelectsDiffLineRange, + main_view.EditHistoricalDiffLine, main_view.EditHunkInFocusedDiff, main_view.EditSelectedDiffLine, main_view.EscapeDismissesSelection, @@ -440,6 +442,7 @@ var tests = []*components.IntegrationTest{ main_view.RemoveLinesFromTheCustomPatch, main_view.RenderTheDiffBesideThePatchMarks, main_view.ResetAPatchBuiltFromACommitsDiff, + main_view.ResetPatchWithEscape, main_view.ResetThePatchFromThePaneShowingIt, main_view.SearchCollapsesTheSelection, main_view.SearchFollowsTheSelection, @@ -490,14 +493,11 @@ var tests = []*components.IntegrationTest{ patch_building.ApplyWithModifiedFileConflict, patch_building.ApplyWithModifiedFileNoConflict, patch_building.CopyRenamedFileDiff, - patch_building.DiscardLinesFromCommit, - patch_building.EditLineInPatchBuildingPanel, patch_building.RemoveFromCommit, patch_building.RemovePartsOfAddedFile, patch_building.RenameSimilarityThresholdChange, patch_building.RenamedFilePartial, patch_building.RenamedFileWhole, - patch_building.ResetWithEscape, patch_building.SelectAllFiles, patch_building.SelectDirecoriesSharingPrefix, patch_building.SpecificSelection,