diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-01-12 15:02:00 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-01-29 18:19:11 +1100 |
commit | b64953ebdb7ea4bd535ebd09f8387f1ff2e71114 (patch) | |
tree | e36b566e562cb09e070a49f52cc885a7ac5b6906 | |
parent | deaa2bcb1564ab27146dc1f9164ec990b9a6dc53 (diff) |
safely unstage lines
-rw-r--r-- | docs/Config.md | 1 | ||||
-rw-r--r-- | pkg/config/app_config.go | 1 | ||||
-rw-r--r-- | pkg/gui/files_panel.go | 2 | ||||
-rw-r--r-- | pkg/gui/staging_panel.go | 23 |
4 files changed, 24 insertions, 3 deletions
diff --git a/docs/Config.md b/docs/Config.md index 5948f1f1e..4eb6e619e 100644 --- a/docs/Config.md +++ b/docs/Config.md @@ -21,6 +21,7 @@ Default path for the config file: `~/.config/jesseduffield/lazygit/config.yml` commitLength: show: true mouseEvents: true + skipUnstageLineWarning: false git: merging: # only applicable to unix users diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index 3f0989619..43fecb524 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -243,6 +243,7 @@ func GetDefaultConfig() []byte { scrollHeight: 2 scrollPastBottom: true mouseEvents: true + skipUnstageLineWarning: false theme: lightTheme: false activeBorderColor: diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index beb913c64..2128d67a7 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -32,6 +32,8 @@ func (gui *Gui) selectFile(alreadySelected bool) error { if err != gui.Errors.ErrNoFiles { return err } + gui.State.SplitMainPanel = false + gui.getMainView().Title = "" return gui.newStringTask("main", gui.Tr.SLocalize("NoChangedFiles")) } diff --git a/pkg/gui/staging_panel.go b/pkg/gui/staging_panel.go index 02fab93b1..a6eecb8b0 100644 --- a/pkg/gui/staging_panel.go +++ b/pkg/gui/staging_panel.go @@ -12,6 +12,13 @@ func (gui *Gui) refreshStagingPanel(forceSecondaryFocused bool, selectedLineIdx state := gui.State.Panels.LineByLine + // We need to force focus here because the confirmation panel for safely staging lines does not return focus automatically. + // This is because if we tell it to return focus it will unconditionally return it to the main panel which may not be what we want + // e.g. in the event that there's nothing left to stage. + if err := gui.switchFocus(gui.g, nil, gui.getMainView()); err != nil { + return err + } + file, err := gui.getSelectedFile(gui.g) if err != nil { if err != gui.Errors.ErrNoFiles { @@ -93,20 +100,30 @@ func (gui *Gui) handleStagingEscape(g *gocui.Gui, v *gocui.View) error { } func (gui *Gui) handleStageSelection(g *gocui.Gui, v *gocui.View) error { - return gui.applySelection(false) + return gui.applySelectionWithPrompt(false) } func (gui *Gui) handleResetSelection(g *gocui.Gui, v *gocui.View) error { - return gui.applySelection(true) + return gui.applySelectionWithPrompt(true) } -func (gui *Gui) applySelection(reverse bool) error { +func (gui *Gui) applySelectionWithPrompt(reverse bool) error { state := gui.State.Panels.LineByLine if !reverse && state.SecondaryFocused { return gui.createErrorPanel(gui.g, gui.Tr.SLocalize("CantStageStaged")) + } else if reverse && !state.SecondaryFocused && !gui.Config.GetUserConfig().GetBool("gui.skipUnstageLineWarning") { + return gui.createConfirmationPanel(gui.g, gui.getMainView(), false, "unstage lines", "Are you sure you want to unstage these lines? It is irreversible.\nTo disable this dialogue set the config key of 'gui.skipUnstageLineWarning' to true", func(*gocui.Gui, *gocui.View) error { + return gui.applySelection(reverse) + }, nil) } + return gui.applySelection(reverse) +} + +func (gui *Gui) applySelection(reverse bool) error { + state := gui.State.Panels.LineByLine + file, err := gui.getSelectedFile(gui.g) if err != nil { return err |