1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-08-09 09:22:48 +03:00

feat: Implement range stash drop

Signed-off-by: gaogao-qwq <gaogaoqwq@gmail.com>
This commit is contained in:
gaogao-qwq
2025-04-02 16:08:24 +08:00
parent cd2286276c
commit 3a03aebd89
5 changed files with 65 additions and 9 deletions

View File

@@ -50,8 +50,8 @@ func (self *StashController) GetKeybindings(opts types.KeybindingsOpts) []*types
}, },
{ {
Key: opts.GetKey(opts.Config.Universal.Remove), Key: opts.GetKey(opts.Config.Universal.Remove),
Handler: self.withItem(self.handleStashDrop), Handler: self.withItems(self.handleStashDrop),
GetDisabledReason: self.require(self.singleItemSelected()), GetDisabledReason: self.require(self.itemRangeSelected()),
Description: self.c.Tr.Drop, Description: self.c.Tr.Drop,
Tooltip: self.c.Tr.StashDropTooltip, Tooltip: self.c.Tr.StashDropTooltip,
DisplayOnScreen: true, DisplayOnScreen: true,
@@ -161,17 +161,20 @@ func (self *StashController) handleStashPop(stashEntry *models.StashEntry) error
return nil return nil
} }
func (self *StashController) handleStashDrop(stashEntry *models.StashEntry) error { func (self *StashController) handleStashDrop(stashEntries []*models.StashEntry) error {
self.c.Confirm(types.ConfirmOpts{ self.c.Confirm(types.ConfirmOpts{
Title: self.c.Tr.StashDrop, Title: self.c.Tr.StashDrop,
Prompt: self.c.Tr.SureDropStashEntry, Prompt: self.c.Tr.SureDropStashEntry,
HandleConfirm: func() error { HandleConfirm: func() error {
self.c.LogAction(self.c.Tr.Actions.Stash) self.c.LogAction(self.c.Tr.Actions.Stash)
err := self.c.Git().Stash.Drop(stashEntry.Index) startIndex := stashEntries[0].Index
for range stashEntries {
err := self.c.Git().Stash.Drop(startIndex)
_ = self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.STASH}}) _ = self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.STASH}})
if err != nil { if err != nil {
return err return err
} }
}
return nil return nil
}, },
}) })

View File

@@ -1247,7 +1247,7 @@ func EnglishTranslationSet() *TranslationSet {
StashApplyTooltip: "Apply the stash entry to your working directory.", StashApplyTooltip: "Apply the stash entry to your working directory.",
NoStashEntries: "No stash entries", NoStashEntries: "No stash entries",
StashDrop: "Stash drop", 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", StashPop: "Stash pop",
SurePopStashEntry: "Are you sure you want to pop this stash entry?", SurePopStashEntry: "Are you sure you want to pop this stash entry?",
StashApply: "Stash apply", StashApply: "Stash apply",

View File

@@ -28,7 +28,7 @@ var Drop = NewIntegrationTest(NewIntegrationTestArgs{
Tap(func() { Tap(func() {
t.ExpectPopup().Confirmation(). t.ExpectPopup().Confirmation().
Title(Equals("Stash drop")). 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() Confirm()
}). }).
IsEmpty() IsEmpty()

View File

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

View File

@@ -323,6 +323,7 @@ var tests = []*components.IntegrationTest{
stash.ApplyPatch, stash.ApplyPatch,
stash.CreateBranch, stash.CreateBranch,
stash.Drop, stash.Drop,
stash.DropMultiple,
stash.Pop, stash.Pop,
stash.PreventDiscardingFileChanges, stash.PreventDiscardingFileChanges,
stash.Rename, stash.Rename,