mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-03 00:57:52 +02:00
Use DiffContextSize
in ShowCmdStr
This commit is contained in:
@ -61,11 +61,12 @@ func (c *GitCommand) AmendHeadCmdStr() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *GitCommand) ShowCmdStr(sha string, filterPath string) string {
|
func (c *GitCommand) ShowCmdStr(sha string, filterPath string) string {
|
||||||
|
contextSize := c.Config.GetUserConfig().Git.DiffContextSize
|
||||||
filterPathArg := ""
|
filterPathArg := ""
|
||||||
if filterPath != "" {
|
if filterPath != "" {
|
||||||
filterPathArg = fmt.Sprintf(" -- %s", c.OSCommand.Quote(filterPath))
|
filterPathArg = fmt.Sprintf(" -- %s", c.OSCommand.Quote(filterPath))
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("git show --submodule --color=%s --no-renames --stat -p %s %s", c.colorArg(), sha, filterPathArg)
|
return fmt.Sprintf("git show --submodule --color=%s --unified=%d --no-renames --stat -p %s %s", c.colorArg(), contextSize, sha, filterPathArg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Revert reverts the selected commit by sha
|
// Revert reverts the selected commit by sha
|
||||||
|
@ -110,3 +110,43 @@ func TestGitCommandCreateFixupCommit(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestGitCommandShowCmdStr is a function.
|
||||||
|
func TestGitCommandShowCmdStr(t *testing.T) {
|
||||||
|
type scenario struct {
|
||||||
|
testName string
|
||||||
|
filterPath string
|
||||||
|
contextSize int
|
||||||
|
expected string
|
||||||
|
}
|
||||||
|
|
||||||
|
scenarios := []scenario{
|
||||||
|
{
|
||||||
|
testName: "Default case without filter path",
|
||||||
|
filterPath: "",
|
||||||
|
contextSize: 3,
|
||||||
|
expected: "git show --submodule --color=always --unified=3 --no-renames --stat -p 1234567890 ",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testName: "Default case with filter path",
|
||||||
|
filterPath: "file.txt",
|
||||||
|
contextSize: 3,
|
||||||
|
expected: "git show --submodule --color=always --unified=3 --no-renames --stat -p 1234567890 -- \"file.txt\"",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testName: "Show diff with custom context size",
|
||||||
|
filterPath: "",
|
||||||
|
contextSize: 77,
|
||||||
|
expected: "git show --submodule --color=always --unified=77 --no-renames --stat -p 1234567890 ",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, s := range scenarios {
|
||||||
|
t.Run(s.testName, func(t *testing.T) {
|
||||||
|
gitCmd := NewDummyGitCommand()
|
||||||
|
gitCmd.Config.GetUserConfig().Git.DiffContextSize = s.contextSize
|
||||||
|
cmdStr := gitCmd.ShowCmdStr("1234567890", s.filterPath)
|
||||||
|
assert.Equal(t, s.expected, cmdStr)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user