mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-03 00:57:52 +02:00
Save diff context size in state.yml instead of config.yml (#2969)
This commit is contained in:
@ -117,7 +117,6 @@ git:
|
|||||||
overrideGpg: false # prevents lazygit from spawning a separate process when using GPG
|
overrideGpg: false # prevents lazygit from spawning a separate process when using GPG
|
||||||
disableForcePushing: false
|
disableForcePushing: false
|
||||||
parseEmoji: false
|
parseEmoji: false
|
||||||
diffContextSize: 3 # how many lines of context are shown around a change in diffs
|
|
||||||
os:
|
os:
|
||||||
copyToClipboardCmd: '' # See 'Custom Command for Copying to Clipboard' section
|
copyToClipboardCmd: '' # See 'Custom Command for Copying to Clipboard' section
|
||||||
editPreset: '' # see 'Configuring File Editing' section
|
editPreset: '' # see 'Configuring File Editing' section
|
||||||
|
@ -62,6 +62,7 @@ func Run(
|
|||||||
|
|
||||||
func NewCommon(config config.AppConfigurer) (*common.Common, error) {
|
func NewCommon(config config.AppConfigurer) (*common.Common, error) {
|
||||||
userConfig := config.GetUserConfig()
|
userConfig := config.GetUserConfig()
|
||||||
|
appState := config.GetAppState()
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
log := newLogger(config)
|
log := newLogger(config)
|
||||||
@ -74,6 +75,7 @@ func NewCommon(config config.AppConfigurer) (*common.Common, error) {
|
|||||||
Log: log,
|
Log: log,
|
||||||
Tr: tr,
|
Tr: tr,
|
||||||
UserConfig: userConfig,
|
UserConfig: userConfig,
|
||||||
|
AppState: appState,
|
||||||
Debug: config.GetDebug(),
|
Debug: config.GetDebug(),
|
||||||
Fs: afero.NewOsFs(),
|
Fs: afero.NewOsFs(),
|
||||||
}, nil
|
}, nil
|
||||||
|
@ -159,9 +159,7 @@ func NewGitCommandAux(
|
|||||||
stashCommands := git_commands.NewStashCommands(gitCommon, fileLoader, workingTreeCommands)
|
stashCommands := git_commands.NewStashCommands(gitCommon, fileLoader, workingTreeCommands)
|
||||||
patchBuilder := patch.NewPatchBuilder(cmn.Log,
|
patchBuilder := patch.NewPatchBuilder(cmn.Log,
|
||||||
func(from string, to string, reverse bool, filename string, plain bool) (string, error) {
|
func(from string, to string, reverse bool, filename string, plain bool) (string, error) {
|
||||||
// TODO: make patch builder take Gui.IgnoreWhitespaceInDiffView into
|
return workingTreeCommands.ShowFileDiff(from, to, reverse, filename, plain)
|
||||||
// account. For now we just pass false.
|
|
||||||
return workingTreeCommands.ShowFileDiff(from, to, reverse, filename, plain, false)
|
|
||||||
})
|
})
|
||||||
patchCommands := git_commands.NewPatchCommands(gitCommon, rebaseCommands, commitCommands, statusCommands, stashCommands, patchBuilder)
|
patchCommands := git_commands.NewPatchCommands(gitCommon, rebaseCommands, commitCommands, statusCommands, stashCommands, patchBuilder)
|
||||||
bisectCommands := git_commands.NewBisectCommands(gitCommon)
|
bisectCommands := git_commands.NewBisectCommands(gitCommon)
|
||||||
|
@ -196,8 +196,8 @@ func (self *CommitCommands) AmendHeadCmdObj() oscommands.ICmdObj {
|
|||||||
return self.cmd.New(cmdArgs)
|
return self.cmd.New(cmdArgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *CommitCommands) ShowCmdObj(sha string, filterPath string, ignoreWhitespace bool) oscommands.ICmdObj {
|
func (self *CommitCommands) ShowCmdObj(sha string, filterPath string) oscommands.ICmdObj {
|
||||||
contextSize := self.UserConfig.Git.DiffContextSize
|
contextSize := self.AppState.DiffContextSize
|
||||||
|
|
||||||
extDiffCmd := self.UserConfig.Git.Paging.ExternalDiffCommand
|
extDiffCmd := self.UserConfig.Git.Paging.ExternalDiffCommand
|
||||||
cmdArgs := NewGitCmd("show").
|
cmdArgs := NewGitCmd("show").
|
||||||
@ -210,7 +210,7 @@ func (self *CommitCommands) ShowCmdObj(sha string, filterPath string, ignoreWhit
|
|||||||
Arg("--decorate").
|
Arg("--decorate").
|
||||||
Arg("-p").
|
Arg("-p").
|
||||||
Arg(sha).
|
Arg(sha).
|
||||||
ArgIf(ignoreWhitespace, "--ignore-all-space").
|
ArgIf(self.AppState.IgnoreWhitespaceInDiffView, "--ignore-all-space").
|
||||||
ArgIf(filterPath != "", "--", filterPath).
|
ArgIf(filterPath != "", "--", filterPath).
|
||||||
ToArgv()
|
ToArgv()
|
||||||
|
|
||||||
|
@ -237,13 +237,15 @@ func TestCommitShowCmdObj(t *testing.T) {
|
|||||||
s := s
|
s := s
|
||||||
t.Run(s.testName, func(t *testing.T) {
|
t.Run(s.testName, func(t *testing.T) {
|
||||||
userConfig := config.GetDefaultConfig()
|
userConfig := config.GetDefaultConfig()
|
||||||
userConfig.Git.DiffContextSize = s.contextSize
|
|
||||||
userConfig.Git.Paging.ExternalDiffCommand = s.extDiffCmd
|
userConfig.Git.Paging.ExternalDiffCommand = s.extDiffCmd
|
||||||
|
appState := &config.AppState{}
|
||||||
|
appState.IgnoreWhitespaceInDiffView = s.ignoreWhitespace
|
||||||
|
appState.DiffContextSize = s.contextSize
|
||||||
|
|
||||||
runner := oscommands.NewFakeRunner(t).ExpectGitArgs(s.expected, "", nil)
|
runner := oscommands.NewFakeRunner(t).ExpectGitArgs(s.expected, "", nil)
|
||||||
instance := buildCommitCommands(commonDeps{userConfig: userConfig, runner: runner})
|
instance := buildCommitCommands(commonDeps{userConfig: userConfig, appState: appState, runner: runner})
|
||||||
|
|
||||||
assert.NoError(t, instance.ShowCmdObj("1234567890", s.filterPath, s.ignoreWhitespace).Run())
|
assert.NoError(t, instance.ShowCmdObj("1234567890", s.filterPath).Run())
|
||||||
runner.CheckForMissingCalls()
|
runner.CheckForMissingCalls()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ import (
|
|||||||
type commonDeps struct {
|
type commonDeps struct {
|
||||||
runner *oscommands.FakeCmdObjRunner
|
runner *oscommands.FakeCmdObjRunner
|
||||||
userConfig *config.UserConfig
|
userConfig *config.UserConfig
|
||||||
|
appState *config.AppState
|
||||||
gitVersion *GitVersion
|
gitVersion *GitVersion
|
||||||
gitConfig *git_config.FakeGitConfig
|
gitConfig *git_config.FakeGitConfig
|
||||||
getenv func(string) string
|
getenv func(string) string
|
||||||
@ -32,7 +33,7 @@ func buildGitCommon(deps commonDeps) *GitCommon {
|
|||||||
|
|
||||||
gitCommon.Common = deps.common
|
gitCommon.Common = deps.common
|
||||||
if gitCommon.Common == nil {
|
if gitCommon.Common == nil {
|
||||||
gitCommon.Common = utils.NewDummyCommonWithUserConfig(deps.userConfig)
|
gitCommon.Common = utils.NewDummyCommonWithUserConfigAndAppState(deps.userConfig, deps.appState)
|
||||||
}
|
}
|
||||||
|
|
||||||
if deps.fs != nil {
|
if deps.fs != nil {
|
||||||
|
@ -80,13 +80,13 @@ func (self *StashCommands) Sha(index int) (string, error) {
|
|||||||
return strings.Trim(sha, "\r\n"), err
|
return strings.Trim(sha, "\r\n"), err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *StashCommands) ShowStashEntryCmdObj(index int, ignoreWhitespace bool) oscommands.ICmdObj {
|
func (self *StashCommands) ShowStashEntryCmdObj(index int) oscommands.ICmdObj {
|
||||||
cmdArgs := NewGitCmd("stash").Arg("show").
|
cmdArgs := NewGitCmd("stash").Arg("show").
|
||||||
Arg("-p").
|
Arg("-p").
|
||||||
Arg("--stat").
|
Arg("--stat").
|
||||||
Arg(fmt.Sprintf("--color=%s", self.UserConfig.Git.Paging.ColorArg)).
|
Arg(fmt.Sprintf("--color=%s", self.UserConfig.Git.Paging.ColorArg)).
|
||||||
Arg(fmt.Sprintf("--unified=%d", self.UserConfig.Git.DiffContextSize)).
|
Arg(fmt.Sprintf("--unified=%d", self.AppState.DiffContextSize)).
|
||||||
ArgIf(ignoreWhitespace, "--ignore-all-space").
|
ArgIf(self.AppState.IgnoreWhitespaceInDiffView, "--ignore-all-space").
|
||||||
Arg(fmt.Sprintf("stash@{%d}", index)).
|
Arg(fmt.Sprintf("stash@{%d}", index)).
|
||||||
ToArgv()
|
ToArgv()
|
||||||
|
|
||||||
|
@ -134,10 +134,12 @@ func TestStashStashEntryCmdObj(t *testing.T) {
|
|||||||
s := s
|
s := s
|
||||||
t.Run(s.testName, func(t *testing.T) {
|
t.Run(s.testName, func(t *testing.T) {
|
||||||
userConfig := config.GetDefaultConfig()
|
userConfig := config.GetDefaultConfig()
|
||||||
userConfig.Git.DiffContextSize = s.contextSize
|
appState := &config.AppState{}
|
||||||
instance := buildStashCommands(commonDeps{userConfig: userConfig})
|
appState.IgnoreWhitespaceInDiffView = s.ignoreWhitespace
|
||||||
|
appState.DiffContextSize = s.contextSize
|
||||||
|
instance := buildStashCommands(commonDeps{userConfig: userConfig, appState: appState})
|
||||||
|
|
||||||
cmdStr := instance.ShowStashEntryCmdObj(s.index, s.ignoreWhitespace).Args()
|
cmdStr := instance.ShowStashEntryCmdObj(s.index).Args()
|
||||||
assert.Equal(t, s.expected, cmdStr)
|
assert.Equal(t, s.expected, cmdStr)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -228,19 +228,19 @@ func (self *WorkingTreeCommands) Exclude(filename string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WorktreeFileDiff returns the diff of a file
|
// WorktreeFileDiff returns the diff of a file
|
||||||
func (self *WorkingTreeCommands) WorktreeFileDiff(file *models.File, plain bool, cached bool, ignoreWhitespace bool) string {
|
func (self *WorkingTreeCommands) WorktreeFileDiff(file *models.File, plain bool, cached bool) string {
|
||||||
// for now we assume an error means the file was deleted
|
// for now we assume an error means the file was deleted
|
||||||
s, _ := self.WorktreeFileDiffCmdObj(file, plain, cached, ignoreWhitespace).RunWithOutput()
|
s, _ := self.WorktreeFileDiffCmdObj(file, plain, cached).RunWithOutput()
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *WorkingTreeCommands) WorktreeFileDiffCmdObj(node models.IFile, plain bool, cached bool, ignoreWhitespace bool) oscommands.ICmdObj {
|
func (self *WorkingTreeCommands) WorktreeFileDiffCmdObj(node models.IFile, plain bool, cached bool) oscommands.ICmdObj {
|
||||||
colorArg := self.UserConfig.Git.Paging.ColorArg
|
colorArg := self.UserConfig.Git.Paging.ColorArg
|
||||||
if plain {
|
if plain {
|
||||||
colorArg = "never"
|
colorArg = "never"
|
||||||
}
|
}
|
||||||
|
|
||||||
contextSize := self.UserConfig.Git.DiffContextSize
|
contextSize := self.AppState.DiffContextSize
|
||||||
prevPath := node.GetPreviousPath()
|
prevPath := node.GetPreviousPath()
|
||||||
noIndex := !node.GetIsTracked() && !node.GetHasStagedChanges() && !cached && node.GetIsFile()
|
noIndex := !node.GetIsTracked() && !node.GetHasStagedChanges() && !cached && node.GetIsFile()
|
||||||
extDiffCmd := self.UserConfig.Git.Paging.ExternalDiffCommand
|
extDiffCmd := self.UserConfig.Git.Paging.ExternalDiffCommand
|
||||||
@ -252,7 +252,7 @@ func (self *WorkingTreeCommands) WorktreeFileDiffCmdObj(node models.IFile, plain
|
|||||||
Arg("--submodule").
|
Arg("--submodule").
|
||||||
Arg(fmt.Sprintf("--unified=%d", contextSize)).
|
Arg(fmt.Sprintf("--unified=%d", contextSize)).
|
||||||
Arg(fmt.Sprintf("--color=%s", colorArg)).
|
Arg(fmt.Sprintf("--color=%s", colorArg)).
|
||||||
ArgIf(ignoreWhitespace, "--ignore-all-space").
|
ArgIf(!plain && self.AppState.IgnoreWhitespaceInDiffView, "--ignore-all-space").
|
||||||
ArgIf(cached, "--cached").
|
ArgIf(cached, "--cached").
|
||||||
ArgIf(noIndex, "--no-index").
|
ArgIf(noIndex, "--no-index").
|
||||||
Arg("--").
|
Arg("--").
|
||||||
@ -266,16 +266,12 @@ func (self *WorkingTreeCommands) WorktreeFileDiffCmdObj(node models.IFile, plain
|
|||||||
|
|
||||||
// ShowFileDiff get the diff of specified from and to. Typically this will be used for a single commit so it'll be 123abc^..123abc
|
// ShowFileDiff get the diff of specified from and to. Typically this will be used for a single commit so it'll be 123abc^..123abc
|
||||||
// but when we're in diff mode it could be any 'from' to any 'to'. The reverse flag is also here thanks to diff mode.
|
// but when we're in diff mode it could be any 'from' to any 'to'. The reverse flag is also here thanks to diff mode.
|
||||||
func (self *WorkingTreeCommands) ShowFileDiff(from string, to string, reverse bool, fileName string, plain bool,
|
func (self *WorkingTreeCommands) ShowFileDiff(from string, to string, reverse bool, fileName string, plain bool) (string, error) {
|
||||||
ignoreWhitespace bool,
|
return self.ShowFileDiffCmdObj(from, to, reverse, fileName, plain).RunWithOutput()
|
||||||
) (string, error) {
|
|
||||||
return self.ShowFileDiffCmdObj(from, to, reverse, fileName, plain, ignoreWhitespace).RunWithOutput()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *WorkingTreeCommands) ShowFileDiffCmdObj(from string, to string, reverse bool, fileName string, plain bool,
|
func (self *WorkingTreeCommands) ShowFileDiffCmdObj(from string, to string, reverse bool, fileName string, plain bool) oscommands.ICmdObj {
|
||||||
ignoreWhitespace bool,
|
contextSize := self.AppState.DiffContextSize
|
||||||
) oscommands.ICmdObj {
|
|
||||||
contextSize := self.UserConfig.Git.DiffContextSize
|
|
||||||
|
|
||||||
colorArg := self.UserConfig.Git.Paging.ColorArg
|
colorArg := self.UserConfig.Git.Paging.ColorArg
|
||||||
if plain {
|
if plain {
|
||||||
@ -295,7 +291,7 @@ func (self *WorkingTreeCommands) ShowFileDiffCmdObj(from string, to string, reve
|
|||||||
Arg(from).
|
Arg(from).
|
||||||
Arg(to).
|
Arg(to).
|
||||||
ArgIf(reverse, "-R").
|
ArgIf(reverse, "-R").
|
||||||
ArgIf(ignoreWhitespace, "--ignore-all-space").
|
ArgIf(!plain && self.AppState.IgnoreWhitespaceInDiffView, "--ignore-all-space").
|
||||||
Arg("--").
|
Arg("--").
|
||||||
Arg(fileName).
|
Arg(fileName).
|
||||||
ToArgv()
|
ToArgv()
|
||||||
|
@ -309,10 +309,12 @@ func TestWorkingTreeDiff(t *testing.T) {
|
|||||||
s := s
|
s := s
|
||||||
t.Run(s.testName, func(t *testing.T) {
|
t.Run(s.testName, func(t *testing.T) {
|
||||||
userConfig := config.GetDefaultConfig()
|
userConfig := config.GetDefaultConfig()
|
||||||
userConfig.Git.DiffContextSize = s.contextSize
|
appState := &config.AppState{}
|
||||||
|
appState.IgnoreWhitespaceInDiffView = s.ignoreWhitespace
|
||||||
|
appState.DiffContextSize = s.contextSize
|
||||||
|
|
||||||
instance := buildWorkingTreeCommands(commonDeps{runner: s.runner, userConfig: userConfig})
|
instance := buildWorkingTreeCommands(commonDeps{runner: s.runner, userConfig: userConfig, appState: appState})
|
||||||
result := instance.WorktreeFileDiff(s.file, s.plain, s.cached, s.ignoreWhitespace)
|
result := instance.WorktreeFileDiff(s.file, s.plain, s.cached)
|
||||||
assert.Equal(t, expectedResult, result)
|
assert.Equal(t, expectedResult, result)
|
||||||
s.runner.CheckForMissingCalls()
|
s.runner.CheckForMissingCalls()
|
||||||
})
|
})
|
||||||
@ -373,11 +375,13 @@ func TestWorkingTreeShowFileDiff(t *testing.T) {
|
|||||||
s := s
|
s := s
|
||||||
t.Run(s.testName, func(t *testing.T) {
|
t.Run(s.testName, func(t *testing.T) {
|
||||||
userConfig := config.GetDefaultConfig()
|
userConfig := config.GetDefaultConfig()
|
||||||
userConfig.Git.DiffContextSize = s.contextSize
|
appState := &config.AppState{}
|
||||||
|
appState.IgnoreWhitespaceInDiffView = s.ignoreWhitespace
|
||||||
|
appState.DiffContextSize = s.contextSize
|
||||||
|
|
||||||
instance := buildWorkingTreeCommands(commonDeps{runner: s.runner, userConfig: userConfig})
|
instance := buildWorkingTreeCommands(commonDeps{runner: s.runner, userConfig: userConfig, appState: appState})
|
||||||
|
|
||||||
result, err := instance.ShowFileDiff(s.from, s.to, s.reverse, "test.txt", s.plain, s.ignoreWhitespace)
|
result, err := instance.ShowFileDiff(s.from, s.to, s.reverse, "test.txt", s.plain)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, expectedResult, result)
|
assert.Equal(t, expectedResult, result)
|
||||||
s.runner.CheckForMissingCalls()
|
s.runner.CheckForMissingCalls()
|
||||||
|
@ -12,6 +12,7 @@ type Common struct {
|
|||||||
Log *logrus.Entry
|
Log *logrus.Entry
|
||||||
Tr *i18n.TranslationSet
|
Tr *i18n.TranslationSet
|
||||||
UserConfig *config.UserConfig
|
UserConfig *config.UserConfig
|
||||||
|
AppState *config.AppState
|
||||||
Debug bool
|
Debug bool
|
||||||
// for interacting with the filesystem. We use afero rather than the default
|
// for interacting with the filesystem. We use afero rather than the default
|
||||||
// `os` package for the sake of mocking the filesystem in tests
|
// `os` package for the sake of mocking the filesystem in tests
|
||||||
|
@ -283,11 +283,13 @@ func (c *AppConfig) SaveAppState() error {
|
|||||||
|
|
||||||
// loadAppState loads recorded AppState from file
|
// loadAppState loads recorded AppState from file
|
||||||
func loadAppState() (*AppState, error) {
|
func loadAppState() (*AppState, error) {
|
||||||
|
appState := getDefaultAppState()
|
||||||
|
|
||||||
filepath, err := configFilePath("state.yml")
|
filepath, err := configFilePath("state.yml")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsPermission(err) {
|
if os.IsPermission(err) {
|
||||||
// apparently when people have read-only permissions they prefer us to fail silently
|
// apparently when people have read-only permissions they prefer us to fail silently
|
||||||
return getDefaultAppState(), nil
|
return appState, nil
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -298,10 +300,9 @@ func loadAppState() (*AppState, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(appStateBytes) == 0 {
|
if len(appStateBytes) == 0 {
|
||||||
return getDefaultAppState(), nil
|
return appState, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
appState := &AppState{}
|
|
||||||
err = yaml.Unmarshal(appStateBytes, appState)
|
err = yaml.Unmarshal(appStateBytes, appState)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -321,6 +322,7 @@ type AppState struct {
|
|||||||
CustomCommandsHistory []string
|
CustomCommandsHistory []string
|
||||||
HideCommandLog bool
|
HideCommandLog bool
|
||||||
IgnoreWhitespaceInDiffView bool
|
IgnoreWhitespaceInDiffView bool
|
||||||
|
DiffContextSize int
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDefaultAppState() *AppState {
|
func getDefaultAppState() *AppState {
|
||||||
@ -328,6 +330,7 @@ func getDefaultAppState() *AppState {
|
|||||||
LastUpdateCheck: 0,
|
LastUpdateCheck: 0,
|
||||||
RecentRepos: []string{},
|
RecentRepos: []string{},
|
||||||
StartupPopupVersion: 0,
|
StartupPopupVersion: 0,
|
||||||
|
DiffContextSize: 3,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +97,6 @@ type GitConfig struct {
|
|||||||
// this should really be under 'gui', not 'git'
|
// this should really be under 'gui', not 'git'
|
||||||
ParseEmoji bool `yaml:"parseEmoji"`
|
ParseEmoji bool `yaml:"parseEmoji"`
|
||||||
Log LogConfig `yaml:"log"`
|
Log LogConfig `yaml:"log"`
|
||||||
DiffContextSize int `yaml:"diffContextSize"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type PagingConfig struct {
|
type PagingConfig struct {
|
||||||
@ -497,7 +496,6 @@ func GetDefaultConfig() *UserConfig {
|
|||||||
DisableForcePushing: false,
|
DisableForcePushing: false,
|
||||||
CommitPrefixes: map[string]CommitPrefixConfig(nil),
|
CommitPrefixes: map[string]CommitPrefixConfig(nil),
|
||||||
ParseEmoji: false,
|
ParseEmoji: false,
|
||||||
DiffContextSize: 3,
|
|
||||||
},
|
},
|
||||||
Refresher: RefresherConfig{
|
Refresher: RefresherConfig{
|
||||||
RefreshInterval: 10,
|
RefreshInterval: 10,
|
||||||
|
@ -113,9 +113,7 @@ func (self *CommitFilesController) GetOnRenderToMain() func() error {
|
|||||||
to := ref.RefName()
|
to := ref.RefName()
|
||||||
from, reverse := self.c.Modes().Diffing.GetFromAndReverseArgsForDiff(ref.ParentRefName())
|
from, reverse := self.c.Modes().Diffing.GetFromAndReverseArgsForDiff(ref.ParentRefName())
|
||||||
|
|
||||||
cmdObj := self.c.Git().WorkingTree.ShowFileDiffCmdObj(
|
cmdObj := self.c.Git().WorkingTree.ShowFileDiffCmdObj(from, to, reverse, node.GetPath(), false)
|
||||||
from, to, reverse, node.GetPath(), false, self.c.GetAppState().IgnoreWhitespaceInDiffView,
|
|
||||||
)
|
|
||||||
task := types.NewRunPtyTask(cmdObj.GetCmd())
|
task := types.NewRunPtyTask(cmdObj.GetCmd())
|
||||||
|
|
||||||
pair := self.c.MainViewPairs().Normal
|
pair := self.c.MainViewPairs().Normal
|
||||||
|
@ -2,6 +2,7 @@ package controllers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
@ -65,7 +66,7 @@ func (self *ContextLinesController) Increase() error {
|
|||||||
return self.c.Error(err)
|
return self.c.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
self.c.UserConfig.Git.DiffContextSize = self.c.UserConfig.Git.DiffContextSize + 1
|
self.c.AppState.DiffContextSize++
|
||||||
return self.applyChange()
|
return self.applyChange()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,14 +74,14 @@ func (self *ContextLinesController) Increase() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *ContextLinesController) Decrease() error {
|
func (self *ContextLinesController) Decrease() error {
|
||||||
old_size := self.c.UserConfig.Git.DiffContextSize
|
old_size := self.c.AppState.DiffContextSize
|
||||||
|
|
||||||
if self.isShowingDiff() && old_size > 1 {
|
if self.isShowingDiff() && old_size > 1 {
|
||||||
if err := self.checkCanChangeContext(); err != nil {
|
if err := self.checkCanChangeContext(); err != nil {
|
||||||
return self.c.Error(err)
|
return self.c.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
self.c.UserConfig.Git.DiffContextSize = old_size - 1
|
self.c.AppState.DiffContextSize = old_size - 1
|
||||||
return self.applyChange()
|
return self.applyChange()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,6 +89,9 @@ func (self *ContextLinesController) Decrease() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *ContextLinesController) applyChange() error {
|
func (self *ContextLinesController) applyChange() error {
|
||||||
|
self.c.Toast(fmt.Sprintf(self.c.Tr.DiffContextSizeChanged, self.c.AppState.DiffContextSize))
|
||||||
|
self.c.SaveAppStateAndLogError()
|
||||||
|
|
||||||
currentContext := self.c.CurrentStaticContext()
|
currentContext := self.c.CurrentStaticContext()
|
||||||
switch currentContext.GetKey() {
|
switch currentContext.GetKey() {
|
||||||
// we make an exception for our staging and patch building contexts because they actually need to refresh their state afterwards.
|
// we make an exception for our staging and patch building contexts because they actually need to refresh their state afterwards.
|
||||||
|
@ -201,7 +201,7 @@ func (self *FilesController) GetOnRenderToMain() func() error {
|
|||||||
split := self.c.UserConfig.Gui.SplitDiff == "always" || (node.GetHasUnstagedChanges() && node.GetHasStagedChanges())
|
split := self.c.UserConfig.Gui.SplitDiff == "always" || (node.GetHasUnstagedChanges() && node.GetHasStagedChanges())
|
||||||
mainShowsStaged := !split && node.GetHasStagedChanges()
|
mainShowsStaged := !split && node.GetHasStagedChanges()
|
||||||
|
|
||||||
cmdObj := self.c.Git().WorkingTree.WorktreeFileDiffCmdObj(node, false, mainShowsStaged, self.c.GetAppState().IgnoreWhitespaceInDiffView)
|
cmdObj := self.c.Git().WorkingTree.WorktreeFileDiffCmdObj(node, false, mainShowsStaged)
|
||||||
title := self.c.Tr.UnstagedChanges
|
title := self.c.Tr.UnstagedChanges
|
||||||
if mainShowsStaged {
|
if mainShowsStaged {
|
||||||
title = self.c.Tr.StagedChanges
|
title = self.c.Tr.StagedChanges
|
||||||
@ -216,7 +216,7 @@ func (self *FilesController) GetOnRenderToMain() func() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if split {
|
if split {
|
||||||
cmdObj := self.c.Git().WorkingTree.WorktreeFileDiffCmdObj(node, false, true, self.c.GetAppState().IgnoreWhitespaceInDiffView)
|
cmdObj := self.c.Git().WorkingTree.WorktreeFileDiffCmdObj(node, false, true)
|
||||||
|
|
||||||
title := self.c.Tr.StagedChanges
|
title := self.c.Tr.StagedChanges
|
||||||
if mainShowsStaged {
|
if mainShowsStaged {
|
||||||
|
@ -73,9 +73,7 @@ func (self *PatchBuildingHelper) RefreshPatchBuildingPanel(opts types.OnFocusOpt
|
|||||||
ref := self.c.Contexts().CommitFiles.CommitFileTreeViewModel.GetRef()
|
ref := self.c.Contexts().CommitFiles.CommitFileTreeViewModel.GetRef()
|
||||||
to := ref.RefName()
|
to := ref.RefName()
|
||||||
from, reverse := self.c.Modes().Diffing.GetFromAndReverseArgsForDiff(ref.ParentRefName())
|
from, reverse := self.c.Modes().Diffing.GetFromAndReverseArgsForDiff(ref.ParentRefName())
|
||||||
// Passing false for ignoreWhitespace because the patch building panel
|
diff, err := self.c.Git().WorkingTree.ShowFileDiff(from, to, reverse, path, true)
|
||||||
// doesn't work when whitespace is ignored
|
|
||||||
diff, err := self.c.Git().WorkingTree.ShowFileDiff(from, to, reverse, path, true, false)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -52,8 +52,8 @@ func (self *StagingHelper) RefreshStagingPanel(focusOpts types.OnFocusOpts) erro
|
|||||||
return self.handleStagingEscape()
|
return self.handleStagingEscape()
|
||||||
}
|
}
|
||||||
|
|
||||||
mainDiff := self.c.Git().WorkingTree.WorktreeFileDiff(file, true, false, false)
|
mainDiff := self.c.Git().WorkingTree.WorktreeFileDiff(file, true, false)
|
||||||
secondaryDiff := self.c.Git().WorkingTree.WorktreeFileDiff(file, true, true, false)
|
secondaryDiff := self.c.Git().WorkingTree.WorktreeFileDiff(file, true, true)
|
||||||
|
|
||||||
// grabbing locks here and releasing before we finish the function
|
// grabbing locks here and releasing before we finish the function
|
||||||
// because pushing say the secondary context could mean entering this function
|
// because pushing say the secondary context could mean entering this function
|
||||||
|
@ -177,7 +177,7 @@ func (self *LocalCommitsController) GetOnRenderToMain() func() error {
|
|||||||
"ref": commit.Name,
|
"ref": commit.Name,
|
||||||
}))
|
}))
|
||||||
} else {
|
} else {
|
||||||
cmdObj := self.c.Git().Commit.ShowCmdObj(commit.Sha, self.c.Modes().Filtering.GetPath(), self.c.GetAppState().IgnoreWhitespaceInDiffView)
|
cmdObj := self.c.Git().Commit.ShowCmdObj(commit.Sha, self.c.Modes().Filtering.GetPath())
|
||||||
task = types.NewRunPtyTask(cmdObj.GetCmd())
|
task = types.NewRunPtyTask(cmdObj.GetCmd())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ func (self *ReflogCommitsController) GetOnRenderToMain() func() error {
|
|||||||
if commit == nil {
|
if commit == nil {
|
||||||
task = types.NewRenderStringTask("No reflog history")
|
task = types.NewRenderStringTask("No reflog history")
|
||||||
} else {
|
} else {
|
||||||
cmdObj := self.c.Git().Commit.ShowCmdObj(commit.Sha, self.c.Modes().Filtering.GetPath(), self.c.GetAppState().IgnoreWhitespaceInDiffView)
|
cmdObj := self.c.Git().Commit.ShowCmdObj(commit.Sha, self.c.Modes().Filtering.GetPath())
|
||||||
|
|
||||||
task = types.NewRunPtyTask(cmdObj.GetCmd())
|
task = types.NewRunPtyTask(cmdObj.GetCmd())
|
||||||
}
|
}
|
||||||
|
@ -64,10 +64,7 @@ func (self *StashController) GetOnRenderToMain() func() error {
|
|||||||
task = types.NewRenderStringTask(self.c.Tr.NoStashEntries)
|
task = types.NewRenderStringTask(self.c.Tr.NoStashEntries)
|
||||||
} else {
|
} else {
|
||||||
task = types.NewRunPtyTask(
|
task = types.NewRunPtyTask(
|
||||||
self.c.Git().Stash.ShowStashEntryCmdObj(
|
self.c.Git().Stash.ShowStashEntryCmdObj(stashEntry.Index).GetCmd(),
|
||||||
stashEntry.Index,
|
|
||||||
self.c.GetAppState().IgnoreWhitespaceInDiffView,
|
|
||||||
).GetCmd(),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ func (self *SubCommitsController) GetOnRenderToMain() func() error {
|
|||||||
if commit == nil {
|
if commit == nil {
|
||||||
task = types.NewRenderStringTask("No commits")
|
task = types.NewRenderStringTask("No commits")
|
||||||
} else {
|
} else {
|
||||||
cmdObj := self.c.Git().Commit.ShowCmdObj(commit.Sha, self.c.Modes().Filtering.GetPath(), self.c.GetAppState().IgnoreWhitespaceInDiffView)
|
cmdObj := self.c.Git().Commit.ShowCmdObj(commit.Sha, self.c.Modes().Filtering.GetPath())
|
||||||
|
|
||||||
task = types.NewRunPtyTask(cmdObj.GetCmd())
|
task = types.NewRunPtyTask(cmdObj.GetCmd())
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,7 @@ func (self *SubmodulesController) GetOnRenderToMain() func() error {
|
|||||||
if file == nil {
|
if file == nil {
|
||||||
task = types.NewRenderStringTask(prefix)
|
task = types.NewRenderStringTask(prefix)
|
||||||
} else {
|
} else {
|
||||||
cmdObj := self.c.Git().WorkingTree.WorktreeFileDiffCmdObj(file, false, !file.HasUnstagedChanges && file.HasStagedChanges, self.c.GetAppState().IgnoreWhitespaceInDiffView)
|
cmdObj := self.c.Git().WorkingTree.WorktreeFileDiffCmdObj(file, false, !file.HasUnstagedChanges && file.HasStagedChanges)
|
||||||
task = types.NewRunCommandTaskWithPrefix(cmdObj.GetCmd(), prefix)
|
task = types.NewRunCommandTaskWithPrefix(cmdObj.GetCmd(), prefix)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,9 +24,7 @@ func (self *ToggleWhitespaceAction) Call() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.c.GetAppState().IgnoreWhitespaceInDiffView = !self.c.GetAppState().IgnoreWhitespaceInDiffView
|
self.c.GetAppState().IgnoreWhitespaceInDiffView = !self.c.GetAppState().IgnoreWhitespaceInDiffView
|
||||||
if err := self.c.SaveAppState(); err != nil {
|
self.c.SaveAppStateAndLogError()
|
||||||
self.c.Log.Errorf("error when saving app state: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return self.c.CurrentSideContext().HandleFocus(types.OnFocusOpts{})
|
return self.c.CurrentSideContext().HandleFocus(types.OnFocusOpts{})
|
||||||
}
|
}
|
||||||
|
@ -24,9 +24,7 @@ func (gui *Gui) handleCreateExtrasMenuPanel() error {
|
|||||||
show := !gui.c.State().GetShowExtrasWindow()
|
show := !gui.c.State().GetShowExtrasWindow()
|
||||||
gui.c.State().SetShowExtrasWindow(show)
|
gui.c.State().SetShowExtrasWindow(show)
|
||||||
gui.c.GetAppState().HideCommandLog = !show
|
gui.c.GetAppState().HideCommandLog = !show
|
||||||
if err := gui.c.SaveAppState(); err != nil {
|
gui.c.SaveAppStateAndLogError()
|
||||||
gui.c.Log.Errorf("error when saving app state: %v", err)
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -92,6 +92,12 @@ func (self *guiCommon) SaveAppState() error {
|
|||||||
return self.gui.Config.SaveAppState()
|
return self.gui.Config.SaveAppState()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *guiCommon) SaveAppStateAndLogError() {
|
||||||
|
if err := self.gui.Config.SaveAppState(); err != nil {
|
||||||
|
self.gui.Log.Errorf("error when saving app state: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (self *guiCommon) GetConfig() config.AppConfigurer {
|
func (self *guiCommon) GetConfig() config.AppConfigurer {
|
||||||
return self.gui.Config
|
return self.gui.Config
|
||||||
}
|
}
|
||||||
|
@ -73,6 +73,7 @@ type IGuiCommon interface {
|
|||||||
GetConfig() config.AppConfigurer
|
GetConfig() config.AppConfigurer
|
||||||
GetAppState() *config.AppState
|
GetAppState() *config.AppState
|
||||||
SaveAppState() error
|
SaveAppState() error
|
||||||
|
SaveAppStateAndLogError()
|
||||||
|
|
||||||
// Runs the given function on the UI thread (this is for things like showing a popup asking a user for input).
|
// Runs the given function on the UI thread (this is for things like showing a popup asking a user for input).
|
||||||
// Only necessary to call if you're not already on the UI thread i.e. you're inside a goroutine.
|
// Only necessary to call if you're not already on the UI thread i.e. you're inside a goroutine.
|
||||||
|
@ -512,6 +512,7 @@ type TranslationSet struct {
|
|||||||
IgnoreWhitespaceNotSupportedHere string
|
IgnoreWhitespaceNotSupportedHere string
|
||||||
IncreaseContextInDiffView string
|
IncreaseContextInDiffView string
|
||||||
DecreaseContextInDiffView string
|
DecreaseContextInDiffView string
|
||||||
|
DiffContextSizeChanged string
|
||||||
CreatePullRequestOptions string
|
CreatePullRequestOptions string
|
||||||
DefaultBranch string
|
DefaultBranch string
|
||||||
SelectBranch string
|
SelectBranch string
|
||||||
@ -1293,6 +1294,7 @@ func EnglishTranslationSet() TranslationSet {
|
|||||||
IgnoreWhitespaceNotSupportedHere: "Ignoring whitespace is not supported in this view",
|
IgnoreWhitespaceNotSupportedHere: "Ignoring whitespace is not supported in this view",
|
||||||
IncreaseContextInDiffView: "Increase the size of the context shown around changes in the diff view",
|
IncreaseContextInDiffView: "Increase the size of the context shown around changes in the diff view",
|
||||||
DecreaseContextInDiffView: "Decrease the size of the context shown around changes in the diff view",
|
DecreaseContextInDiffView: "Decrease the size of the context shown around changes in the diff view",
|
||||||
|
DiffContextSizeChanged: "Changed diff context size to %d",
|
||||||
CreatePullRequestOptions: "Create pull request options",
|
CreatePullRequestOptions: "Create pull request options",
|
||||||
DefaultBranch: "Default branch",
|
DefaultBranch: "Default branch",
|
||||||
SelectBranch: "Select branch",
|
SelectBranch: "Select branch",
|
||||||
|
@ -27,12 +27,13 @@ func NewDummyCommon() *common.Common {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDummyCommonWithUserConfig(userConfig *config.UserConfig) *common.Common {
|
func NewDummyCommonWithUserConfigAndAppState(userConfig *config.UserConfig, appState *config.AppState) *common.Common {
|
||||||
tr := i18n.EnglishTranslationSet()
|
tr := i18n.EnglishTranslationSet()
|
||||||
return &common.Common{
|
return &common.Common{
|
||||||
Log: NewDummyLog(),
|
Log: NewDummyLog(),
|
||||||
Tr: &tr,
|
Tr: &tr,
|
||||||
UserConfig: userConfig,
|
UserConfig: userConfig,
|
||||||
|
AppState: appState,
|
||||||
// TODO: remove dependency on actual filesystem in tests and switch to using
|
// TODO: remove dependency on actual filesystem in tests and switch to using
|
||||||
// in-memory for everything
|
// in-memory for everything
|
||||||
Fs: afero.NewOsFs(),
|
Fs: afero.NewOsFs(),
|
||||||
|
Reference in New Issue
Block a user