Skip to content

Commit 2b60f83

Browse files
stefanhallerkarolzwolak
authored andcommitted
Fix dropping range selection of filtered stashes (jesseduffield#4849)
### PR Description When filtering by file path, dropping a range selection of stashes would drop the wrong ones if those stashes would be noncontiguous in the unfiltered list.
2 parents 4d28385 + e593055 commit 2b60f83

File tree

4 files changed

+74
-4
lines changed

4 files changed

+74
-4
lines changed

pkg/gui/controllers/stash_controller.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,8 @@ func (self *StashController) handleStashDrop(stashEntries []*models.StashEntry)
161161
Prompt: self.c.Tr.SureDropStashEntry,
162162
HandleConfirm: func() error {
163163
self.c.LogAction(self.c.Tr.Actions.Stash)
164-
startIndex := stashEntries[0].Index
165-
for range stashEntries {
166-
err := self.c.Git().Stash.Drop(startIndex)
164+
for i := len(stashEntries) - 1; i >= 0; i-- {
165+
err := self.c.Git().Stash.Drop(stashEntries[i].Index)
167166
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.STASH}})
168167
if err != nil {
169168
return err

pkg/integration/tests/stash/drop_multiple.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ var DropMultiple = NewIntegrationTest(NewIntegrationTestArgs{
3333
Contains("stash two"),
3434
Contains("stash one"),
3535
).
36-
Press(keys.Universal.ToggleRangeSelect).
3736
Press(keys.Universal.RangeSelectDown).
3837
Press(keys.Universal.Remove).
3938
Tap(func() {
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package stash
2+
3+
import (
4+
"github.com/jesseduffield/lazygit/pkg/config"
5+
. "github.com/jesseduffield/lazygit/pkg/integration/components"
6+
)
7+
8+
var DropMultipleInFilteredMode = NewIntegrationTest(NewIntegrationTestArgs{
9+
Description: "Drop multiple stash entries when filtering by path",
10+
ExtraCmdArgs: []string{},
11+
Skip: false,
12+
SetupConfig: func(config *config.AppConfig) {},
13+
SetupRepo: func(shell *Shell) {
14+
shell.EmptyCommit("initial commit")
15+
shell.CreateFileAndAdd("file1", "content1")
16+
shell.Stash("stash one")
17+
shell.CreateFileAndAdd("file2", "content2a")
18+
shell.Stash("stash two-a")
19+
shell.CreateFileAndAdd("file3", "content3")
20+
shell.Stash("stash three")
21+
shell.CreateFileAndAdd("file2", "content2b")
22+
shell.Stash("stash two-b")
23+
shell.CreateFileAndAdd("file4", "content4")
24+
shell.Stash("stash four")
25+
},
26+
Run: func(t *TestDriver, keys config.KeybindingConfig) {
27+
t.Views().Stash().
28+
Lines(
29+
Contains("stash four"),
30+
Contains("stash two-b"),
31+
Contains("stash three"),
32+
Contains("stash two-a"),
33+
Contains("stash one"),
34+
)
35+
36+
t.GlobalPress(keys.Universal.FilteringMenu)
37+
t.ExpectPopup().Menu().
38+
Title(Equals("Filtering")).
39+
Select(Contains("Enter path to filter by")).
40+
Confirm()
41+
42+
t.ExpectPopup().Prompt().
43+
Title(Equals("Enter path:")).
44+
Type("file2").
45+
Confirm()
46+
47+
t.Views().Stash().
48+
Focus().
49+
Lines(
50+
Contains("stash two-b").IsSelected(),
51+
Contains("stash two-a"),
52+
).
53+
Press(keys.Universal.RangeSelectDown).
54+
Press(keys.Universal.Remove).
55+
Tap(func() {
56+
t.ExpectPopup().Confirmation().
57+
Title(Equals("Stash drop")).
58+
Content(Contains("Are you sure you want to drop the selected stash entry(ies)?")).
59+
Confirm()
60+
}).
61+
IsEmpty()
62+
63+
t.GlobalPress(keys.Universal.Return) // cancel filtering mode
64+
t.Views().Stash().
65+
Lines(
66+
Contains("stash four"),
67+
Contains("stash three"),
68+
Contains("stash one"),
69+
)
70+
},
71+
})

pkg/integration/tests/test_list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ var tests = []*components.IntegrationTest{
358358
stash.CreateBranch,
359359
stash.Drop,
360360
stash.DropMultiple,
361+
stash.DropMultipleInFilteredMode,
361362
stash.FilterByPath,
362363
stash.Pop,
363364
stash.PreventDiscardingFileChanges,

0 commit comments

Comments
 (0)