mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-29 23:17:32 +02:00
Fix multi selection stage/discard not working for files with substrings (#3599)
- **PR Description** I found an issue with multi selection stage/discard. Here is a minimal repro: ```bash git init touch a touch aa lazygit ``` Select both files using shift and hit space. Only `a` is staged. - **Please check if the PR fulfills these requirements** * [ ] Cheatsheets are up-to-date (run `go generate ./...`) * [x] Code has been formatted (see [here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#code-formatting)) * [x] Tests have been added/updated (see [here](https://github.com/jesseduffield/lazygit/blob/master/pkg/integration/README.md) for the integration test guide) * [ ] Text is internationalised (see [here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#internationalisation)) * [ ] Docs have been updated if necessary * [x] You've read through your own file changes for silly mistakes etc <!-- Be sure to name your PR with an imperative e.g. 'Add worktrees view' see https://github.com/jesseduffield/lazygit/releases/tag/v0.40.0 for examples -->
This commit is contained in:
commit
34214af41f
@ -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
|
||||
}
|
||||
}
|
||||
|
45
pkg/integration/tests/file/stage_children_range_select.go
Normal file
45
pkg/integration/tests/file/stage_children_range_select.go
Normal file
@ -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(),
|
||||
)
|
||||
},
|
||||
})
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user