1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-15 01:34:26 +02:00

Move IgnoreWhitespaceInDiffView to user config

When toggling the value in the UI we simply overwrite the value in UserConfig;
this would be bad if there was ever a chance that we want to write the user
config back to disk, but it is very unlikely that we can do that, because
currently we have no way to tell which parts of the config come from the global
config file and which ones come from a repo-local one.
This commit is contained in:
Stefan Haller
2025-07-07 14:57:12 +02:00
parent f3164afa1e
commit 8d7bfd131e
13 changed files with 27 additions and 18 deletions

View File

@ -366,6 +366,9 @@ git:
allBranchesLogCmds: allBranchesLogCmds:
- git log --graph --all --color=always --abbrev-commit --decorate --date=relative --pretty=medium - git log --graph --all --color=always --abbrev-commit --decorate --date=relative --pretty=medium
# If true, git diffs are rendered with the `--ignore-all-space` flag, which ignores whitespace changes. Can be toggled from within Lazygit with `<c-w>`.
ignoreWhitespaceInDiffView: false
# If true, do not spawn a separate process when using GPG # If true, do not spawn a separate process when using GPG
overrideGpg: false overrideGpg: false

View File

@ -268,7 +268,7 @@ func (self *CommitCommands) ShowCmdObj(hash string, filterPath string) *oscomman
Arg("--decorate"). Arg("--decorate").
Arg("-p"). Arg("-p").
Arg(hash). Arg(hash).
ArgIf(self.AppState.IgnoreWhitespaceInDiffView, "--ignore-all-space"). ArgIf(self.UserConfig().Git.IgnoreWhitespaceInDiffView, "--ignore-all-space").
Arg(fmt.Sprintf("--find-renames=%d%%", self.AppState.RenameSimilarityThreshold)). Arg(fmt.Sprintf("--find-renames=%d%%", self.AppState.RenameSimilarityThreshold)).
ArgIf(filterPath != "", "--", filterPath). ArgIf(filterPath != "", "--", filterPath).
Dir(self.repoPaths.worktreePath). Dir(self.repoPaths.worktreePath).

View File

