1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-31 14:24:25 +03:00

add confirmation before performing undo or redo action

This commit is contained in:
Jesse Duffield
2022-03-24 09:25:51 +11:00
parent 12ecd665c8
commit f113ff21bf
2 changed files with 48 additions and 17 deletions

View File

@ -1,6 +1,8 @@
package controllers package controllers
import ( import (
"fmt"
"github.com/jesseduffield/lazygit/pkg/commands/types/enums" "github.com/jesseduffield/lazygit/pkg/commands/types/enums"
"github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/utils" "github.com/jesseduffield/lazygit/pkg/utils"
@ -83,17 +85,30 @@ func (self *UndoController) reflogUndo() error {
switch action.kind { switch action.kind {
case COMMIT, REBASE: case COMMIT, REBASE:
self.c.LogAction(self.c.Tr.Actions.Undo) return true, self.c.Ask(types.AskOpts{
return true, self.hardResetWithAutoStash(action.from, hardResetOptions{ Title: self.c.Tr.Actions.Undo,
EnvVars: undoEnvVars, Prompt: fmt.Sprintf(self.c.Tr.HardResetAutostashPrompt, action.from),
WaitingStatus: undoingStatus, HandleConfirm: func() error {
self.c.LogAction(self.c.Tr.Actions.Undo)
return self.hardResetWithAutoStash(action.from, hardResetOptions{
EnvVars: undoEnvVars,
WaitingStatus: undoingStatus,
})
},
}) })
case CHECKOUT: case CHECKOUT:
self.c.LogAction(self.c.Tr.Actions.Undo) return true, self.c.Ask(types.AskOpts{
return true, self.helpers.Refs.CheckoutRef(action.from, types.CheckoutRefOptions{ Title: self.c.Tr.Actions.Undo,
EnvVars: undoEnvVars, Prompt: fmt.Sprintf(self.c.Tr.CheckoutPrompt, action.from),
WaitingStatus: undoingStatus, HandleConfirm: func() error {
self.c.LogAction(self.c.Tr.Actions.Undo)
return self.helpers.Refs.CheckoutRef(action.from, types.CheckoutRefOptions{
EnvVars: undoEnvVars,
WaitingStatus: undoingStatus,
})
},
}) })
case CURRENT_REBASE: case CURRENT_REBASE:
// do nothing // do nothing
} }
@ -121,16 +136,29 @@ func (self *UndoController) reflogRedo() error {
switch action.kind { switch action.kind {
case COMMIT, REBASE: case COMMIT, REBASE:
self.c.LogAction(self.c.Tr.Actions.Redo) return true, self.c.Ask(types.AskOpts{
return true, self.hardResetWithAutoStash(action.to, hardResetOptions{ Title: self.c.Tr.Actions.Redo,
EnvVars: redoEnvVars, Prompt: fmt.Sprintf(self.c.Tr.HardResetAutostashPrompt, action.to),
WaitingStatus: redoingStatus, HandleConfirm: func() error {
self.c.LogAction(self.c.Tr.Actions.Redo)
return self.hardResetWithAutoStash(action.to, hardResetOptions{
EnvVars: redoEnvVars,
WaitingStatus: redoingStatus,
})
},
}) })
case CHECKOUT: case CHECKOUT:
self.c.LogAction(self.c.Tr.Actions.Redo) return true, self.c.Ask(types.AskOpts{
return true, self.helpers.Refs.CheckoutRef(action.to, types.CheckoutRefOptions{ Title: self.c.Tr.Actions.Redo,
EnvVars: redoEnvVars, Prompt: fmt.Sprintf(self.c.Tr.CheckoutPrompt, action.to),
WaitingStatus: redoingStatus, HandleConfirm: func() error {
self.c.LogAction(self.c.Tr.Actions.Redo)
return self.helpers.Refs.CheckoutRef(action.to, types.CheckoutRefOptions{
EnvVars: redoEnvVars,
WaitingStatus: redoingStatus,
})
},
}) })
case CURRENT_REBASE: case CURRENT_REBASE:
// do nothing // do nothing

View File

@ -456,6 +456,8 @@ type TranslationSet struct {
ConfirmRevertCommit string ConfirmRevertCommit string
RewordInEditorTitle string RewordInEditorTitle string
RewordInEditorPrompt string RewordInEditorPrompt string
CheckoutPrompt string
HardResetAutostashPrompt string
Actions Actions Actions Actions
Bisect Bisect Bisect Bisect
} }
@ -1031,7 +1033,8 @@ func EnglishTranslationSet() TranslationSet {
ConfirmRevertCommit: "Are you sure you want to revert {{.selectedCommit}}?", ConfirmRevertCommit: "Are you sure you want to revert {{.selectedCommit}}?",
RewordInEditorTitle: "Reword in editor", RewordInEditorTitle: "Reword in editor",
RewordInEditorPrompt: "Are you sure you want to reword this commit in your editor?", RewordInEditorPrompt: "Are you sure you want to reword this commit in your editor?",
HardResetAutostashPrompt: "Are you sure you want to hard reset to '%s'? An auto-stash will be performed if necessary.",
CheckoutPrompt: "Are you sure you want to checkout '%s'?",
Actions: Actions{ Actions: Actions{
// TODO: combine this with the original keybinding descriptions (those are all in lowercase atm) // TODO: combine this with the original keybinding descriptions (those are all in lowercase atm)
CheckoutCommit: "Checkout commit", CheckoutCommit: "Checkout commit",