mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-08-06 11:02:41 +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:
@@ -1,11 +1,13 @@
|
|||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
|
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/patch"
|
"github.com/jesseduffield/lazygit/pkg/commands/patch"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -185,10 +187,20 @@ func (self *StagingController) TogglePanel() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *StagingController) ToggleStaged() 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)
|
return self.applySelectionAndRefresh(self.staged)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *StagingController) DiscardSelection() error {
|
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) }
|
reset := func() error { return self.applySelectionAndRefresh(true) }
|
||||||
|
|
||||||
if !self.staged && !self.c.UserConfig().Gui.SkipDiscardChangeWarning {
|
if !self.staged && !self.c.UserConfig().Gui.SkipDiscardChangeWarning {
|
||||||
|
@@ -926,6 +926,8 @@ type Actions struct {
|
|||||||
UnstageFile string
|
UnstageFile string
|
||||||
UnstageAllFiles string
|
UnstageAllFiles string
|
||||||
StageAllFiles string
|
StageAllFiles string
|
||||||
|
NotEnoughContextToStage string
|
||||||
|
NotEnoughContextToDiscard string
|
||||||
IgnoreExcludeFile string
|
IgnoreExcludeFile string
|
||||||
IgnoreFileErr string
|
IgnoreFileErr string
|
||||||
ExcludeFile string
|
ExcludeFile string
|
||||||
@@ -1913,6 +1915,8 @@ func EnglishTranslationSet() *TranslationSet {
|
|||||||
UnstageFile: "Unstage file",
|
UnstageFile: "Unstage file",
|
||||||
UnstageAllFiles: "Unstage all files",
|
UnstageAllFiles: "Unstage all files",
|
||||||
StageAllFiles: "Stage 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",
|
IgnoreExcludeFile: "Ignore or exclude file",
|
||||||
IgnoreFileErr: "Cannot ignore .gitignore",
|
IgnoreFileErr: "Cannot ignore .gitignore",
|
||||||
ExcludeFile: "Exclude file",
|
ExcludeFile: "Exclude file",
|
||||||
|
Reference in New Issue
Block a user