mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-10-28 04:14:56 +03:00
stash controller
This commit is contained in:
@@ -1,19 +1,8 @@
|
||||
package gui
|
||||
|
||||
import (
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
)
|
||||
|
||||
// list panel functions
|
||||
|
||||
func (gui *Gui) getSelectedStashEntry() *models.StashEntry {
|
||||
return gui.State.Contexts.Stash.GetSelected()
|
||||
}
|
||||
|
||||
func (gui *Gui) stashRenderToMain() error {
|
||||
var task updateTask
|
||||
stashEntry := gui.getSelectedStashEntry()
|
||||
stashEntry := gui.State.Contexts.Stash.GetSelected()
|
||||
if stashEntry == nil {
|
||||
task = NewRenderStringTask(gui.c.Tr.NoStashEntries)
|
||||
} else {
|
||||
@@ -27,97 +16,3 @@ func (gui *Gui) stashRenderToMain() error {
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// specific functions
|
||||
|
||||
func (gui *Gui) handleStashApply() error {
|
||||
stashEntry := gui.getSelectedStashEntry()
|
||||
if stashEntry == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
apply := func() error {
|
||||
gui.c.LogAction(gui.c.Tr.Actions.Stash)
|
||||
err := gui.git.Stash.Apply(stashEntry.Index)
|
||||
_ = gui.postStashRefresh()
|
||||
if err != nil {
|
||||
return gui.c.Error(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
if gui.c.UserConfig.Gui.SkipStashWarning {
|
||||
return apply()
|
||||
}
|
||||
|
||||
return gui.c.Ask(types.AskOpts{
|
||||
Title: gui.c.Tr.StashApply,
|
||||
Prompt: gui.c.Tr.SureApplyStashEntry,
|
||||
HandleConfirm: func() error {
|
||||
return apply()
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func (gui *Gui) handleStashPop() error {
|
||||
stashEntry := gui.getSelectedStashEntry()
|
||||
if stashEntry == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
pop := func() error {
|
||||
gui.c.LogAction(gui.c.Tr.Actions.Stash)
|
||||
err := gui.git.Stash.Pop(stashEntry.Index)
|
||||
_ = gui.postStashRefresh()
|
||||
if err != nil {
|
||||
return gui.c.Error(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
if gui.c.UserConfig.Gui.SkipStashWarning {
|
||||
return pop()
|
||||
}
|
||||
|
||||
return gui.c.Ask(types.AskOpts{
|
||||
Title: gui.c.Tr.StashPop,
|
||||
Prompt: gui.c.Tr.SurePopStashEntry,
|
||||
HandleConfirm: func() error {
|
||||
return pop()
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func (gui *Gui) handleStashDrop() error {
|
||||
stashEntry := gui.getSelectedStashEntry()
|
||||
if stashEntry == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return gui.c.Ask(types.AskOpts{
|
||||
Title: gui.c.Tr.StashDrop,
|
||||
Prompt: gui.c.Tr.SureDropStashEntry,
|
||||
HandleConfirm: func() error {
|
||||
gui.c.LogAction(gui.c.Tr.Actions.Stash)
|
||||
err := gui.git.Stash.Drop(stashEntry.Index)
|
||||
_ = gui.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.STASH}})
|
||||
if err != nil {
|
||||
return gui.c.Error(err)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func (gui *Gui) postStashRefresh() error {
|
||||
return gui.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.STASH, types.FILES}})
|
||||
}
|
||||
|
||||
func (gui *Gui) handleNewBranchOffStashEntry() error {
|
||||
stashEntry := gui.getSelectedStashEntry()
|
||||
if stashEntry == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return gui.helpers.Refs.NewBranch(stashEntry.RefName(), stashEntry.Description(), "")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user