diff --git a/pkg/commands/git.go b/pkg/commands/git.go index 5904dfe4d..bfe19b85f 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -135,8 +135,10 @@ func NewGitCommandAux( rebaseCommands := git_commands.NewRebaseCommands(gitCommon, commitCommands, workingTreeCommands) stashCommands := git_commands.NewStashCommands(gitCommon, fileLoader, workingTreeCommands) patchBuilder := patch.NewPatchBuilder(cmn.Log, - func(from string, to string, reverse bool, filename string, previousPath string, plain bool) (string, error) { - return workingTreeCommands.ShowFileDiff(from, to, reverse, filename, previousPath, plain) + func(from string, to string, reverse bool, filename string, previousPath string) (string, error) { + // A patch is built from git's own diff: what a diff renderer would make of it + // is a picture of it, not something that can be applied. + return workingTreeCommands.ShowFileDiff(from, to, reverse, filename, previousPath, git_commands.DiffModePlain) }) patchCommands := git_commands.NewPatchCommands(gitCommon, rebaseCommands, commitCommands, statusCommands, stashCommands, patchBuilder) bisectCommands := git_commands.NewBisectCommands(gitCommon) diff --git a/pkg/commands/git_commands/commit.go b/pkg/commands/git_commands/commit.go index d067e9831..387a1fdc7 100644 --- a/pkg/commands/git_commands/commit.go +++ b/pkg/commands/git_commands/commit.go @@ -240,12 +240,12 @@ func (self *CommitCommands) AmendHeadCmdObj() *oscommands.CmdObj { return self.cmd.New(cmdArgs) } -func (self *CommitCommands) ShowCmdObj(hash string, filterPaths []string) *oscommands.CmdObj { +func (self *CommitCommands) ShowCmdObj(hash string, filterPaths []string, mode DiffMode) *oscommands.CmdObj { cmdArgs := NewGitCmd("show"). Config("diff.noprefix=false"). - AddCommonDiffArgs(self.diffRendererConfigManager, self.UserConfig(), true). + AddCommonDiffArgs(self.diffRendererConfigManager, self.UserConfig(), mode). Arg("--submodule"). - Arg("--color=" + self.diffRendererConfigManager.GetColorArg()). + Arg("--color=" + mode.colorArg(self.diffRendererConfigManager)). Arg("--stat"). Arg("--decorate"). Arg("-p"). diff --git a/pkg/commands/git_commands/commit_test.go b/pkg/commands/git_commands/commit_test.go index 4381ccb5f..274385f53 100644 --- a/pkg/commands/git_commands/commit_test.go +++ b/pkg/commands/git_commands/commit_test.go @@ -341,7 +341,7 @@ func TestCommitShowCmdObj(t *testing.T) { } instance := buildCommitCommands(commonDeps{userConfig: userConfig, appState: &config.AppState{}, runner: runner, repoPaths: &repoPaths}) - assert.NoError(t, instance.ShowCmdObj("1234567890", s.filterPaths).Run()) + assert.NoError(t, instance.ShowCmdObj("1234567890", s.filterPaths, DiffModeRendered).Run()) runner.CheckForMissingCalls() }) } diff --git a/pkg/commands/git_commands/diff.go b/pkg/commands/git_commands/diff.go index d532f1bbb..daf710eaa 100644 --- a/pkg/commands/git_commands/diff.go +++ b/pkg/commands/git_commands/diff.go @@ -18,13 +18,13 @@ func NewDiffCommands(gitCommon *GitCommon) *DiffCommands { // This is for generating diffs to be shown in the UI (e.g. rendering a range // diff to the main view). It uses a custom diff renderer if one is configured. -func (self *DiffCommands) DiffCmdObj(diffArgs []string) *oscommands.CmdObj { +func (self *DiffCommands) DiffCmdObj(diffArgs []string, mode DiffMode) *oscommands.CmdObj { return self.cmd.New( NewGitCmd("diff"). Config("diff.noprefix=false"). - AddCommonDiffArgs(self.diffRendererConfigManager, self.UserConfig(), true). + AddCommonDiffArgs(self.diffRendererConfigManager, self.UserConfig(), mode). Arg("--submodule"). - Arg(fmt.Sprintf("--color=%s", self.diffRendererConfigManager.GetColorArg())). + Arg(fmt.Sprintf("--color=%s", mode.colorArg(self.diffRendererConfigManager))). Arg(diffArgs...). Dir(self.repoPaths.worktreePath). ToArgv(), diff --git a/pkg/commands/git_commands/diff_mode.go b/pkg/commands/git_commands/diff_mode.go new file mode 100644 index 000000000..ed3724ef1 --- /dev/null +++ b/pkg/commands/git_commands/diff_mode.go @@ -0,0 +1,35 @@ +package git_commands + +import ( + "github.com/jesseduffield/lazygit/pkg/config" +) + +// DiffMode says what a diff command's output is for. This decides whether the +// configured diff renderer produces it, and whether it is coloured. +type DiffMode int + +const ( + // DiffModeRendered is the diff as the user has arranged for it to look: through the + // diff renderer, with the renderer's own arguments and its preference about colour. + DiffModeRendered DiffMode = iota + // DiffModeRaw is git's own coloured diff, for showing a diff whose rendered form + // couldn't be acted on. + DiffModeRaw + // DiffModePlain is git's own uncoloured diff, for building patches from and copying + // text out of rather than for looking at. + DiffModePlain +) + +// colorArg returns the value to pass to git's --color for this mode. Rendered output is +// coloured however the renderer wants its input; a raw diff gets git's own colour, which +// is the point of it; a plain one is for reading as text, not for looking at. +func (self DiffMode) colorArg(diffRendererConfigManager *config.DiffRendererConfigManager) string { + switch self { + case DiffModeRendered: + return diffRendererConfigManager.GetColorArg() + case DiffModeRaw: + return "always" + default: + return "never" + } +} diff --git a/pkg/commands/git_commands/git_command_builder.go b/pkg/commands/git_commands/git_command_builder.go index 683d46a6f..fe7a6d075 100644 --- a/pkg/commands/git_commands/git_command_builder.go +++ b/pkg/commands/git_commands/git_command_builder.go @@ -123,16 +123,21 @@ func (self *GitCommandBuilder) GitDirIf(condition bool, path string) *GitCommand return self } -func (self *GitCommandBuilder) AddCommonDiffArgs(diffRendererConfigManager *config.DiffRendererConfigManager, userConfig *config.UserConfig, forUI bool) *GitCommandBuilder { +func (self *GitCommandBuilder) AddCommonDiffArgs(diffRendererConfigManager *config.DiffRendererConfigManager, userConfig *config.UserConfig, mode DiffMode) *GitCommandBuilder { contextSize := userConfig.Git.DiffContextSize - useExtDiff := forUI && diffRendererConfigManager.GetDiffRendererType() == config.DiffRendererType_ExtDiff + useExtDiff := mode == DiffModeRendered && diffRendererConfigManager.GetDiffRendererType() == config.DiffRendererType_ExtDiff return self. ArgIfElse(useExtDiff, "--ext-diff", "--no-ext-diff"). Arg(fmt.Sprintf("--unified=%d", contextSize)). - ArgIf(forUI && userConfig.Git.IgnoreWhitespaceInDiffView, "--ignore-all-space"). + // Ignoring whitespace is about what the user wants to see, so it holds for a raw + // diff as much as for a rendered one. Patches are built from a plain diff, + // where a diff that leaves changes out would apply to nothing. + ArgIf(mode != DiffModePlain && userConfig.Git.IgnoreWhitespaceInDiffView, "--ignore-all-space"). Arg(fmt.Sprintf("--find-renames=%d%%", userConfig.Git.RenameSimilarityThreshold)). - ArgIf(forUI, diffRendererConfigManager.GetRawGitArgs()...) + // The renderer's own arguments to git — a word diff, say — are part of the + // rendering, so they go with it. + ArgIf(mode == DiffModeRendered, diffRendererConfigManager.GetRawGitArgs()...) } func (self *GitCommandBuilder) ToArgv() []string { diff --git a/pkg/commands/git_commands/stash.go b/pkg/commands/git_commands/stash.go index ea23c5141..f904a7ac4 100644 --- a/pkg/commands/git_commands/stash.go +++ b/pkg/commands/git_commands/stash.go @@ -80,14 +80,14 @@ func (self *StashCommands) Hash(index int) (string, error) { return strings.Trim(hash, "\r\n"), err } -func (self *StashCommands) ShowStashEntryCmdObj(index int) *oscommands.CmdObj { +func (self *StashCommands) ShowStashEntryCmdObj(index int, mode DiffMode) *oscommands.CmdObj { // "-u" is the same as "--include-untracked", but the latter fails in older git versions for some reason cmdArgs := NewGitCmd("stash").Arg("show"). - AddCommonDiffArgs(self.diffRendererConfigManager, self.UserConfig(), true). + AddCommonDiffArgs(self.diffRendererConfigManager, self.UserConfig(), mode). Arg("-p"). Arg("--stat"). Arg("-u"). - Arg(fmt.Sprintf("--color=%s", self.diffRendererConfigManager.GetColorArg())). + Arg(fmt.Sprintf("--color=%s", mode.colorArg(self.diffRendererConfigManager))). Arg(fmt.Sprintf("refs/stash@{%d}", index)). Dir(self.repoPaths.worktreePath). ToArgv() diff --git a/pkg/commands/git_commands/stash_test.go b/pkg/commands/git_commands/stash_test.go index 91eb846ed..35b687cbd 100644 --- a/pkg/commands/git_commands/stash_test.go +++ b/pkg/commands/git_commands/stash_test.go @@ -174,7 +174,7 @@ func TestStashStashEntryCmdObj(t *testing.T) { } instance := buildStashCommands(commonDeps{userConfig: userConfig, appState: &config.AppState{}, repoPaths: &repoPaths}) - cmdStr := instance.ShowStashEntryCmdObj(s.index).Args() + cmdStr := instance.ShowStashEntryCmdObj(s.index, DiffModeRendered).Args() assert.Equal(t, s.expected, cmdStr) }) } diff --git a/pkg/commands/git_commands/working_tree.go b/pkg/commands/git_commands/working_tree.go index 1ab37fa6a..4f4a19a89 100644 --- a/pkg/commands/git_commands/working_tree.go +++ b/pkg/commands/git_commands/working_tree.go @@ -383,9 +383,9 @@ func (self *WorkingTreeCommands) Exclude(filename string) error { } // WorktreeFileDiff returns the diff of a file -func (self *WorkingTreeCommands) WorktreeFileDiff(file *models.File, plain bool, cached bool) string { +func (self *WorkingTreeCommands) WorktreeFileDiff(file *models.File, mode DiffMode, cached bool) string { // for now we assume an error means the file was deleted - s, _ := self.WorktreeFileDiffCmdObj(file, plain, cached, file.Names()).RunWithOutput() + s, _ := self.WorktreeFileDiffCmdObj(file, mode, cached, file.Names()).RunWithOutput() return s } @@ -393,18 +393,13 @@ func (self *WorkingTreeCommands) WorktreeFileDiff(file *models.File, plain bool, // in the working tree. node is the item they belong to; all it decides is // whether git has to compare against /dev/null, which is the case for a file // that isn't in the index yet. -func (self *WorkingTreeCommands) WorktreeFileDiffCmdObj(node models.IFile, plain bool, cached bool, paths []string) *oscommands.CmdObj { - colorArg := self.diffRendererConfigManager.GetColorArg() - if plain { - colorArg = "never" - } - +func (self *WorkingTreeCommands) WorktreeFileDiffCmdObj(node models.IFile, mode DiffMode, cached bool, paths []string) *oscommands.CmdObj { noIndex := !node.GetIsTracked() && !node.GetHasStagedChanges() && !cached && node.GetIsFile() cmdArgs := NewGitCmd("diff"). - AddCommonDiffArgs(self.diffRendererConfigManager, self.UserConfig(), !plain). + AddCommonDiffArgs(self.diffRendererConfigManager, self.UserConfig(), mode). Arg("--submodule"). - Arg(fmt.Sprintf("--color=%s", colorArg)). + Arg(fmt.Sprintf("--color=%s", mode.colorArg(self.diffRendererConfigManager))). ArgIf(cached, "--cached"). ArgIf(noIndex, "--no-index"). Arg("--"). @@ -420,25 +415,20 @@ func (self *WorkingTreeCommands) WorktreeFileDiffCmdObj(node models.IFile, plain // 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. // For a renamed file, previousPath is the path it was renamed from (empty otherwise); // both paths must be passed to git for the rename to be detected. -func (self *WorkingTreeCommands) ShowFileDiff(from string, to string, reverse bool, fileName string, previousPath string, plain bool) (string, error) { +func (self *WorkingTreeCommands) ShowFileDiff(from string, to string, reverse bool, fileName string, previousPath string, mode DiffMode) (string, error) { fileNames := []string{fileName} if previousPath != "" { fileNames = append(fileNames, previousPath) } - return self.ShowFileDiffCmdObj(from, to, reverse, fileNames, plain).RunWithOutput() + return self.ShowFileDiffCmdObj(from, to, reverse, fileNames, mode).RunWithOutput() } -func (self *WorkingTreeCommands) ShowFileDiffCmdObj(from string, to string, reverse bool, fileNames []string, plain bool) *oscommands.CmdObj { - colorArg := self.diffRendererConfigManager.GetColorArg() - if plain { - colorArg = "never" - } - +func (self *WorkingTreeCommands) ShowFileDiffCmdObj(from string, to string, reverse bool, fileNames []string, mode DiffMode) *oscommands.CmdObj { cmdArgs := NewGitCmd("diff"). Config("diff.noprefix=false"). - AddCommonDiffArgs(self.diffRendererConfigManager, self.UserConfig(), !plain). + AddCommonDiffArgs(self.diffRendererConfigManager, self.UserConfig(), mode). Arg("--submodule"). - Arg(fmt.Sprintf("--color=%s", colorArg)). + Arg(fmt.Sprintf("--color=%s", mode.colorArg(self.diffRendererConfigManager))). Arg(from). Arg(to). ArgIf(reverse, "-R"). diff --git a/pkg/commands/git_commands/working_tree_test.go b/pkg/commands/git_commands/working_tree_test.go index 5b87a1320..e9e5e48d2 100644 --- a/pkg/commands/git_commands/working_tree_test.go +++ b/pkg/commands/git_commands/working_tree_test.go @@ -197,7 +197,7 @@ func TestWorkingTreeDiff(t *testing.T) { type scenario struct { testName string file *models.File - plain bool + mode DiffMode cached bool ignoreWhitespace bool contextSize uint64 @@ -215,7 +215,7 @@ func TestWorkingTreeDiff(t *testing.T) { HasStagedChanges: false, Tracked: true, }, - plain: false, + mode: DiffModeRendered, cached: false, ignoreWhitespace: false, contextSize: 3, @@ -230,7 +230,7 @@ func TestWorkingTreeDiff(t *testing.T) { HasStagedChanges: false, Tracked: true, }, - plain: false, + mode: DiffModeRendered, cached: true, ignoreWhitespace: false, contextSize: 3, @@ -245,7 +245,7 @@ func TestWorkingTreeDiff(t *testing.T) { HasStagedChanges: false, Tracked: true, }, - plain: true, + mode: DiffModePlain, cached: false, ignoreWhitespace: false, contextSize: 3, @@ -260,7 +260,7 @@ func TestWorkingTreeDiff(t *testing.T) { HasStagedChanges: false, Tracked: false, }, - plain: false, + mode: DiffModeRendered, cached: false, ignoreWhitespace: false, contextSize: 3, @@ -275,7 +275,7 @@ func TestWorkingTreeDiff(t *testing.T) { HasStagedChanges: false, Tracked: true, }, - plain: false, + mode: DiffModeRendered, cached: false, ignoreWhitespace: true, contextSize: 3, @@ -290,7 +290,7 @@ func TestWorkingTreeDiff(t *testing.T) { HasStagedChanges: false, Tracked: true, }, - plain: false, + mode: DiffModeRendered, cached: false, ignoreWhitespace: false, contextSize: 17, @@ -305,7 +305,7 @@ func TestWorkingTreeDiff(t *testing.T) { HasStagedChanges: false, Tracked: true, }, - plain: false, + mode: DiffModeRendered, cached: false, ignoreWhitespace: false, contextSize: 3, @@ -326,7 +326,7 @@ func TestWorkingTreeDiff(t *testing.T) { } instance := buildWorkingTreeCommands(commonDeps{runner: s.runner, userConfig: userConfig, appState: &config.AppState{}, repoPaths: &repoPaths}) - result := instance.WorktreeFileDiff(s.file, s.plain, s.cached) + result := instance.WorktreeFileDiff(s.file, s.mode, s.cached) assert.Equal(t, expectedResult, result) s.runner.CheckForMissingCalls() }) @@ -341,7 +341,7 @@ func TestWorkingTreeShowFileDiff(t *testing.T) { reverse bool fileName string previousPath string - plain bool + mode DiffMode ignoreWhitespace bool contextSize uint64 runner *oscommands.FakeCmdObjRunner @@ -356,7 +356,7 @@ func TestWorkingTreeShowFileDiff(t *testing.T) { to: "0987654321", reverse: false, fileName: "test.txt", - plain: false, + mode: DiffModeRendered, ignoreWhitespace: false, contextSize: 3, runner: oscommands.NewFakeRunner(t). @@ -368,7 +368,7 @@ func TestWorkingTreeShowFileDiff(t *testing.T) { to: "0987654321", reverse: false, fileName: "test.txt", - plain: false, + mode: DiffModeRendered, ignoreWhitespace: false, contextSize: 123, runner: oscommands.NewFakeRunner(t). @@ -380,7 +380,7 @@ func TestWorkingTreeShowFileDiff(t *testing.T) { to: "0987654321", reverse: false, fileName: "test.txt", - plain: false, + mode: DiffModeRendered, ignoreWhitespace: true, contextSize: 3, runner: oscommands.NewFakeRunner(t). @@ -393,7 +393,7 @@ func TestWorkingTreeShowFileDiff(t *testing.T) { reverse: false, fileName: "new.txt", previousPath: "old.txt", - plain: false, + mode: DiffModeRendered, ignoreWhitespace: false, contextSize: 3, runner: oscommands.NewFakeRunner(t). @@ -412,7 +412,7 @@ func TestWorkingTreeShowFileDiff(t *testing.T) { instance := buildWorkingTreeCommands(commonDeps{runner: s.runner, userConfig: userConfig, appState: &config.AppState{}, repoPaths: &repoPaths}) - result, err := instance.ShowFileDiff(s.from, s.to, s.reverse, s.fileName, s.previousPath, s.plain) + result, err := instance.ShowFileDiff(s.from, s.to, s.reverse, s.fileName, s.previousPath, s.mode) assert.NoError(t, err) assert.Equal(t, expectedResult, result) s.runner.CheckForMissingCalls() diff --git a/pkg/commands/patch/patch_builder.go b/pkg/commands/patch/patch_builder.go index 0d5ca34f8..78c539e86 100644 --- a/pkg/commands/patch/patch_builder.go +++ b/pkg/commands/patch/patch_builder.go @@ -33,7 +33,7 @@ type fileInfo struct { } type ( - loadFileDiffFunc func(from string, to string, reverse bool, filename string, previousPath string, plain bool) (string, error) + loadFileDiffFunc func(from string, to string, reverse bool, filename string, previousPath string) (string, error) ) // PatchBuilder manages the building of a patch for a commit to be applied to another commit (or the working tree, or removed from the current commit). We also support building patches from things like stashes, for which there is less flexibility @@ -162,7 +162,7 @@ func (p *PatchBuilder) getFileInfo(filename string, previousPath string) (*fileI return info, nil } - diff, err := p.loadFileDiff(from, to, reverse, filename, previousPath, true) + diff, err := p.loadFileDiff(from, to, reverse, filename, previousPath) if err != nil { return nil, err } diff --git a/pkg/gui/controllers/commits_files_controller.go b/pkg/gui/controllers/commits_files_controller.go index 2e31ad906..f59056da1 100644 --- a/pkg/gui/controllers/commits_files_controller.go +++ b/pkg/gui/controllers/commits_files_controller.go @@ -176,7 +176,7 @@ func (self *CommitFilesController) GetOnRenderToMain() func() { from, reverse := self.c.Modes().Diffing.GetFromAndReverseArgsForDiff(from) paths := self.pathsForDiff(node) - cmdObj := self.c.Git().WorkingTree.ShowFileDiffCmdObj(from, to, reverse, paths, false) + cmdObj := self.c.Git().WorkingTree.ShowFileDiffCmdObj(from, to, reverse, paths, git_commands.DiffModeRendered) task := types.NewRunDiffRendererTask(cmdObj.GetCmd()) self.c.RenderToMainViews(types.RefreshMainOpts{ @@ -207,7 +207,7 @@ func (self *CommitFilesController) copyDiffToClipboard(paths []string, toastMess from, to := self.context().GetFromAndToForDiff() from, reverse := self.c.Modes().Diffing.GetFromAndReverseArgsForDiff(from) - cmdObj := self.c.Git().WorkingTree.ShowFileDiffCmdObj(from, to, reverse, paths, true) + cmdObj := self.c.Git().WorkingTree.ShowFileDiffCmdObj(from, to, reverse, paths, git_commands.DiffModePlain) diff, err := cmdObj.RunWithOutput() if err != nil { return err diff --git a/pkg/gui/controllers/files_controller.go b/pkg/gui/controllers/files_controller.go index 93bc6f379..2b9f37064 100644 --- a/pkg/gui/controllers/files_controller.go +++ b/pkg/gui/controllers/files_controller.go @@ -352,7 +352,7 @@ func (self *FilesController) renderNonTextualConflict(node *filetree.FileNode) { message := self.conflictResolutionHint(node.File.GetMergeStateDescription(self.c.Tr)) if node.File.ShortStatus == "DU" || node.File.ShortStatus == "UD" { - cmdObj := self.c.Git().Diff.DiffCmdObj([]string{"--base", "--", node.GetPath()}) + cmdObj := self.c.Git().Diff.DiffCmdObj([]string{"--base", "--", node.GetPath()}, git_commands.DiffModeRendered) prefix := message + "\n\n" if node.File.ShortStatus == "DU" { prefix += self.c.Tr.MergeConflictIncomingDiff @@ -384,7 +384,7 @@ func (self *FilesController) renderWorkingTreeDiff(node *filetree.FileNode) { refreshOpts := types.RefreshMainOpts{Pair: self.c.MainViewPairs().Normal} if showUnstaged { - cmdObj := self.c.Git().WorkingTree.WorktreeFileDiffCmdObj(node, false, false, paths) + cmdObj := self.c.Git().WorkingTree.WorktreeFileDiffCmdObj(node, git_commands.DiffModeRendered, false, paths) refreshOpts.Main = &types.ViewUpdateOpts{ Task: types.NewRunDiffRendererTask(cmdObj.GetCmd()), SubTitle: self.c.Helpers().Diff.IgnoringWhitespaceSubTitle(), @@ -394,7 +394,7 @@ func (self *FilesController) renderWorkingTreeDiff(node *filetree.FileNode) { } if showStaged { - cmdObj := self.c.Git().WorkingTree.WorktreeFileDiffCmdObj(node, false, true, paths) + cmdObj := self.c.Git().WorkingTree.WorktreeFileDiffCmdObj(node, git_commands.DiffModeRendered, true, paths) refreshOpts.Secondary = &types.ViewUpdateOpts{ Task: types.NewRunDiffRendererTask(cmdObj.GetCmd()), SubTitle: self.c.Helpers().Diff.IgnoringWhitespaceSubTitle(), diff --git a/pkg/gui/controllers/helpers/diff_helper.go b/pkg/gui/controllers/helpers/diff_helper.go index c5d88f39b..3a8306fc2 100644 --- a/pkg/gui/controllers/helpers/diff_helper.go +++ b/pkg/gui/controllers/helpers/diff_helper.go @@ -74,12 +74,12 @@ func (self *DiffHelper) GetUpdateTaskForRenderingCommitsDiff(commit *models.Comm args = append(args, filterPath) } } - cmdObj := self.c.Git().Diff.DiffCmdObj(args) + cmdObj := self.c.Git().Diff.DiffCmdObj(args, git_commands.DiffModeRendered) prefix := style.FgYellow.Sprintf("%s %s-%s\n\n", self.c.Tr.ShowingDiffForRange, from.ShortRefName(), to.ShortRefName()) return types.NewRunDiffRendererTaskWithPrefix(cmdObj.GetCmd(), prefix) } - cmdObj := self.c.Git().Commit.ShowCmdObj(commit.Hash(), self.FilterPathsForCommit(commit)) + cmdObj := self.c.Git().Commit.ShowCmdObj(commit.Hash(), self.FilterPathsForCommit(commit), git_commands.DiffModeRendered) return types.NewRunDiffRendererTask(cmdObj.GetCmd()) } @@ -92,7 +92,7 @@ func (self *DiffHelper) PlainDiffBetweenRefs(from string, to string, paths []str from, reverse := self.c.Modes().Diffing.GetFromAndReverseArgsForDiff(from) // An error means there is no diff to be had, which for our purposes is the same // as an empty one. - diff, _ := self.c.Git().WorkingTree.ShowFileDiffCmdObj(from, to, reverse, paths, true).RunWithOutput() + diff, _ := self.c.Git().WorkingTree.ShowFileDiffCmdObj(from, to, reverse, paths, git_commands.DiffModePlain).RunWithOutput() return diff } @@ -133,7 +133,7 @@ func (self *DiffHelper) RenderToMainAgain() { func (self *DiffHelper) RenderDiff() { args := self.DiffArgs() - cmdObj := self.c.Git().Diff.DiffCmdObj(args) + cmdObj := self.c.Git().Diff.DiffCmdObj(args, git_commands.DiffModeRendered) prefix := style.FgMagenta.Sprintf( "%s %s\n\n", self.c.Tr.ShowingGitDiff, diff --git a/pkg/gui/controllers/helpers/patch_building_helper.go b/pkg/gui/controllers/helpers/patch_building_helper.go index ac79ee8d7..d8288df4f 100644 --- a/pkg/gui/controllers/helpers/patch_building_helper.go +++ b/pkg/gui/controllers/helpers/patch_building_helper.go @@ -3,6 +3,8 @@ package helpers import ( "fmt" + "github.com/jesseduffield/lazygit/pkg/commands/git_commands" + "github.com/jesseduffield/lazygit/pkg/commands/patch" "github.com/jesseduffield/lazygit/pkg/gui/patch_exploring" "github.com/jesseduffield/lazygit/pkg/gui/types" @@ -73,7 +75,7 @@ func (self *PatchBuildingHelper) RefreshPatchBuildingPanel(opts types.OnFocusOpt from, to := self.c.Contexts().CommitFiles.GetFromAndToForDiff() from, reverse := self.c.Modes().Diffing.GetFromAndReverseArgsForDiff(from) - diff, err := self.c.Git().WorkingTree.ShowFileDiff(from, to, reverse, file.Path, file.PreviousPath, true) + diff, err := self.c.Git().WorkingTree.ShowFileDiff(from, to, reverse, file.Path, file.PreviousPath, git_commands.DiffModePlain) if err != nil { return } diff --git a/pkg/gui/controllers/helpers/staging_helper.go b/pkg/gui/controllers/helpers/staging_helper.go index 55b9c133b..071c1d4be 100644 --- a/pkg/gui/controllers/helpers/staging_helper.go +++ b/pkg/gui/controllers/helpers/staging_helper.go @@ -1,6 +1,7 @@ package helpers import ( + "github.com/jesseduffield/lazygit/pkg/commands/git_commands" "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/gui/patch_exploring" "github.com/jesseduffield/lazygit/pkg/gui/types" @@ -53,8 +54,8 @@ func (self *StagingHelper) RefreshStagingPanel(focusOpts types.OnFocusOpts) { return } - mainDiff := self.c.Git().WorkingTree.WorktreeFileDiff(file, true, false) - secondaryDiff := self.c.Git().WorkingTree.WorktreeFileDiff(file, true, true) + mainDiff := self.c.Git().WorkingTree.WorktreeFileDiff(file, git_commands.DiffModePlain, false) + secondaryDiff := self.c.Git().WorkingTree.WorktreeFileDiff(file, git_commands.DiffModePlain, true) // grabbing locks here and releasing before we finish the function // because pushing say the secondary context could mean entering this function diff --git a/pkg/gui/controllers/reflog_commits_controller.go b/pkg/gui/controllers/reflog_commits_controller.go index a0a008105..bd000214f 100644 --- a/pkg/gui/controllers/reflog_commits_controller.go +++ b/pkg/gui/controllers/reflog_commits_controller.go @@ -1,6 +1,7 @@ package controllers import ( + "github.com/jesseduffield/lazygit/pkg/commands/git_commands" "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/gui/context" "github.com/jesseduffield/lazygit/pkg/gui/types" @@ -59,7 +60,7 @@ func (self *ReflogCommitsController) GetOnRenderToMain() func() { if commit == nil { task = types.NewRenderStringTask("No reflog history") } else { - cmdObj := self.c.Git().Commit.ShowCmdObj(commit.Hash(), self.c.Helpers().Diff.FilterPathsForCommit(commit)) + cmdObj := self.c.Git().Commit.ShowCmdObj(commit.Hash(), self.c.Helpers().Diff.FilterPathsForCommit(commit), git_commands.DiffModeRendered) task = types.NewRunDiffRendererTask(cmdObj.GetCmd()) } diff --git a/pkg/gui/controllers/stash_controller.go b/pkg/gui/controllers/stash_controller.go index 79a2bcd20..762090ae6 100644 --- a/pkg/gui/controllers/stash_controller.go +++ b/pkg/gui/controllers/stash_controller.go @@ -3,6 +3,8 @@ package controllers import ( "fmt" + "github.com/jesseduffield/lazygit/pkg/commands/git_commands" + "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/gocui" "github.com/jesseduffield/lazygit/pkg/gui/context" @@ -94,7 +96,7 @@ func (self *StashController) GetOnRenderToMain() func() { } else { prefix := style.FgYellow.Sprintf("%s\n\n", stashEntry.Description()) task = types.NewRunDiffRendererTaskWithPrefix( - self.c.Git().Stash.ShowStashEntryCmdObj(stashEntry.Index).GetCmd(), + self.c.Git().Stash.ShowStashEntryCmdObj(stashEntry.Index, git_commands.DiffModeRendered).GetCmd(), prefix, ) } diff --git a/pkg/gui/controllers/submodules_controller.go b/pkg/gui/controllers/submodules_controller.go index 82ca509ca..c807e6352 100644 --- a/pkg/gui/controllers/submodules_controller.go +++ b/pkg/gui/controllers/submodules_controller.go @@ -5,6 +5,8 @@ import ( "path/filepath" "strings" + "github.com/jesseduffield/lazygit/pkg/commands/git_commands" + "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/gocui" "github.com/jesseduffield/lazygit/pkg/gui/context" @@ -123,7 +125,7 @@ func (self *SubmodulesController) GetOnRenderToMain() func() { if file == nil { task = types.NewRenderStringTask(prefix) } else { - cmdObj := self.c.Git().WorkingTree.WorktreeFileDiffCmdObj(file, false, !file.HasUnstagedChanges && file.HasStagedChanges, file.Names()) + cmdObj := self.c.Git().WorkingTree.WorktreeFileDiffCmdObj(file, git_commands.DiffModeRendered, !file.HasUnstagedChanges && file.HasStagedChanges, file.Names()) task = types.NewRunCommandTaskWithPrefix(cmdObj.GetCmd(), prefix) } } diff --git a/pkg/gui/controllers/working_tree_diff_actions.go b/pkg/gui/controllers/working_tree_diff_actions.go index 4b2b8bf7f..5086f5ca8 100644 --- a/pkg/gui/controllers/working_tree_diff_actions.go +++ b/pkg/gui/controllers/working_tree_diff_actions.go @@ -40,7 +40,7 @@ func (self *WorkingTreeDiffActions) PlainDiff(pane types.DiffPaneContext, paths // An error means there is no diff to be had, which for our purposes is the same as // an empty one. diff, _ := self.c.Git().WorkingTree. - WorktreeFileDiffCmdObj(node, true, self.showsStagedSide(pane), paths). + WorktreeFileDiffCmdObj(node, git_commands.DiffModePlain, self.showsStagedSide(pane), paths). RunWithOutput() return diff } @@ -196,7 +196,7 @@ func (self *WorkingTreeDiffActions) fileForDiffLinePath(path string) *models.Fil func (self *WorkingTreeDiffActions) applyDiffLines( file *models.File, infos []types.DiffLineInfo, sourceCached bool, opts git_commands.ApplyPatchOpts, ) (bool, error) { - parsedPatch := patch.Parse(self.c.Git().WorkingTree.WorktreeFileDiff(file, true, sourceCached)) + parsedPatch := patch.Parse(self.c.Git().WorkingTree.WorktreeFileDiff(file, git_commands.DiffModePlain, sourceCached)) type changeLine struct { lineNumber int diff --git a/pkg/gui/presentation/files_test.go b/pkg/gui/presentation/files_test.go index c7e333682..74d8f1369 100644 --- a/pkg/gui/presentation/files_test.go +++ b/pkg/gui/presentation/files_test.go @@ -227,7 +227,7 @@ M file1 } patchBuilder := patch.NewPatchBuilder( utils.NewDummyLog(), - func(from string, to string, reverse bool, filename string, previousPath string, plain bool) (string, error) { + func(from string, to string, reverse bool, filename string, previousPath string) (string, error) { return "", nil }, )