summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2018-08-19 20:19:53 +1000
committerGitHub <noreply@github.com>2018-08-19 20:19:53 +1000
commit51558f51ab3b54b445f7449582a060f1bc42de18 (patch)
tree6f8a1ea71656a46a9f863d887cc6c23e698f424c
parent20086071088fb59be68a1d752147dcd00e541395 (diff)
parent35884f81e92b442cc902a3cd06857c08b5451085 (diff)
Merge pull request #186 from jesseduffield/hotfix/169-more-filenames-with-spaces
Handle filenames with spaces better
-rw-r--r--pkg/commands/git.go21
-rw-r--r--pkg/commands/git_test.go2
2 files changed, 10 insertions, 13 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 {
diff --git a/pkg/commands/git_test.go b/pkg/commands/git_test.go
index 1cd9901b3..9c2a64330 100644
--- a/pkg/commands/git_test.go
+++ b/pkg/commands/git_test.go
@@ -45,7 +45,7 @@ func TestDiff(t *testing.T) {
DisplayString: " D deleted_staged",
},
{
- Name: "\"file with space staged\"",
+ Name: "file with space staged",
HasStagedChanges: true,
HasUnstagedChanges: false,
Tracked: false,