mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-01-10 04:07:18 +02:00
Use DiffContextSize
in ShowFileDiffStr
This commit is contained in:
parent
ca88620e8f
commit
14d9e776be
@ -248,6 +248,7 @@ func (c *GitCommand) ShowFileDiff(from string, to string, reverse bool, fileName
|
|||||||
|
|
||||||
func (c *GitCommand) ShowFileDiffCmdStr(from string, to string, reverse bool, fileName string, plain bool) string {
|
func (c *GitCommand) ShowFileDiffCmdStr(from string, to string, reverse bool, fileName string, plain bool) string {
|
||||||
colorArg := c.colorArg()
|
colorArg := c.colorArg()
|
||||||
|
contextSize := c.Config.GetUserConfig().Git.DiffContextSize
|
||||||
if plain {
|
if plain {
|
||||||
colorArg = "never"
|
colorArg = "never"
|
||||||
}
|
}
|
||||||
@ -257,7 +258,7 @@ func (c *GitCommand) ShowFileDiffCmdStr(from string, to string, reverse bool, fi
|
|||||||
reverseFlag = " -R "
|
reverseFlag = " -R "
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf("git diff --submodule --no-ext-diff --no-renames --color=%s %s %s %s -- %s", colorArg, from, to, reverseFlag, c.OSCommand.Quote(fileName))
|
return fmt.Sprintf("git diff --submodule --no-ext-diff --unified=%d --no-renames --color=%s %s %s %s -- %s", contextSize, colorArg, from, to, reverseFlag, c.OSCommand.Quote(fileName))
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckoutFile checks out the file for the given commit
|
// CheckoutFile checks out the file for the given commit
|
||||||
|
@ -441,6 +441,59 @@ func TestGitCommandDiff(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestGitCommandShowFileDiff is a function.
|
||||||
|
func TestGitCommandShowFileDiff(t *testing.T) {
|
||||||
|
type scenario struct {
|
||||||
|
testName string
|
||||||
|
command func(string, ...string) *exec.Cmd
|
||||||
|
from string
|
||||||
|
to string
|
||||||
|
reverse bool
|
||||||
|
plain bool
|
||||||
|
contextSize int
|
||||||
|
}
|
||||||
|
|
||||||
|
scenarios := []scenario{
|
||||||
|
{
|
||||||
|
"Default case",
|
||||||
|
func(cmd string, args ...string) *exec.Cmd {
|
||||||
|
assert.EqualValues(t, "git", cmd)
|
||||||
|
assert.EqualValues(t, []string{"diff", "--submodule", "--no-ext-diff", "--unified=3", "--no-renames", "--color=always", "1234567890", "0987654321", "--", "test.txt"}, args)
|
||||||
|
|
||||||
|
return secureexec.Command("echo")
|
||||||
|
},
|
||||||
|
"1234567890",
|
||||||
|
"0987654321",
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
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=123", "--no-renames", "--color=always", "1234567890", "0987654321", "--", "test.txt"}, args)
|
||||||
|
|
||||||
|
return secureexec.Command("echo")
|
||||||
|
},
|
||||||
|
"1234567890",
|
||||||
|
"0987654321",
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
123,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, s := range scenarios {
|
||||||
|
t.Run(s.testName, func(t *testing.T) {
|
||||||
|
gitCmd := NewDummyGitCommand()
|
||||||
|
gitCmd.OSCommand.Command = s.command
|
||||||
|
gitCmd.Config.GetUserConfig().Git.DiffContextSize = s.contextSize
|
||||||
|
gitCmd.ShowFileDiff(s.from, s.to, s.reverse, "test.txt", s.plain)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TestGitCommandCheckoutFile is a function.
|
// TestGitCommandCheckoutFile is a function.
|
||||||
func TestGitCommandCheckoutFile(t *testing.T) {
|
func TestGitCommandCheckoutFile(t *testing.T) {
|
||||||
type scenario struct {
|
type scenario struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user