1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-11-06 08:59:31 +02:00

safely unstage lines

This commit is contained in:
Jesse Duffield
2020-01-12 15:02:00 +11:00
parent deaa2bcb15
commit b64953ebdb
4 changed files with 24 additions and 3 deletions

View File

@@ -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

View File

@@ -243,6 +243,7 @@ func GetDefaultConfig() []byte {
scrollHeight: 2
scrollPastBottom: true
mouseEvents: true
skipUnstageLineWarning: false
theme:
lightTheme: false
activeBorderColor:

View File

@@ -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"))
}

View File

@@ -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