Skip to content

Commit facc73a

Browse files
authored
Allow range drop stashes (#4451)
- **PR Description** This pr implement dropping multiple stashes feature. In #3196, dropping multiple stashes feature is listed as possible but less needed. In practice, I tend to use `apply` instead of `drop` in order to retrieve some temporary changes in the near future, but the consequence of this is that at the end of the work week I often have to go back and manually clean up stashes that I no longer need or that I simply forgot to drop. - **Please check if the PR fulfills these requirements** * [x] 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)) * [ ] If a new UserConfig entry was added, make sure it can be hot-reloaded (see [here](https://github.com/jesseduffield/lazygit/blob/master/docs/dev/Codebase_Guide.md#using-userconfig)) * [ ] Docs have been updated if necessary * [x] You've read through your own file changes for silly mistakes etc
2 parents cd22862 + 3a03aeb commit facc73a

File tree

5 files changed

+65
-9
lines changed

5 files changed

+65
-9
lines changed

pkg/gui/controllers/stash_controller.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ func (self *StashController) GetKeybindings(opts types.KeybindingsOpts) []*types
5050
},
5151
{
5252
Key: opts.GetKey(opts.Config.Universal.Remove),
53-
Handler: self.withItem(self.handleStashDrop),
54-
GetDisabledReason: self.require(self.singleItemSelected()),
53+
Handler: self.withItems(self.handleStashDrop),
54+
GetDisabledReason: self.require(self.itemRangeSelected()),
5555
Description: self.c.Tr.Drop,
5656
Tooltip: self.c.Tr.StashDropTooltip,
5757
DisplayOnScreen: true,
@@ -161,16 +161,19 @@ func (self *StashController) handleStashPop(stashEntry *models.StashEntry) error
161161
return nil
162162
}
163163

164-
func (self *StashController) handleStashDrop(stashEntry *models.StashEntry) error {
164+
func (self *StashController) handleStashDrop(stashEntries []*models.StashEntry) error {
165165
self.c.Confirm(types.ConfirmOpts{
166166
Title: self.c.Tr.StashDrop,
167167
Prompt: self.c.Tr.SureDropStashEntry,
168168
HandleConfirm: func() error {
169169
self.c.LogAction(self.c.Tr.Actions.Stash)
170-
err := self.c.Git().Stash.Drop(stashEntry.Index)
171-
_ = self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.STASH}})
172-
if err != nil {
173-
return err
170+
startIndex := stashEntries[0].Index
171+
for range stashEntries {
172+
err := self.c.Git().Stash.Drop(startIndex)
173+
_ = self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.STASH}})
174+
if err != nil {
175+
return err
176+
}
174177
}
175178
return nil
176179
},

pkg/i18n/english.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1247,7 +1247,7 @@ func EnglishTranslationSet() *TranslationSet {
12471247
StashApplyTooltip: "Apply the stash entry to your working directory.",
12481248
NoStashEntries: "No stash entries",
12491249
StashDrop: "Stash drop",
1250-
SureDropStashEntry: "Are you sure you want to drop this stash entry?",
1250+
SureDropStashEntry: "Are you sure you want to drop the selected stash entry(ies)?",
12511251
StashPop: "Stash pop",
12521252
SurePopStashEntry: "Are you sure you want to pop this stash entry?",
12531253
StashApply: "Stash apply",

pkg/integration/tests/stash/drop.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var Drop = NewIntegrationTest(NewIntegrationTestArgs{
2828
Tap(func() {
2929
t.ExpectPopup().Confirmation().
3030
Title(Equals("Stash drop")).
31-
Content(Contains("Are you sure you want to drop this stash entry?")).
31+
Content(Contains("Are you sure you want to drop the selected stash entry(ies)?")).
3232
Confirm()
3333
}).
3434
IsEmpty()
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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 DropMultiple = NewIntegrationTest(NewIntegrationTestArgs{
9+
Description: "Drop multiple stash entries",
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", "content2")
18+
shell.Stash("stash two")
19+
shell.CreateFileAndAdd("file3", "content3")
20+
shell.Stash("stash three")
21+
shell.CreateFileAndAdd("file4", "content4")
22+
shell.Stash("stash four")
23+
},
24+
Run: func(t *TestDriver, keys config.KeybindingConfig) {
25+
t.Views().Files().IsEmpty()
26+
27+
t.Views().Stash().
28+
Focus().
29+
SelectNextItem().
30+
Lines(
31+
Contains("stash four"),
32+
Contains("stash three").IsSelected(),
33+
Contains("stash two"),
34+
Contains("stash one"),
35+
).
36+
Press(keys.Universal.ToggleRangeSelect).
37+
Press(keys.Universal.RangeSelectDown).
38+
Press(keys.Universal.Remove).
39+
Tap(func() {
40+
t.ExpectPopup().Confirmation().
41+
Title(Equals("Stash drop")).
42+
Content(Contains("Are you sure you want to drop the selected stash entry(ies)?")).
43+
Confirm()
44+
}).
45+
Lines(
46+
Contains("stash four"),
47+
Contains("stash one"),
48+
)
49+
50+
t.Views().Files().IsEmpty()
51+
},
52+
})

pkg/integration/tests/test_list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ var tests = []*components.IntegrationTest{
323323
stash.ApplyPatch,
324324
stash.CreateBranch,
325325
stash.Drop,
326+
stash.DropMultiple,
326327
stash.Pop,
327328
stash.PreventDiscardingFileChanges,
328329
stash.Rename,

0 commit comments

Comments
 (0)