diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2018-08-19 20:13:29 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2018-08-19 20:13:29 +1000 |
commit | 35884f81e92b442cc902a3cd06857c08b5451085 (patch) | |
tree | 6f8a1ea71656a46a9f863d887cc6c23e698f424c /pkg/commands/git.go | |
parent | 20086071088fb59be68a1d752147dcd00e541395 (diff) |
handle filenames with spaces better
Diffstat (limited to 'pkg/commands/git.go')
-rw-r--r-- | pkg/commands/git.go | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go index 95a60e8a6..5176e55c9 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -83,7 +83,7 @@ func (c *GitCommand) GetStatusFiles() []File { filename := statusString[3:] tracked := !includes([]string{"??", "A ", "AM"}, change) file := File{ - Name: filename, + Name: c.OSCommand.Unquote(filename), DisplayString: statusString, HasStagedChanges: !includes([]string{" ", "U", "?"}, stagedChange), HasUnstagedChanges: unstagedChange != " ", @@ -321,24 +321,24 @@ func (c *GitCommand) SquashFixupCommit(branchName string, shaValue string) error } // CatFile obtain the contents of a file -func (c *GitCommand) CatFile(file string) (string, error) { - return c.OSCommand.RunCommandWithOutput("cat " + file) +func (c *GitCommand) CatFile(fileName string) (string, error) { + return c.OSCommand.RunCommandWithOutput("cat " + c.OSCommand.Quote(fileName)) } // StageFile stages a file -func (c *GitCommand) StageFile(file string) error { - return c.OSCommand.RunCommand("git add " + c.OSCommand.Quote(file)) +func (c *GitCommand) StageFile(fileName string) error { + return c.OSCommand.RunCommand("git add " + c.OSCommand.Quote(fileName)) } // UnStageFile unstages a file -func (c *GitCommand) UnStageFile(file string, tracked bool) error { +func (c *GitCommand) UnStageFile(fileName string, tracked bool) error { var command string if tracked { command = "git reset HEAD " } else { command = "git rm --cached " } - return c.OSCommand.RunCommand(command + file) + return c.OSCommand.RunCommand(command + c.OSCommand.Quote(fileName)) } // GitStatus returns the plaintext short status of the repo @@ -364,7 +364,7 @@ func (c *GitCommand) RemoveFile(file File) error { } } if !file.Tracked { - return os.RemoveAll(c.OSCommand.Unquote(file.Name)) + return os.RemoveAll(file.Name) } // if the file is tracked, we assume you want to just check it out return c.OSCommand.RunCommand("git checkout -- " + file.Name) @@ -479,12 +479,9 @@ 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 + fileName := c.OSCommand.Quote(file.Name) if file.HasStagedChanges && !file.HasUnstagedChanges { cachedArg = "--cached" - } else { - // if the file is staged and has spaces in it, it comes pre-quoted - fileName = c.OSCommand.Quote(fileName) } trackedArg := "--" if !file.Tracked && !file.HasStagedChanges { |