From 488c43aaa201822e3fc824b79d3a3026e3ab865c Mon Sep 17 00:00:00 2001 From: Ryooooooga Date: Fri, 13 Aug 2021 21:39:38 +0900 Subject: [PATCH 1/3] fix crash when double quotes in filename #1433 --- pkg/commands/files.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/commands/files.go b/pkg/commands/files.go index 51523ea5f..99e9bcf5c 100644 --- a/pkg/commands/files.go +++ b/pkg/commands/files.go @@ -250,7 +250,7 @@ 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 From 37700908cc9c0267eb67c693f166f052ca12fd7f Mon Sep 17 00:00:00 2001 From: Ryooooooga Date: Fri, 13 Aug 2021 21:49:40 +0900 Subject: [PATCH 2/3] fix checkout file command --- pkg/commands/files.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/commands/files.go b/pkg/commands/files.go index 99e9bcf5c..9fa5fb1bd 100644 --- a/pkg/commands/files.go +++ b/pkg/commands/files.go @@ -255,7 +255,7 @@ func (c *GitCommand) ShowFileDiffCmdStr(from string, to string, reverse bool, fi // 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 From 0740409f43bfc2fb154c65aaece7abeca78d1e9b Mon Sep 17 00:00:00 2001 From: Ryooooooga Date: Fri, 13 Aug 2021 22:15:06 +0900 Subject: [PATCH 3/3] fix test --- pkg/commands/files_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/commands/files_test.go b/pkg/commands/files_test.go index fd4b9f69f..01c1a6793 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", }, {