1
0
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:
Jesse Duffield 2024-07-06 21:26:32 +10:00 committed by GitHub
commit 34214af41f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 51 additions and 1 deletions

View File

@ -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
}
}

View 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(),
)
},
})

View File

@ -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,