From a5eec48b4b8f51054ef1b909df76cfd13ab78d46 Mon Sep 17 00:00:00 2001 From: Brandon Date: Sat, 25 May 2024 15:47:15 -0700 Subject: [PATCH 1/3] Fix multi selection stage/discard not working for files with substrings --- pkg/gui/controllers/files_controller.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/gui/controllers/files_controller.go b/pkg/gui/controllers/files_controller.go index 81d3f4cf0..39730ae09 100644 --- a/pkg/gui/controllers/files_controller.go +++ b/pkg/gui/controllers/files_controller.go @@ -1009,10 +1009,14 @@ func normalisedSelectedNodes(selectedNodes []*filetree.FileNode) []*filetree.Fil func isDescendentOfSelectedNodes(node *filetree.FileNode, selectedNodes []*filetree.FileNode) bool { for _, selectedNode := range selectedNodes { + if selectedNode.IsFile() { + continue + } + selectedNodePath := selectedNode.GetPath() nodePath := node.GetPath() - if strings.HasPrefix(nodePath, selectedNodePath) && nodePath != selectedNodePath { + if strings.HasPrefix(nodePath, selectedNodePath+"/") { return true } } From 2e5b570bb69e2cb1c1622b2ecb65ccb8c97cbe9a Mon Sep 17 00:00:00 2001 From: Brandon Date: Sun, 26 May 2024 11:34:25 -0700 Subject: [PATCH 2/3] Add integration test --- pkg/integration/components/shell.go | 11 +++++ .../tests/file/stage_renamed_range_select.go | 43 +++++++++++++++++++ pkg/integration/tests/test_list.go | 1 + 3 files changed, 55 insertions(+) create mode 100644 pkg/integration/tests/file/stage_renamed_range_select.go diff --git a/pkg/integration/components/shell.go b/pkg/integration/components/shell.go index 01a9caf3a..e38e0cd3f 100644 --- a/pkg/integration/components/shell.go +++ b/pkg/integration/components/shell.go @@ -134,6 +134,17 @@ func (self *Shell) UpdateFile(path string, content string) *Shell { return self } +func (self *Shell) Rename(path string, newPath string) *Shell { + fullPath := filepath.Join(self.dir, path) + newFullPath := filepath.Join(self.dir, newPath) + err := os.Rename(fullPath, newFullPath) + if err != nil { + self.fail(fmt.Sprintf("error renaming %s to %s\n%s", fullPath, newFullPath, err)) + } + + return self +} + func (self *Shell) NewBranch(name string) *Shell { return self.RunCommand([]string{"git", "checkout", "-b", name}) } diff --git a/pkg/integration/tests/file/stage_renamed_range_select.go b/pkg/integration/tests/file/stage_renamed_range_select.go new file mode 100644 index 000000000..472d8ef11 --- /dev/null +++ b/pkg/integration/tests/file/stage_renamed_range_select.go @@ -0,0 +1,43 @@ +package file + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var StageRenamedRangeSelect = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Stage a range of renamed files/folders using range select", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) { + }, + SetupRepo: func(shell *Shell) { + shell.CreateFileAndAdd("dir1/file-a", "A's content") + shell.CreateFileAndAdd("file-b", "B's content") + shell.Commit("first commit") + shell.Rename("dir1", "dir1_v2") + shell.Rename("file-b", "file-b_v2") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Files(). + IsFocused(). + Lines( + Contains("▼ dir1").IsSelected(), + Contains(" D").Contains("file-a"), + Contains("▼ dir1_v2"), + Contains(" ??").Contains("file-a"), + Contains(" D").Contains("file-b"), + Contains("??").Contains("file-b_v2"), + ). + // Select everything + Press(keys.Universal.ToggleRangeSelect). + NavigateToLine(Contains("file-b_v2")). + // Stage + PressPrimaryAction(). + Lines( + Contains("▼ dir1_v2"), + Contains(" R ").Contains("dir1/file-a → file-a"), + Contains("R ").Contains("file-b → file-b_v2").IsSelected(), + ) + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index cbd3471e5..ff2634d07 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -161,6 +161,7 @@ var tests = []*components.IntegrationTest{ file.Gitignore, file.RememberCommitMessageAfterFail, file.StageRangeSelect, + file.StageRenamedRangeSelect, filter_and_search.FilterCommitFiles, filter_and_search.FilterFiles, filter_and_search.FilterFuzzy, From 38aa5b89ab10adeff83ae9e67d669268813bd2f1 Mon Sep 17 00:00:00 2001 From: Brandon Date: Tue, 28 May 2024 18:09:07 -0700 Subject: [PATCH 3/3] Simplify integration test --- pkg/integration/components/shell.go | 11 ----- .../tests/file/stage_children_range_select.go | 45 +++++++++++++++++++ .../tests/file/stage_renamed_range_select.go | 43 ------------------ pkg/integration/tests/test_list.go | 2 +- 4 files changed, 46 insertions(+), 55 deletions(-) create mode 100644 pkg/integration/tests/file/stage_children_range_select.go delete mode 100644 pkg/integration/tests/file/stage_renamed_range_select.go diff --git a/pkg/integration/components/shell.go b/pkg/integration/components/shell.go index e38e0cd3f..01a9caf3a 100644 --- a/pkg/integration/components/shell.go +++ b/pkg/integration/components/shell.go @@ -134,17 +134,6 @@ func (self *Shell) UpdateFile(path string, content string) *Shell { return self } -func (self *Shell) Rename(path string, newPath string) *Shell { - fullPath := filepath.Join(self.dir, path) - newFullPath := filepath.Join(self.dir, newPath) - err := os.Rename(fullPath, newFullPath) - if err != nil { - self.fail(fmt.Sprintf("error renaming %s to %s\n%s", fullPath, newFullPath, err)) - } - - return self -} - func (self *Shell) NewBranch(name string) *Shell { return self.RunCommand([]string{"git", "checkout", "-b", name}) } diff --git a/pkg/integration/tests/file/stage_children_range_select.go b/pkg/integration/tests/file/stage_children_range_select.go new file mode 100644 index 000000000..30a0a5e6b --- /dev/null +++ b/pkg/integration/tests/file/stage_children_range_select.go @@ -0,0 +1,45 @@ +package file + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var StageChildrenRangeSelect = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Stage a range of files/folders and their children using range select", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) { + }, + SetupRepo: func(shell *Shell) { + shell.CreateFile("foo", "") + shell.CreateFile("foobar", "") + shell.CreateFile("baz/file", "") + shell.CreateFile("bazbam/file", "") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Files(). + IsFocused(). + Lines( + Contains("▼ baz").IsSelected(), + Contains(" ??").Contains("file"), + Contains("▼ bazbam"), + Contains(" ??").Contains("file"), + Contains("??").Contains("foo"), + Contains("??").Contains("foobar"), + ). + // Select everything + Press(keys.Universal.ToggleRangeSelect). + NavigateToLine(Contains("foobar")). + // Stage + PressPrimaryAction(). + Lines( + Contains("▼ baz").IsSelected(), + Contains(" A ").Contains("file").IsSelected(), + Contains("▼ bazbam").IsSelected(), + Contains(" A ").Contains("file").IsSelected(), + Contains("A ").Contains("foo").IsSelected(), + Contains("A ").Contains("foobar").IsSelected(), + ) + }, +}) diff --git a/pkg/integration/tests/file/stage_renamed_range_select.go b/pkg/integration/tests/file/stage_renamed_range_select.go deleted file mode 100644 index 472d8ef11..000000000 --- a/pkg/integration/tests/file/stage_renamed_range_select.go +++ /dev/null @@ -1,43 +0,0 @@ -package file - -import ( - "github.com/jesseduffield/lazygit/pkg/config" - . "github.com/jesseduffield/lazygit/pkg/integration/components" -) - -var StageRenamedRangeSelect = NewIntegrationTest(NewIntegrationTestArgs{ - Description: "Stage a range of renamed files/folders using range select", - ExtraCmdArgs: []string{}, - Skip: false, - SetupConfig: func(config *config.AppConfig) { - }, - SetupRepo: func(shell *Shell) { - shell.CreateFileAndAdd("dir1/file-a", "A's content") - shell.CreateFileAndAdd("file-b", "B's content") - shell.Commit("first commit") - shell.Rename("dir1", "dir1_v2") - shell.Rename("file-b", "file-b_v2") - }, - Run: func(t *TestDriver, keys config.KeybindingConfig) { - t.Views().Files(). - IsFocused(). - Lines( - Contains("▼ dir1").IsSelected(), - Contains(" D").Contains("file-a"), - Contains("▼ dir1_v2"), - Contains(" ??").Contains("file-a"), - Contains(" D").Contains("file-b"), - Contains("??").Contains("file-b_v2"), - ). - // Select everything - Press(keys.Universal.ToggleRangeSelect). - NavigateToLine(Contains("file-b_v2")). - // Stage - PressPrimaryAction(). - Lines( - Contains("▼ dir1_v2"), - Contains(" R ").Contains("dir1/file-a → file-a"), - Contains("R ").Contains("file-b → file-b_v2").IsSelected(), - ) - }, -}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index ff2634d07..bfc0fe786 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -160,8 +160,8 @@ var tests = []*components.IntegrationTest{ file.DiscardVariousChangesRangeSelect, file.Gitignore, file.RememberCommitMessageAfterFail, + file.StageChildrenRangeSelect, file.StageRangeSelect, - file.StageRenamedRangeSelect, filter_and_search.FilterCommitFiles, filter_and_search.FilterFiles, filter_and_search.FilterFuzzy,