1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-09-16 09:16:26 +02:00

feat: add rename stash

This commit is contained in:
Ryooooooga
2022-10-14 22:19:53 +09:00
parent 8f3ccd07db
commit 11316b7a48
17 changed files with 132 additions and 7 deletions

View File

@@ -1,9 +1,12 @@
package controllers
import (
"regexp"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/utils"
)
type StashController struct {
@@ -44,6 +47,11 @@ func (self *StashController) GetKeybindings(opts types.KeybindingsOpts) []*types
Handler: self.checkSelected(self.handleNewBranchOffStashEntry),
Description: self.c.Tr.LcNewBranch,
},
{
Key: opts.GetKey(opts.Config.Stash.RenameStash),
Handler: self.checkSelected(self.handleRenameStashEntry),
Description: self.c.Tr.LcRenameStash,
},
}
return bindings
@@ -122,7 +130,7 @@ func (self *StashController) handleStashDrop(stashEntry *models.StashEntry) erro
Prompt: self.c.Tr.SureDropStashEntry,
HandleConfirm: func() error {
self.c.LogAction(self.c.Tr.Actions.Stash)
err := self.git.Stash.Drop(stashEntry.Index)
_, err := self.git.Stash.Drop(stashEntry.Index)
_ = self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.STASH}})
if err != nil {
return self.c.Error(err)
@@ -139,3 +147,38 @@ func (self *StashController) postStashRefresh() error {
func (self *StashController) handleNewBranchOffStashEntry(stashEntry *models.StashEntry) error {
return self.helpers.Refs.NewBranch(stashEntry.RefName(), stashEntry.Description(), "")
}
func (self *StashController) handleRenameStashEntry(stashEntry *models.StashEntry) error {
message := utils.ResolvePlaceholderString(
self.c.Tr.RenameStashPrompt,
map[string]string{
"stashName": stashEntry.RefName(),
},
)
return self.c.Prompt(types.PromptOpts{
Title: message,
InitialContent: stashEntry.Name,
HandleConfirm: func(response string) error {
self.c.LogAction(self.c.Tr.Actions.RenameStash)
output, err := self.git.Stash.Drop(stashEntry.Index)
if err != nil {
return err
}
stashShaPattern := regexp.MustCompile(`\(([0-9a-f]+)\)`)
matches := stashShaPattern.FindStringSubmatch(output)
stashSha := ""
if len(matches) > 1 {
stashSha = matches[1]
}
err = self.git.Stash.Store(stashSha, response)
_ = self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.STASH}})
if err != nil {
return err
}
return nil
},
})
}