Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pkg/gui/controllers/files_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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+"/") {

@brandondong brandondong May 25, 2024 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on Windows, path names will similarly use / instead of \.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To recap the logic here for posterity:

  • the first part which checks if the selected node is a file is there to ensure that if you have a file named 'a' and a file named 'aa', that the latter is not considered a descendant of the former. In short: if you're a file, it's not possible to have descendants so we can early exit
  • The second part is for when you have one directory named 'a' and another named 'aa', using the same logic as above.

Is that right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes!

return true
}
}
Expand Down
45 changes: 45 additions & 0 deletions pkg/integration/tests/file/stage_children_range_select.go
Original file line number Diff line number Diff line change
@@ -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(),
)
},
})
1 change: 1 addition & 0 deletions pkg/integration/tests/test_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ var tests = []*components.IntegrationTest{
file.DiscardVariousChangesRangeSelect,
file.Gitignore,
file.RememberCommitMessageAfterFail,
file.StageChildrenRangeSelect,
file.StageRangeSelect,
filter_and_search.FilterCommitFiles,
filter_and_search.FilterFiles,
Expand Down