summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRandshot <randshot@norealm.xyz>2020-07-13 15:22:19 +0200
committerJesse Duffield <jessedduffield@gmail.com>2020-07-14 08:26:53 +1000
commit39a2122dc00651267c864647abf2c88cfd9d1e43 (patch)
treedba5be2efbb6ff4f9ecf4914f0129ab60d19b50f
parentfe6d8d62c5c0ef302ae44f95cd13a03600477199 (diff)
add quotes around the git commit command on non-windows systems
Signed-off-by: Randshot <randshot@norealm.xyz>
-rw-r--r--pkg/commands/git.go20
-rw-r--r--pkg/commands/git_test.go4
2 files changed, 20 insertions, 4 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go
index fd7d9e9b1..05d42b433 100644
--- a/pkg/commands/git.go
+++ b/pkg/commands/git.go
@@ -453,7 +453,15 @@ func (c *GitCommand) usingGpg() bool {
func (c *GitCommand) Commit(message string, flags string) (*exec.Cmd, error) {
command := fmt.Sprintf("git commit %s -m %s", flags, c.OSCommand.Quote(message))
if c.usingGpg() {
- return c.OSCommand.ExecutableFromString(fmt.Sprintf("%s %s %s", c.OSCommand.Platform.shell, c.OSCommand.Platform.shellArg, command)), nil
+ quotedCommand := ""
+ // Windows does not seem to like quotes around the command
+ if c.OSCommand.Platform.os == "windows" {
+ quotedCommand = command
+ } else {
+ quotedCommand = c.OSCommand.Quote(command)
+ }
+
+ return c.OSCommand.ExecutableFromString(fmt.Sprintf("%s %s %s", c.OSCommand.Platform.shell, c.OSCommand.Platform.shellArg, quotedCommand)), nil
}
return nil, c.OSCommand.RunCommand(command)
@@ -470,7 +478,15 @@ func (c *GitCommand) GetHeadCommitMessage() (string, error) {
func (c *GitCommand) AmendHead() (*exec.Cmd, error) {
command := "git commit --amend --no-edit --allow-empty"
if c.usingGpg() {
- return c.OSCommand.ExecutableFromString(fmt.Sprintf("%s %s %s", c.OSCommand.Platform.shell, c.OSCommand.Platform.shellArg, command)), nil
+ quotedCommand := ""
+ // Windows does not seem to like quotes around the command
+ if c.OSCommand.Platform.os == "windows" {
+ quotedCommand = command
+ } else {
+ quotedCommand = c.OSCommand.Quote(command)
+ }
+
+ return c.OSCommand.ExecutableFromString(fmt.Sprintf("%s %s %s", c.OSCommand.Platform.shell, c.OSCommand.Platform.shellArg, quotedCommand)), nil
}
return nil, c.OSCommand.RunCommand(command)
diff --git a/pkg/commands/git_test.go b/pkg/commands/git_test.go
index ed1fed013..d74f8b682 100644
--- a/pkg/commands/git_test.go
+++ b/pkg/commands/git_test.go
@@ -815,7 +815,7 @@ func TestGitCommandCommit(t *testing.T) {
"Commit using gpg",
func(cmd string, args ...string) *exec.Cmd {
assert.EqualValues(t, "bash", cmd)
- assert.EqualValues(t, []string{"-c", "git", "commit", "-m", "test"}, args)
+ assert.EqualValues(t, []string{"-c", "git commit -m 'test'"}, args)
return exec.Command("echo")
},
@@ -905,7 +905,7 @@ func TestGitCommandAmendHead(t *testing.T) {
"Amend commit using gpg",
func(cmd string, args ...string) *exec.Cmd {
assert.EqualValues(t, "bash", cmd)
- assert.EqualValues(t, []string{"-c", "git", "commit", "--amend", "--no-edit", "--allow-empty"}, args)
+ assert.EqualValues(t, []string{"-c", "git commit --amend --no-edit --allow-empty"}, args)
return exec.Command("echo")
},