mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-23 12:18:51 +02:00
Disable staging and unstaging lines or hunks when the diff context size is 0 (#4235)
- **PR Description** 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. Fixes #4233.
This commit is contained in:
commit
5dff9af027
@ -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 {
|
||||
|
@ -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",
|
||||
|
Loading…
x
Reference in New Issue
Block a user