From bf419abb8efa55bf3a4455cd5342f811e0e62384 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Mon, 25 Aug 2025 18:41:06 +0200 Subject: [PATCH] Fix dropping a range of stashes in filtered mode To fix the problem described in the previous commit, iterate backwards over the stashes that we want to delete. This allows us to use their Index field. --- pkg/gui/controllers/stash_controller.go | 5 ++--- .../tests/stash/drop_multiple_in_filtered_mode.go | 10 ---------- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/pkg/gui/controllers/stash_controller.go b/pkg/gui/controllers/stash_controller.go index c9a938bb5..6af074386 100644 --- a/pkg/gui/controllers/stash_controller.go +++ b/pkg/gui/controllers/stash_controller.go @@ -161,9 +161,8 @@ func (self *StashController) handleStashDrop(stashEntries []*models.StashEntry) Prompt: self.c.Tr.SureDropStashEntry, HandleConfirm: func() error { self.c.LogAction(self.c.Tr.Actions.Stash) - startIndex := stashEntries[0].Index - for range stashEntries { - err := self.c.Git().Stash.Drop(startIndex) + for i := len(stashEntries) - 1; i >= 0; i-- { + err := self.c.Git().Stash.Drop(stashEntries[i].Index) self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.STASH}}) if err != nil { return err diff --git a/pkg/integration/tests/stash/drop_multiple_in_filtered_mode.go b/pkg/integration/tests/stash/drop_multiple_in_filtered_mode.go index c7dc9ee32..b4a6e1c5d 100644 --- a/pkg/integration/tests/stash/drop_multiple_in_filtered_mode.go +++ b/pkg/integration/tests/stash/drop_multiple_in_filtered_mode.go @@ -58,24 +58,14 @@ var DropMultipleInFilteredMode = NewIntegrationTest(NewIntegrationTestArgs{ Content(Contains("Are you sure you want to drop the selected stash entry(ies)?")). Confirm() }). - /* EXPECTED: IsEmpty() - ACTUAL: */ - Lines( - Contains("stash two-a"), - ) t.GlobalPress(keys.Universal.Return) // cancel filtering mode t.Views().Stash(). Lines( - /* EXPECTED: Contains("stash four"), Contains("stash three"), Contains("stash one"), - ACTUAL: */ - Contains("stash four"), - Contains("stash two-a"), - Contains("stash one"), ) }, })