1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-30 03:23:08 +03:00

Disable staging and unstaging lines or hunks when the diff context size is 0

Git diff and patch doesn't work reliably with a context size of 0, so disable it
in this case (and discarding changes as well). Magit does the same, see
https://github.com/magit/magit/issues/4222.

Staging entire files by pressing space in the Files panel is still possible, of
course.
This commit is contained in:
Stefan Haller
2025-02-05 16:04:50 +01:00
parent c0141685fe
commit 437daf2f74
2 changed files with 16 additions and 0 deletions

View File

@ -1,11 +1,13 @@
package controllers
import (
"fmt"
"strings"
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
"github.com/jesseduffield/lazygit/pkg/commands/patch"
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
@ -185,10 +187,20 @@ func (self *StagingController) TogglePanel() error {
}
func (self *StagingController) ToggleStaged() error {
if self.c.AppState.DiffContextSize == 0 {
return fmt.Errorf(self.c.Tr.Actions.NotEnoughContextToStage,
keybindings.Label(self.c.UserConfig().Keybinding.Universal.IncreaseContextInDiffView))
}
return self.applySelectionAndRefresh(self.staged)
}
func (self *StagingController) DiscardSelection() error {
if self.c.AppState.DiffContextSize == 0 {
return fmt.Errorf(self.c.Tr.Actions.NotEnoughContextToDiscard,
keybindings.Label(self.c.UserConfig().Keybinding.Universal.IncreaseContextInDiffView))
}
reset := func() error { return self.applySelectionAndRefresh(true) }
if !self.staged && !self.c.UserConfig().Gui.SkipDiscardChangeWarning {

View File

@ -926,6 +926,8 @@ type Actions struct {
UnstageFile string
UnstageAllFiles string
StageAllFiles string
NotEnoughContextToStage string
NotEnoughContextToDiscard string
IgnoreExcludeFile string
IgnoreFileErr string
ExcludeFile string
@ -1913,6 +1915,8 @@ func EnglishTranslationSet() *TranslationSet {
UnstageFile: "Unstage file",
UnstageAllFiles: "Unstage all files",
StageAllFiles: "Stage all files",
NotEnoughContextToStage: "Staging or unstaging changes is not possible with a diff context size of 0. Increase the context using '%s'.",
NotEnoughContextToDiscard: "Discarding changes is not possible with a diff context size of 0. Increase the context using '%s'.",
IgnoreExcludeFile: "Ignore or exclude file",
IgnoreFileErr: "Cannot ignore .gitignore",
ExcludeFile: "Exclude file",