mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-01-10 04:07:18 +02:00
Use DiffContextSize
in WorkTreeFileDiffCmdStr
This commit is contained in:
parent
9feaf5d70f
commit
ca88620e8f
@ -207,6 +207,7 @@ func (c *GitCommand) WorktreeFileDiffCmdStr(node models.IFile, plain bool, cache
|
|||||||
colorArg := c.colorArg()
|
colorArg := c.colorArg()
|
||||||
quotedPath := c.OSCommand.Quote(node.GetPath())
|
quotedPath := c.OSCommand.Quote(node.GetPath())
|
||||||
ignoreWhitespaceArg := ""
|
ignoreWhitespaceArg := ""
|
||||||
|
contextSize := c.Config.GetUserConfig().Git.DiffContextSize
|
||||||
if cached {
|
if cached {
|
||||||
cachedArg = "--cached"
|
cachedArg = "--cached"
|
||||||
}
|
}
|
||||||
@ -220,7 +221,7 @@ func (c *GitCommand) WorktreeFileDiffCmdStr(node models.IFile, plain bool, cache
|
|||||||
ignoreWhitespaceArg = "--ignore-all-space"
|
ignoreWhitespaceArg = "--ignore-all-space"
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf("git diff --submodule --no-ext-diff --color=%s %s %s %s %s", colorArg, ignoreWhitespaceArg, cachedArg, trackedArg, quotedPath)
|
return fmt.Sprintf("git diff --submodule --no-ext-diff --unified=%d --color=%s %s %s %s %s", contextSize, colorArg, ignoreWhitespaceArg, cachedArg, trackedArg, quotedPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *GitCommand) ApplyPatch(patch string, flags ...string) error {
|
func (c *GitCommand) ApplyPatch(patch string, flags ...string) error {
|
||||||
|
@ -317,6 +317,7 @@ func TestGitCommandDiff(t *testing.T) {
|
|||||||
plain bool
|
plain bool
|
||||||
cached bool
|
cached bool
|
||||||
ignoreWhitespace bool
|
ignoreWhitespace bool
|
||||||
|
contextSize int
|
||||||
}
|
}
|
||||||
|
|
||||||
scenarios := []scenario{
|
scenarios := []scenario{
|
||||||
@ -324,7 +325,7 @@ func TestGitCommandDiff(t *testing.T) {
|
|||||||
"Default case",
|
"Default case",
|
||||||
func(cmd string, args ...string) *exec.Cmd {
|
func(cmd string, args ...string) *exec.Cmd {
|
||||||
assert.EqualValues(t, "git", cmd)
|
assert.EqualValues(t, "git", cmd)
|
||||||
assert.EqualValues(t, []string{"diff", "--submodule", "--no-ext-diff", "--color=always", "--", "test.txt"}, args)
|
assert.EqualValues(t, []string{"diff", "--submodule", "--no-ext-diff", "--unified=3", "--color=always", "--", "test.txt"}, args)
|
||||||
|
|
||||||
return secureexec.Command("echo")
|
return secureexec.Command("echo")
|
||||||
},
|
},
|
||||||
@ -336,12 +337,13 @@ func TestGitCommandDiff(t *testing.T) {
|
|||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
|
3,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cached",
|
"cached",
|
||||||
func(cmd string, args ...string) *exec.Cmd {
|
func(cmd string, args ...string) *exec.Cmd {
|
||||||
assert.EqualValues(t, "git", cmd)
|
assert.EqualValues(t, "git", cmd)
|
||||||
assert.EqualValues(t, []string{"diff", "--submodule", "--no-ext-diff", "--color=always", "--cached", "--", "test.txt"}, args)
|
assert.EqualValues(t, []string{"diff", "--submodule", "--no-ext-diff", "--unified=3", "--color=always", "--cached", "--", "test.txt"}, args)
|
||||||
|
|
||||||
return secureexec.Command("echo")
|
return secureexec.Command("echo")
|
||||||
},
|
},
|
||||||
@ -353,12 +355,13 @@ func TestGitCommandDiff(t *testing.T) {
|
|||||||
false,
|
false,
|
||||||
true,
|
true,
|
||||||
false,
|
false,
|
||||||
|
3,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"plain",
|
"plain",
|
||||||
func(cmd string, args ...string) *exec.Cmd {
|
func(cmd string, args ...string) *exec.Cmd {
|
||||||
assert.EqualValues(t, "git", cmd)
|
assert.EqualValues(t, "git", cmd)
|
||||||
assert.EqualValues(t, []string{"diff", "--submodule", "--no-ext-diff", "--color=never", "--", "test.txt"}, args)
|
assert.EqualValues(t, []string{"diff", "--submodule", "--no-ext-diff", "--unified=3", "--color=never", "--", "test.txt"}, args)
|
||||||
|
|
||||||
return secureexec.Command("echo")
|
return secureexec.Command("echo")
|
||||||
},
|
},
|
||||||
@ -370,12 +373,13 @@ func TestGitCommandDiff(t *testing.T) {
|
|||||||
true,
|
true,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
|
3,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"File not tracked and file has no staged changes",
|
"File not tracked and file has no staged changes",
|
||||||
func(cmd string, args ...string) *exec.Cmd {
|
func(cmd string, args ...string) *exec.Cmd {
|
||||||
assert.EqualValues(t, "git", cmd)
|
assert.EqualValues(t, "git", cmd)
|
||||||
assert.EqualValues(t, []string{"diff", "--submodule", "--no-ext-diff", "--color=always", "--no-index", "--", "/dev/null", "test.txt"}, args)
|
assert.EqualValues(t, []string{"diff", "--submodule", "--no-ext-diff", "--unified=3", "--color=always", "--no-index", "--", "/dev/null", "test.txt"}, args)
|
||||||
|
|
||||||
return secureexec.Command("echo")
|
return secureexec.Command("echo")
|
||||||
},
|
},
|
||||||
@ -387,12 +391,13 @@ func TestGitCommandDiff(t *testing.T) {
|
|||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
|
3,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Default case (ignore whitespace)",
|
"Default case (ignore whitespace)",
|
||||||
func(cmd string, args ...string) *exec.Cmd {
|
func(cmd string, args ...string) *exec.Cmd {
|
||||||
assert.EqualValues(t, "git", cmd)
|
assert.EqualValues(t, "git", cmd)
|
||||||
assert.EqualValues(t, []string{"diff", "--submodule", "--no-ext-diff", "--color=always", "--ignore-all-space", "--", "test.txt"}, args)
|
assert.EqualValues(t, []string{"diff", "--submodule", "--no-ext-diff", "--unified=3", "--color=always", "--ignore-all-space", "--", "test.txt"}, args)
|
||||||
|
|
||||||
return secureexec.Command("echo")
|
return secureexec.Command("echo")
|
||||||
},
|
},
|
||||||
@ -404,6 +409,25 @@ func TestGitCommandDiff(t *testing.T) {
|
|||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
true,
|
true,
|
||||||
|
3,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Show diff with custom context size",
|
||||||
|
func(cmd string, args ...string) *exec.Cmd {
|
||||||
|
assert.EqualValues(t, "git", cmd)
|
||||||
|
assert.EqualValues(t, []string{"diff", "--submodule", "--no-ext-diff", "--unified=17", "--color=always", "--", "test.txt"}, args)
|
||||||
|
|
||||||
|
return secureexec.Command("echo")
|
||||||
|
},
|
||||||
|
&models.File{
|
||||||
|
Name: "test.txt",
|
||||||
|
HasStagedChanges: false,
|
||||||
|
Tracked: true,
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
17,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -411,6 +435,7 @@ func TestGitCommandDiff(t *testing.T) {
|
|||||||
t.Run(s.testName, func(t *testing.T) {
|
t.Run(s.testName, func(t *testing.T) {
|
||||||
gitCmd := NewDummyGitCommand()
|
gitCmd := NewDummyGitCommand()
|
||||||
gitCmd.OSCommand.Command = s.command
|
gitCmd.OSCommand.Command = s.command
|
||||||
|
gitCmd.Config.GetUserConfig().Git.DiffContextSize = s.contextSize
|
||||||
gitCmd.WorktreeFileDiff(s.file, s.plain, s.cached, s.ignoreWhitespace)
|
gitCmd.WorktreeFileDiff(s.file, s.plain, s.cached, s.ignoreWhitespace)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user