summaryrefslogtreecommitdiffstats
path: root/pkg/gui
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2021-11-01 08:58:58 +1100
committerJesse Duffield <jessedduffield@gmail.com>2021-11-01 09:18:30 +1100
commit927ee631061fbc3c86c4d73ac5056d8b4bd84c81 (patch)
tree71ebb9353e9e085a91c529c90b0308bec4e645fb /pkg/gui
parent9989c96321685ac3493642fb8e1fa511896175e3 (diff)
support aborting a merge or rebase with esc
Diffstat (limited to 'pkg/gui')
-rw-r--r--pkg/gui/merge_panel.go2
-rw-r--r--pkg/gui/modes.go15
-rw-r--r--pkg/gui/rebase_options_panel.go44
3 files changed, 54 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"
+ }
+}