mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-31 23:19:40 +02:00
just disallow undo/redo while rebasing because you need more info than just the reflog
This commit is contained in:
parent
45bba0a3c5
commit
bbcc4b7b70
@ -32,11 +32,9 @@ type reflogAction struct {
|
|||||||
// Here we're going through the reflog and maintaining a counter that represents how many
|
// Here we're going through the reflog and maintaining a counter that represents how many
|
||||||
// undos/redos/user actions we've seen. when we hit a user action we call the callback specifying
|
// undos/redos/user actions we've seen. when we hit a user action we call the callback specifying
|
||||||
// what the counter is up to and the nature of the action.
|
// what the counter is up to and the nature of the action.
|
||||||
// We can't take you from a non-interactive rebase state into an interactive rebase state, so if we hit
|
// If we find ourselves mid-rebase, we just return because undo/redo mid rebase
|
||||||
// a 'finish' or an 'abort' entry, we ignore everything else until we find the corresponding 'start' entry.
|
// requires knowledge of previous TODO file states, which you can't just get from the reflog.
|
||||||
// If we find ourselves already in an interactive rebase and we've hit the start entry,
|
// Though we might support this later, hence the use of the CURRENT_REBASE action kind.
|
||||||
// we can't really do an undo because there's no way to redo back into the rebase.
|
|
||||||
// instead we just ask the user if they want to abort the rebase instead.
|
|
||||||
func (gui *Gui) parseReflogForActions(onUserAction func(counter int, action reflogAction) (bool, error)) error {
|
func (gui *Gui) parseReflogForActions(onUserAction func(counter int, action reflogAction) (bool, error)) error {
|
||||||
counter := 0
|
counter := 0
|
||||||
reflogCommits := gui.State.ReflogCommits
|
reflogCommits := gui.State.ReflogCommits
|
||||||
@ -89,6 +87,10 @@ func (gui *Gui) reflogUndo(g *gocui.Gui, v *gocui.View) error {
|
|||||||
undoEnvVars := []string{"GIT_REFLOG_ACTION=[lazygit undo]"}
|
undoEnvVars := []string{"GIT_REFLOG_ACTION=[lazygit undo]"}
|
||||||
undoingStatus := gui.Tr.SLocalize("UndoingStatus")
|
undoingStatus := gui.Tr.SLocalize("UndoingStatus")
|
||||||
|
|
||||||
|
if gui.State.WorkingTreeState == "rebasing" {
|
||||||
|
return gui.createErrorPanel(gui.g, gui.Tr.SLocalize("cantUndoWhileRebasing"))
|
||||||
|
}
|
||||||
|
|
||||||
return gui.parseReflogForActions(func(counter int, action reflogAction) (bool, error) {
|
return gui.parseReflogForActions(func(counter int, action reflogAction) (bool, error) {
|
||||||
if counter != 0 {
|
if counter != 0 {
|
||||||
return false, nil
|
return false, nil
|
||||||
@ -100,10 +102,6 @@ func (gui *Gui) reflogUndo(g *gocui.Gui, v *gocui.View) error {
|
|||||||
EnvVars: undoEnvVars,
|
EnvVars: undoEnvVars,
|
||||||
WaitingStatus: undoingStatus,
|
WaitingStatus: undoingStatus,
|
||||||
})
|
})
|
||||||
case CURRENT_REBASE:
|
|
||||||
return true, gui.createConfirmationPanel(g, v, true, gui.Tr.SLocalize("AbortRebase"), gui.Tr.SLocalize("UndoOutOfRebaseWarning"), func(g *gocui.Gui, v *gocui.View) error {
|
|
||||||
return gui.genericMergeCommand("abort")
|
|
||||||
}, nil)
|
|
||||||
case CHECKOUT:
|
case CHECKOUT:
|
||||||
return true, gui.handleCheckoutRef(action.from, handleCheckoutRefOptions{
|
return true, gui.handleCheckoutRef(action.from, handleCheckoutRefOptions{
|
||||||
EnvVars: undoEnvVars,
|
EnvVars: undoEnvVars,
|
||||||
@ -120,6 +118,10 @@ func (gui *Gui) reflogRedo(g *gocui.Gui, v *gocui.View) error {
|
|||||||
redoEnvVars := []string{"GIT_REFLOG_ACTION=[lazygit redo]"}
|
redoEnvVars := []string{"GIT_REFLOG_ACTION=[lazygit redo]"}
|
||||||
redoingStatus := gui.Tr.SLocalize("RedoingStatus")
|
redoingStatus := gui.Tr.SLocalize("RedoingStatus")
|
||||||
|
|
||||||
|
if gui.State.WorkingTreeState == "rebasing" {
|
||||||
|
return gui.createErrorPanel(gui.g, gui.Tr.SLocalize("cantRedoWhileRebasing"))
|
||||||
|
}
|
||||||
|
|
||||||
return gui.parseReflogForActions(func(counter int, action reflogAction) (bool, error) {
|
return gui.parseReflogForActions(func(counter int, action reflogAction) (bool, error) {
|
||||||
// if we're redoing and the counter is zero, we just return
|
// if we're redoing and the counter is zero, we just return
|
||||||
if counter == 0 {
|
if counter == 0 {
|
||||||
@ -134,9 +136,6 @@ func (gui *Gui) reflogRedo(g *gocui.Gui, v *gocui.View) error {
|
|||||||
EnvVars: redoEnvVars,
|
EnvVars: redoEnvVars,
|
||||||
WaitingStatus: redoingStatus,
|
WaitingStatus: redoingStatus,
|
||||||
})
|
})
|
||||||
case CURRENT_REBASE:
|
|
||||||
// no idea if this is even possible but you certainly can't redo into the end of a rebase if you're still in the rebase
|
|
||||||
return true, nil
|
|
||||||
case CHECKOUT:
|
case CHECKOUT:
|
||||||
return true, gui.handleCheckoutRef(action.to, handleCheckoutRefOptions{
|
return true, gui.handleCheckoutRef(action.to, handleCheckoutRefOptions{
|
||||||
EnvVars: redoEnvVars,
|
EnvVars: redoEnvVars,
|
||||||
|
@ -1057,11 +1057,11 @@ func addEnglish(i18nObject *i18n.Bundle) error {
|
|||||||
ID: "prevTab",
|
ID: "prevTab",
|
||||||
Other: "previous tab",
|
Other: "previous tab",
|
||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "AbortRebase",
|
ID: "cantUndoWhileRebasing",
|
||||||
Other: "Abort rebase",
|
Other: "Can't undo while rebasing",
|
||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "UndoOutOfRebaseWarning",
|
ID: "cantRedoWhileRebasing",
|
||||||
Other: "If you undo at this point, you won't be able to re-enter this rebase by pressing redo. Abort rebase?",
|
Other: "Can't redo while rebasing",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user