diff --git a/pkg/commands/files.go b/pkg/commands/files.go index 51523ea5f88..9fa5fb1bd2e 100644 --- a/pkg/commands/files.go +++ b/pkg/commands/files.go @@ -250,12 +250,12 @@ func (c *GitCommand) ShowFileDiffCmdStr(from string, to string, reverse bool, fi reverseFlag = " -R " } - return fmt.Sprintf(`git diff --submodule --no-ext-diff --no-renames --color=%s %s %s %s -- "%s"`, colorArg, from, to, reverseFlag, fileName) + return fmt.Sprintf("git diff --submodule --no-ext-diff --no-renames --color=%s %s %s %s -- %s", colorArg, from, to, reverseFlag, c.OSCommand.Quote(fileName)) } // CheckoutFile checks out the file for the given commit func (c *GitCommand) CheckoutFile(commitSha, fileName string) error { - return c.RunCommand("git checkout %s %s", commitSha, fileName) + return c.RunCommand("git checkout %s -- %s", commitSha, c.OSCommand.Quote(fileName)) } // DiscardOldFileChanges discards changes to a file from an old commit diff --git a/pkg/commands/files_test.go b/pkg/commands/files_test.go index fd4b9f69f65..01c1a67938b 100644 --- a/pkg/commands/files_test.go +++ b/pkg/commands/files_test.go @@ -455,7 +455,7 @@ func TestGitCommandCheckoutFile(t *testing.T) { "test999.txt", test.CreateMockCommand(t, []*test.CommandSwapper{ { - Expect: "git checkout 11af912 test999.txt", + Expect: "git checkout 11af912 -- test999.txt", Replace: "echo", }, }), @@ -469,7 +469,7 @@ func TestGitCommandCheckoutFile(t *testing.T) { "test999.txt", test.CreateMockCommand(t, []*test.CommandSwapper{ { - Expect: "git checkout 11af912 test999.txt", + Expect: "git checkout 11af912 -- test999.txt", Replace: "test", }, }), @@ -606,7 +606,7 @@ func TestGitCommandDiscardOldFileChanges(t *testing.T) { Replace: "echo", }, { - Expect: "git checkout HEAD^ test999.txt", + Expect: "git checkout HEAD^ -- test999.txt", Replace: "echo", }, {