From 574b34930ca3a44533017672b37bd50329445f21 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Tue, 14 Aug 2018 18:48:08 +1000 Subject: [PATCH] support files with spaces in name --- pkg/commands/git.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/pkg/commands/git.go b/pkg/commands/git.go index e7a5212a2..44fd57f1c 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -327,7 +327,7 @@ func (c *GitCommand) CatFile(file string) (string, error) { // StageFile stages a file func (c *GitCommand) StageFile(file string) error { - return c.OSCommand.RunCommand("git add " + file) + return c.OSCommand.RunCommand("git add " + c.OSCommand.Quote(file)) } // UnStageFile unstages a file @@ -474,18 +474,23 @@ func (c *GitCommand) Show(sha string) string { // Diff returns the diff of a file func (c *GitCommand) Diff(file File) string { cachedArg := "" + fileName := file.Name if file.HasStagedChanges && !file.HasUnstagedChanges { - cachedArg = "--cached " + cachedArg = "--cached" + } else { + // if the file is staged and has spaces in it, it comes pre-quoted + fileName = c.OSCommand.Quote(fileName) } deletedArg := "" if file.Deleted { - deletedArg = "-- " + deletedArg = "--" } trackedArg := "" if !file.Tracked && !file.HasStagedChanges { - trackedArg = "--no-index /dev/null " + trackedArg = "--no-index /dev/null" } - command := "git diff --color " + cachedArg + deletedArg + trackedArg + file.Name + command := fmt.Sprintf("%s %s %s %s %s", "git diff --color ", cachedArg, deletedArg, trackedArg, fileName) + // for now we assume an error means the file was deleted s, _ := c.OSCommand.RunCommandWithOutput(command) return s