diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2021-11-01 08:58:58 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2021-11-01 09:18:30 +1100 |
commit | 927ee631061fbc3c86c4d73ac5056d8b4bd84c81 (patch) | |
tree | 71ebb9353e9e085a91c529c90b0308bec4e645fb | |
parent | 9989c96321685ac3493642fb8e1fa511896175e3 (diff) |
support aborting a merge or rebase with esc
-rw-r--r-- | pkg/gui/merge_panel.go | 2 | ||||
-rw-r--r-- | pkg/gui/modes.go | 15 | ||||
-rw-r--r-- | pkg/gui/rebase_options_panel.go | 44 | ||||
-rw-r--r-- | pkg/i18n/english.go | 4 |
4 files changed, 58 insertions, 7 deletions
diff --git a/pkg/gui/merge_panel.go b/pkg/gui/merge_panel.go index 9fcd475c8..c0c55de6c 100644 --- a/pkg/gui/merge_panel.go +++ b/pkg/gui/merge_panel.go @@ -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) diff --git a/pkg/gui/modes.go b/pkg/gui/modes.go index af8977989..92b7d3171 100644 --- a/pkg/gui/modes.go +++ b/pkg/gui/modes.go @@ -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, + }, } } diff --git a/pkg/gui/rebase_options_panel.go b/pkg/gui/rebase_options_panel.go index d554bc746..280022000 100644 --- a/pkg/gui/rebase_options_panel.go +++ b/pkg/gui/rebase_options_panel.go @@ -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" + } +} diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index ae5fab1b3..8f39948a0 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -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", |