1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-28 16:02:01 +03:00

Don't pass ignoreWhitespace to git commands

Now that AppState is available via common.Common, they can take it from there.
This commit is contained in:
Stefan Haller
2023-08-28 12:39:52 +02:00
parent 18c5780485
commit 1dac4158e9
16 changed files with 40 additions and 45 deletions

View File

@ -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)

View File

@ -196,7 +196,7 @@ 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.UserConfig.Git.DiffContextSize
extDiffCmd := self.UserConfig.Git.Paging.ExternalDiffCommand extDiffCmd := self.UserConfig.Git.Paging.ExternalDiffCommand
@ -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()

View File

@ -239,11 +239,13 @@ func TestCommitShowCmdObj(t *testing.T) {
userConfig := config.GetDefaultConfig() userConfig := config.GetDefaultConfig()
userConfig.Git.DiffContextSize = s.contextSize userConfig.Git.DiffContextSize = s.contextSize
userConfig.Git.Paging.ExternalDiffCommand = s.extDiffCmd userConfig.Git.Paging.ExternalDiffCommand = s.extDiffCmd
appState := &config.AppState{}
appState.IgnoreWhitespaceInDiffView = s.ignoreWhitespace
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()
}) })
} }

View File

@ -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.UserConfig.Git.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()

View File

@ -135,9 +135,11 @@ func TestStashStashEntryCmdObj(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.DiffContextSize = s.contextSize userConfig.Git.DiffContextSize = s.contextSize
instance := buildStashCommands(commonDeps{userConfig: userConfig}) appState := &config.AppState{}
appState.IgnoreWhitespaceInDiffView = s.ignoreWhitespace
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)
}) })
} }

View File

@ -228,13 +228,13 @@ 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"
@ -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,15 +266,11 @@ 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,
) oscommands.ICmdObj {
contextSize := self.UserConfig.Git.DiffContextSize contextSize := self.UserConfig.Git.DiffContextSize
colorArg := self.UserConfig.Git.Paging.ColorArg colorArg := self.UserConfig.Git.Paging.ColorArg
@ -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()

View File

@ -310,9 +310,11 @@ func TestWorkingTreeDiff(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.DiffContextSize = s.contextSize userConfig.Git.DiffContextSize = s.contextSize
appState := &config.AppState{}
appState.IgnoreWhitespaceInDiffView = s.ignoreWhitespace
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()
}) })
@ -374,10 +376,12 @@ func TestWorkingTreeShowFileDiff(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.DiffContextSize = s.contextSize userConfig.Git.DiffContextSize = s.contextSize
appState := &config.AppState{}
appState.IgnoreWhitespaceInDiffView = s.ignoreWhitespace
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()

View File

@ -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

View File

@ -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 {

View File

@ -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
} }

View File

@ -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

View File

@ -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())
} }

View File

@ -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())
} }

View File

@ -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(),
) )
} }

View File

@ -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())
} }

View File

@ -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)
} }
} }