mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-02-03 13:21:56 +02:00
support aborting a merge or rebase with esc
This commit is contained in:
parent
9989c96321
commit
927ee63106
@ -285,7 +285,7 @@ func (gui *Gui) promptToContinueRebase() error {
|
||||
return err
|
||||
}
|
||||
|
||||
return gui.genericMergeCommand("continue")
|
||||
return gui.genericMergeCommand(REBASE_OPTION_CONTINUE)
|
||||
},
|
||||
handleClose: func() error {
|
||||
return gui.pushContext(gui.State.Contexts.Files)
|
||||
|
@ -1,6 +1,7 @@
|
||||
package gui
|
||||
|
||||
import (
|
||||
"github.com/jesseduffield/lazygit/pkg/commands"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
||||
)
|
||||
|
||||
@ -58,5 +59,19 @@ func (gui *Gui) modeStatuses() []modeStatus {
|
||||
},
|
||||
reset: gui.exitCherryPickingMode,
|
||||
},
|
||||
{
|
||||
isActive: func() bool {
|
||||
return gui.GitCommand.WorkingTreeState() != commands.REBASE_MODE_NORMAL
|
||||
},
|
||||
description: func() string {
|
||||
workingTreeState := gui.GitCommand.WorkingTreeState()
|
||||
return style.FgYellow.Sprintf(
|
||||
"%s %s",
|
||||
workingTreeState,
|
||||
style.AttrUnderline.Sprint(gui.Tr.ResetInParentheses),
|
||||
)
|
||||
},
|
||||
reset: gui.abortMergeOrRebaseWithConfirm,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -7,11 +7,19 @@ import (
|
||||
"github.com/jesseduffield/lazygit/pkg/commands"
|
||||
)
|
||||
|
||||
type RebaseOption string
|
||||
|
||||
const (
|
||||
REBASE_OPTION_CONTINUE = "continue"
|
||||
REBASE_OPTION_ABORT = "abort"
|
||||
REBASE_OPTION_SKIP = "skip"
|
||||
)
|
||||
|
||||
func (gui *Gui) handleCreateRebaseOptionsMenu() error {
|
||||
options := []string{"continue", "abort"}
|
||||
options := []string{REBASE_OPTION_CONTINUE, REBASE_OPTION_ABORT}
|
||||
|
||||
if gui.GitCommand.WorkingTreeState() == commands.REBASE_MODE_REBASING {
|
||||
options = append(options, "skip")
|
||||
options = append(options, REBASE_OPTION_SKIP)
|
||||
}
|
||||
|
||||
menuItems := make([]*menuItem, len(options))
|
||||
@ -49,7 +57,7 @@ func (gui *Gui) genericMergeCommand(command string) error {
|
||||
// we should end up with a command like 'git merge --continue'
|
||||
|
||||
// it's impossible for a rebase to require a commit so we'll use a subprocess only if it's a merge
|
||||
if status == commands.REBASE_MODE_MERGING && command != "abort" && gui.Config.GetUserConfig().Git.Merging.ManualCommit {
|
||||
if status == commands.REBASE_MODE_MERGING && command != REBASE_OPTION_ABORT && gui.Config.GetUserConfig().Git.Merging.ManualCommit {
|
||||
sub := gitCommand.OSCommand.PrepareSubProcess("git", commandType, fmt.Sprintf("--%s", command))
|
||||
if sub != nil {
|
||||
return gui.runSubprocessWithSuspenseAndRefresh(sub)
|
||||
@ -87,9 +95,9 @@ func (gui *Gui) handleGenericMergeCommandResult(result error) error {
|
||||
if result == nil {
|
||||
return nil
|
||||
} else if strings.Contains(result.Error(), "No changes - did you forget to use") {
|
||||
return gui.genericMergeCommand("skip")
|
||||
return gui.genericMergeCommand(REBASE_OPTION_SKIP)
|
||||
} else if strings.Contains(result.Error(), "The previous cherry-pick is now empty") {
|
||||
return gui.genericMergeCommand("continue")
|
||||
return gui.genericMergeCommand(REBASE_OPTION_CONTINUE)
|
||||
} else if strings.Contains(result.Error(), "No rebase in progress?") {
|
||||
// assume in this case that we're already done
|
||||
return nil
|
||||
@ -106,10 +114,34 @@ func (gui *Gui) handleGenericMergeCommandResult(result error) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return gui.genericMergeCommand("abort")
|
||||
return gui.genericMergeCommand(REBASE_OPTION_ABORT)
|
||||
},
|
||||
})
|
||||
} else {
|
||||
return gui.createErrorPanel(result.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func (gui *Gui) abortMergeOrRebaseWithConfirm() error {
|
||||
// prompt user to confirm that they want to abort, then do it
|
||||
mode := gui.workingTreeStateNoun()
|
||||
return gui.ask(askOpts{
|
||||
title: fmt.Sprintf(gui.Tr.AbortTitle, mode),
|
||||
prompt: fmt.Sprintf(gui.Tr.AbortPrompt, mode),
|
||||
handleConfirm: func() error {
|
||||
return gui.genericMergeCommand(REBASE_OPTION_ABORT)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func (gui *Gui) workingTreeStateNoun() string {
|
||||
workingTreeState := gui.GitCommand.WorkingTreeState()
|
||||
switch workingTreeState {
|
||||
case commands.REBASE_MODE_NORMAL:
|
||||
return ""
|
||||
case commands.REBASE_MODE_MERGING:
|
||||
return "merge"
|
||||
default:
|
||||
return "rebase"
|
||||
}
|
||||
}
|
||||
|
@ -436,6 +436,8 @@ type TranslationSet struct {
|
||||
MustSpecifyOriginError string
|
||||
GitOutput string
|
||||
GitCommandFailed string
|
||||
AbortTitle string
|
||||
AbortPrompt string
|
||||
Spans Spans
|
||||
}
|
||||
|
||||
@ -965,6 +967,8 @@ func englishTranslationSet() TranslationSet {
|
||||
MustSpecifyOriginError: "Must specify a remote if specifying a branch",
|
||||
GitOutput: "Git output:",
|
||||
GitCommandFailed: "Git command failed. Check command log for details (open with %s)",
|
||||
AbortTitle: "Abort %s",
|
||||
AbortPrompt: "Are you sure you want to abort the current %s?",
|
||||
Spans: Spans{
|
||||
// TODO: combine this with the original keybinding descriptions (those are all in lowercase atm)
|
||||
CheckoutCommit: "Checkout commit",
|
||||
|
Loading…
x
Reference in New Issue
Block a user