1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-08-06 11:02:41 +03:00

commands/git : refactor test to Diff, refactor function

This commit is contained in:
Anthony HAMON
2018-09-18 21:09:51 +02:00
parent bdeb78c9a0
commit 360b7c1def
3 changed files with 50 additions and 119 deletions

View File

@@ -506,15 +506,15 @@ func (c *GitCommand) Show(sha string) (string, error) {
// Diff returns the diff of a file
func (c *GitCommand) Diff(file *File) string {
cachedArg := ""
trackedArg := "--"
fileName := c.OSCommand.Quote(file.Name)
if file.HasStagedChanges && !file.HasUnstagedChanges {
cachedArg = "--cached"
}
trackedArg := "--"
if !file.Tracked && !file.HasStagedChanges {
trackedArg = "--no-index /dev/null"
}
command := fmt.Sprintf("%s %s %s %s", "git diff --color ", cachedArg, trackedArg, fileName)
command := fmt.Sprintf("git diff --color %s %s %s", cachedArg, trackedArg, fileName)
// for now we assume an error means the file was deleted
s, _ := c.OSCommand.RunCommandWithOutput(command)