mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-10-03 20:46:47 -04:00
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 <copilot@github.com>
This commit is contained in:
co-authored by
GitHub Copilot
parent
3b5bfe4529
commit
bbc2e56747
+14
-24
@@ -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"),
|
||||
)
|
||||
},
|
||||
})
|
||||
+6
-5
@@ -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")).
|
||||
@@ -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"))
|
||||
},
|
||||
})
|
||||
@@ -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"))
|
||||
},
|
||||
})
|
||||
@@ -379,9 +379,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,
|
||||
@@ -437,6 +439,7 @@ var tests = []*components.IntegrationTest{
|
||||
main_view.RawFallbackUnderAnExternalDiff,
|
||||
main_view.RemoveLinesFromTheCustomPatch,
|
||||
main_view.ResetAPatchBuiltFromACommitsDiff,
|
||||
main_view.ResetPatchWithEscape,
|
||||
main_view.ResetThePatchFromThePaneShowingIt,
|
||||
main_view.SearchCollapsesTheSelection,
|
||||
main_view.SearchFollowsTheSelection,
|
||||
@@ -487,14 +490,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,
|
||||
|
||||
Reference in New Issue
Block a user