@ -320,8 +320,8 @@ func TestCommitShowCmdObj(t *testing.T) {
t.Run(s.testName, func(t *testing.T) { t.Run(s.testName, func(t *testing.T) {
userConfig := config.GetDefaultConfig() userConfig := config.GetDefaultConfig()
userConfig.Git.Paging.ExternalDiffCommand = s.extDiffCmd userConfig.Git.Paging.ExternalDiffCommand = s.extDiffCmd
userConfig.Git.IgnoreWhitespaceInDiffView = s.ignoreWhitespace
appState := &config.AppState{} appState := &config.AppState{}
appState.IgnoreWhitespaceInDiffView = s.ignoreWhitespace
appState.DiffContextSize = s.contextSize appState.DiffContextSize = s.contextSize
appState.RenameSimilarityThreshold = s.similarityThreshold appState.RenameSimilarityThreshold = s.similarityThreshold

View File

@ -21,7 +21,7 @@ func NewDiffCommands(gitCommon *GitCommon) *DiffCommands {
func (self *DiffCommands) DiffCmdObj(diffArgs []string) *oscommands.CmdObj { func (self *DiffCommands) DiffCmdObj(diffArgs []string) *oscommands.CmdObj {
extDiffCmd := self.UserConfig().Git.Paging.ExternalDiffCommand extDiffCmd := self.UserConfig().Git.Paging.ExternalDiffCommand
useExtDiff := extDiffCmd != "" useExtDiff := extDiffCmd != ""
ignoreWhitespace := self.AppState.IgnoreWhitespaceInDiffView ignoreWhitespace := self.UserConfig().Git.IgnoreWhitespaceInDiffView
return self.cmd.New( return self.cmd.New(
NewGitCmd("diff"). NewGitCmd("diff").

View File

@ -88,7 +88,7 @@ func (self *StashCommands) ShowStashEntryCmdObj(index int) *oscommands.CmdObj {
Arg("-u"). Arg("-u").
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.AppState.DiffContextSize)). Arg(fmt.Sprintf("--unified=%d", self.AppState.DiffContextSize)).
ArgIf(self.AppState.IgnoreWhitespaceInDiffView, "--ignore-all-space"). ArgIf(self.UserConfig().Git.IgnoreWhitespaceInDiffView, "--ignore-all-space").
Arg(fmt.Sprintf("--find-renames=%d%%", self.AppState.RenameSimilarityThreshold)). Arg(fmt.Sprintf("--find-renames=%d%%", self.AppState.RenameSimilarityThreshold)).
Arg(fmt.Sprintf("refs/stash@{%d}", index)). Arg(fmt.Sprintf("refs/stash@{%d}", index)).
Dir(self.repoPaths.worktreePath). Dir(self.repoPaths.worktreePath).

View File

@ -144,8 +144,8 @@ func TestStashStashEntryCmdObj(t *testing.T) {
for _, s := range scenarios { for _, s := range scenarios {
t.Run(s.testName, func(t *testing.T) { t.Run(s.testName, func(t *testing.T) {
userConfig := config.GetDefaultConfig() userConfig := config.GetDefaultConfig()
userConfig.Git.IgnoreWhitespaceInDiffView = s.ignoreWhitespace
appState := &config.AppState{} appState := &config.AppState{}
appState.IgnoreWhitespaceInDiffView = s.ignoreWhitespace
appState.DiffContextSize = s.contextSize appState.DiffContextSize = s.contextSize
appState.RenameSimilarityThreshold = s.similarityThreshold appState.RenameSimilarityThreshold = s.similarityThreshold
repoPaths := RepoPaths{ repoPaths := RepoPaths{

View File

@ -272,7 +272,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(!plain && self.AppState.IgnoreWhitespaceInDiffView, "--ignore-all-space"). ArgIf(!plain && self.UserConfig().Git.IgnoreWhitespaceInDiffView, "--ignore-all-space").
Arg(fmt.Sprintf("--find-renames=%d%%", self.AppState.RenameSimilarityThreshold)). Arg(fmt.Sprintf("--find-renames=%d%%", self.AppState.RenameSimilarityThreshold)).
ArgIf(cached, "--cached"). ArgIf(cached, "--cached").
ArgIf(noIndex, "--no-index"). ArgIf(noIndex, "--no-index").
@ -314,7 +314,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(!plain && self.AppState.IgnoreWhitespaceInDiffView, "--ignore-all-space"). ArgIf(!plain && self.UserConfig().Git.IgnoreWhitespaceInDiffView, "--ignore-all-space").
Arg("--"). Arg("--").
Arg(fileName). Arg(fileName).
Dir(self.repoPaths.worktreePath). Dir(self.repoPaths.worktreePath).

View File

@ -327,8 +327,8 @@ func TestWorkingTreeDiff(t *testing.T) {
for _, s := range scenarios { for _, s := range scenarios {
t.Run(s.testName, func(t *testing.T) { t.Run(s.testName, func(t *testing.T) {
userConfig := config.GetDefaultConfig() userConfig := config.GetDefaultConfig()
userConfig.Git.IgnoreWhitespaceInDiffView = s.ignoreWhitespace
appState := &config.AppState{} appState := &config.AppState{}
appState.IgnoreWhitespaceInDiffView = s.ignoreWhitespace
appState.DiffContextSize = s.contextSize appState.DiffContextSize = s.contextSize
appState.RenameSimilarityThreshold = s.similarityThreshold appState.RenameSimilarityThreshold = s.similarityThreshold
repoPaths := RepoPaths{ repoPaths := RepoPaths{
@ -396,8 +396,8 @@ func TestWorkingTreeShowFileDiff(t *testing.T) {
for _, s := range scenarios { for _, s := range scenarios {
t.Run(s.testName, func(t *testing.T) { t.Run(s.testName, func(t *testing.T) {
userConfig := config.GetDefaultConfig() userConfig := config.GetDefaultConfig()
userConfig.Git.IgnoreWhitespaceInDiffView = s.ignoreWhitespace
appState := &config.AppState{} appState := &config.AppState{}
appState.IgnoreWhitespaceInDiffView = s.ignoreWhitespace
appState.DiffContextSize = s.contextSize appState.DiffContextSize = s.contextSize
repoPaths := RepoPaths{ repoPaths := RepoPaths{
worktreePath: "/path/to/worktree", worktreePath: "/path/to/worktree",

View File

@ -676,12 +676,11 @@ type AppState struct {
// For backwards compatibility we keep the old name in yaml files. // For backwards compatibility we keep the old name in yaml files.
ShellCommandsHistory []string `yaml:"customcommandshistory"` ShellCommandsHistory []string `yaml:"customcommandshistory"`
HideCommandLog bool HideCommandLog bool
IgnoreWhitespaceInDiffView bool DiffContextSize uint64
DiffContextSize uint64 RenameSimilarityThreshold int
RenameSimilarityThreshold int LocalBranchSortOrder string
LocalBranchSortOrder string RemoteBranchSortOrder string
RemoteBranchSortOrder string
// One of: 'date-order' | 'author-date-order' | 'topo-order' | 'default' // One of: 'date-order' | 'author-date-order' | 'topo-order' | 'default'
// 'topo-order' makes it easier to read the git log graph, but commits may not // 'topo-order' makes it easier to read the git log graph, but commits may not

View File

@ -264,6 +264,8 @@ type GitConfig struct {
BranchLogCmd string `yaml:"branchLogCmd"` BranchLogCmd string `yaml:"branchLogCmd"`
// Commands used to display git log of all branches in the main window, they will be cycled in order of appearance (array of strings) // Commands used to display git log of all branches in the main window, they will be cycled in order of appearance (array of strings)
AllBranchesLogCmds []string `yaml:"allBranchesLogCmds"` AllBranchesLogCmds []string `yaml:"allBranchesLogCmds"`
// If true, git diffs are rendered with the `--ignore-all-space` flag, which ignores whitespace changes. Can be toggled from within Lazygit with `<c-w>`.
IgnoreWhitespaceInDiffView bool `yaml:"ignoreWhitespaceInDiffView"`
// If true, do not spawn a separate process when using GPG // If true, do not spawn a separate process when using GPG
OverrideGpg bool `yaml:"overrideGpg"` OverrideGpg bool `yaml:"overrideGpg"`
// If true, do not allow force pushes // If true, do not allow force pushes
@ -808,6 +810,7 @@ func GetDefaultConfig() *UserConfig {
AutoStageResolvedConflicts: true, AutoStageResolvedConflicts: true,
BranchLogCmd: "git log --graph --color=always --abbrev-commit --decorate --date=relative --pretty=medium {{branchName}} --", BranchLogCmd: "git log --graph --color=always --abbrev-commit --decorate --date=relative --pretty=medium {{branchName}} --",
AllBranchesLogCmds: []string{"git log --graph --all --color=always --abbrev-commit --decorate --date=relative --pretty=medium"}, AllBranchesLogCmds: []string{"git log --graph --all --color=always --abbrev-commit --decorate --date=relative --pretty=medium"},
IgnoreWhitespaceInDiffView: false,
DisableForcePushing: false, DisableForcePushing: false,
CommitPrefixes: map[string][]CommitPrefixConfig(nil), CommitPrefixes: map[string][]CommitPrefixConfig(nil),
BranchPrefix: "", BranchPrefix: "",

View File

@ -144,7 +144,7 @@ func (self *DiffHelper) WithDiffModeCheck(f func()) {
} }
func (self *DiffHelper) IgnoringWhitespaceSubTitle() string { func (self *DiffHelper) IgnoringWhitespaceSubTitle() string {
if self.c.GetAppState().IgnoreWhitespaceInDiffView { if self.c.UserConfig().Git.IgnoreWhitespaceInDiffView {
return self.c.Tr.IgnoreWhitespaceDiffViewSubTitle return self.c.Tr.IgnoreWhitespaceDiffViewSubTitle
} }

View File

@ -25,8 +25,7 @@ func (self *ToggleWhitespaceAction) Call() error {
return errors.New(self.c.Tr.IgnoreWhitespaceNotSupportedHere) return errors.New(self.c.Tr.IgnoreWhitespaceNotSupportedHere)
} }
self.c.GetAppState().IgnoreWhitespaceInDiffView = !self.c.GetAppState().IgnoreWhitespaceInDiffView self.c.UserConfig().Git.IgnoreWhitespaceInDiffView = !self.c.UserConfig().Git.IgnoreWhitespaceInDiffView
self.c.SaveAppStateAndLogError()
self.c.Context().CurrentSide().HandleFocus(types.OnFocusOpts{}) self.c.Context().CurrentSide().HandleFocus(types.OnFocusOpts{})
return nil return nil

View File

@ -359,6 +359,11 @@
"git log --graph --all --color=always --abbrev-commit --decorate --date=relative --pretty=medium" "git log --graph --all --color=always --abbrev-commit --decorate --date=relative --pretty=medium"
] ]
}, },
"ignoreWhitespaceInDiffView": {
"type": "boolean",
"description": "If true, git diffs are rendered with the `--ignore-all-space` flag, which ignores whitespace changes. Can be toggled from within Lazygit with `\u003cc-w\u003e`.",
"default": false
},
"overrideGpg": { "overrideGpg": {
"type": "boolean", "type": "boolean",
"description": "If true, do not spawn a separate process when using GPG", "description": "If true, do not spawn a separate process when using GPG",