summaryrefslogtreecommitdiffstats
path: root/pkg/commands/git.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2018-08-14 18:48:08 +1000
committerJesse Duffield <jessedduffield@gmail.com>2018-08-14 18:48:08 +1000
commit574b34930ca3a44533017672b37bd50329445f21 (patch)
treead3e5965321e659f26255d485995a9163fd4e1f8 /pkg/commands/git.go
parent77080f44a4bf5a4153e632adf9aa23a9d2cba30b (diff)
support files with spaces in name
Diffstat (limited to 'pkg/commands/git.go')
-rw-r--r--pkg/commands/git.go15
1 files 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