Support externalDiffCommand in diffing mode (#3519)

- **PR Description**

Support `git.paging.externalDiffCommand` config in diffing mode (i.e.
when showing the diff between two commits using `W`).

Fixes #3518.
This commit is contained in:
Stefan Haller 2024-04-25 08:53:14 +02:00 committed by GitHub
commit aa81e191e2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,6 +1,10 @@
package git_commands package git_commands
import "github.com/jesseduffield/lazygit/pkg/commands/oscommands" import (
"fmt"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
)
type DiffCommands struct { type DiffCommands struct {
*GitCommon *GitCommon
@ -13,10 +17,16 @@ func NewDiffCommands(gitCommon *GitCommon) *DiffCommands {
} }
func (self *DiffCommands) DiffCmdObj(diffArgs []string) oscommands.ICmdObj { func (self *DiffCommands) DiffCmdObj(diffArgs []string) oscommands.ICmdObj {
extDiffCmd := self.UserConfig.Git.Paging.ExternalDiffCommand
useExtDiff := extDiffCmd != ""
return self.cmd.New( return self.cmd.New(
NewGitCmd("diff"). NewGitCmd("diff").
Config("diff.noprefix=false"). Config("diff.noprefix=false").
Arg("--submodule", "--no-ext-diff", "--color"). ConfigIf(useExtDiff, "diff.external="+extDiffCmd).
ArgIfElse(useExtDiff, "--ext-diff", "--no-ext-diff").
Arg("--submodule").
Arg(fmt.Sprintf("--color=%s", self.UserConfig.Git.Paging.ColorArg)).
Arg(diffArgs...). Arg(diffArgs...).
Dir(self.repoPaths.worktreePath). Dir(self.repoPaths.worktreePath).
ToArgv(), ToArgv(),