From 3a03aebd89f05a26284d882cee8e7c0d13b383d2 Mon Sep 17 00:00:00 2001 From: gaogao-qwq Date: Wed, 2 Apr 2025 16:08:24 +0800 Subject: [PATCH] feat: Implement range stash drop Signed-off-by: gaogao-qwq --- pkg/gui/controllers/stash_controller.go | 17 ++++--- pkg/i18n/english.go | 2 +- pkg/integration/tests/stash/drop.go | 2 +- pkg/integration/tests/stash/drop_multiple.go | 52 ++++++++++++++++++++ pkg/integration/tests/test_list.go | 1 + 5 files changed, 65 insertions(+), 9 deletions(-) create mode 100644 pkg/integration/tests/stash/drop_multiple.go diff --git a/pkg/gui/controllers/stash_controller.go b/pkg/gui/controllers/stash_controller.go index 002c68b3d..6b88e6849 100644 --- a/pkg/gui/controllers/stash_controller.go +++ b/pkg/gui/controllers/stash_controller.go @@ -50,8 +50,8 @@ func (self *StashController) GetKeybindings(opts types.KeybindingsOpts) []*types }, { Key: opts.GetKey(opts.Config.Universal.Remove), - Handler: self.withItem(self.handleStashDrop), - GetDisabledReason: self.require(self.singleItemSelected()), + Handler: self.withItems(self.handleStashDrop), + GetDisabledReason: self.require(self.itemRangeSelected()), Description: self.c.Tr.Drop, Tooltip: self.c.Tr.StashDropTooltip, DisplayOnScreen: true, @@ -161,16 +161,19 @@ func (self *StashController) handleStashPop(stashEntry *models.StashEntry) error return nil } -func (self *StashController) handleStashDrop(stashEntry *models.StashEntry) error { +func (self *StashController) handleStashDrop(stashEntries []*models.StashEntry) error { self.c.Confirm(types.ConfirmOpts{ Title: self.c.Tr.StashDrop, Prompt: self.c.Tr.SureDropStashEntry, HandleConfirm: func() error { self.c.LogAction(self.c.Tr.Actions.Stash) - err := self.c.Git().Stash.Drop(stashEntry.Index) - _ = self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.STASH}}) - if err != nil { - return err + startIndex := stashEntries[0].Index + for range stashEntries { + err := self.c.Git().Stash.Drop(startIndex) + _ = self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.STASH}}) + if err != nil { + return err + } } return nil }, diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 73571d7ee..2ca489d7e 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -1247,7 +1247,7 @@ func EnglishTranslationSet() *TranslationSet { StashApplyTooltip: "Apply the stash entry to your working directory.", NoStashEntries: "No stash entries", StashDrop: "Stash drop", - SureDropStashEntry: "Are you sure you want to drop this stash entry?", + SureDropStashEntry: "Are you sure you want to drop the selected stash entry(ies)?", StashPop: "Stash pop", SurePopStashEntry: "Are you sure you want to pop this stash entry?", StashApply: "Stash apply", diff --git a/pkg/integration/tests/stash/drop.go b/pkg/integration/tests/stash/drop.go index af749bc3d..4dd9310a5 100644 --- a/pkg/integration/tests/stash/drop.go +++ b/pkg/integration/tests/stash/drop.go @@ -28,7 +28,7 @@ var Drop = NewIntegrationTest(NewIntegrationTestArgs{ Tap(func() { t.ExpectPopup().Confirmation(). Title(Equals("Stash drop")). - Content(Contains("Are you sure you want to drop this stash entry?")). + Content(Contains("Are you sure you want to drop the selected stash entry(ies)?")). Confirm() }). IsEmpty() diff --git a/pkg/integration/tests/stash/drop_multiple.go b/pkg/integration/tests/stash/drop_multiple.go new file mode 100644 index 000000000..7d6ab2a63 --- /dev/null +++ b/pkg/integration/tests/stash/drop_multiple.go @@ -0,0 +1,52 @@ +package stash + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var DropMultiple = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Drop multiple stash entries", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + shell.EmptyCommit("initial commit") + shell.CreateFileAndAdd("file1", "content1") + shell.Stash("stash one") + shell.CreateFileAndAdd("file2", "content2") + shell.Stash("stash two") + shell.CreateFileAndAdd("file3", "content3") + shell.Stash("stash three") + shell.CreateFileAndAdd("file4", "content4") + shell.Stash("stash four") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Files().IsEmpty() + + t.Views().Stash(). + Focus(). + SelectNextItem(). + Lines( + Contains("stash four"), + Contains("stash three").IsSelected(), + Contains("stash two"), + Contains("stash one"), + ). + Press(keys.Universal.ToggleRangeSelect). + Press(keys.Universal.RangeSelectDown). + Press(keys.Universal.Remove). + Tap(func() { + t.ExpectPopup().Confirmation(). + Title(Equals("Stash drop")). + Content(Contains("Are you sure you want to drop the selected stash entry(ies)?")). + Confirm() + }). + Lines( + Contains("stash four"), + Contains("stash one"), + ) + + t.Views().Files().IsEmpty() + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index b7e204fd2..210ae2852 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -323,6 +323,7 @@ var tests = []*components.IntegrationTest{ stash.ApplyPatch, stash.CreateBranch, stash.Drop, + stash.DropMultiple, stash.Pop, stash.PreventDiscardingFileChanges, stash.Rename,