Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/commands/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ 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
return c.OSCommand.ShellCommandFromString(command), nil
}

return nil, c.OSCommand.RunCommand(command)
Expand All @@ -470,7 +470,7 @@ 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
return c.OSCommand.ShellCommandFromString(command), nil
}

return nil, c.OSCommand.RunCommand(command)
Expand Down
4 changes: 2 additions & 2 deletions pkg/commands/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
},
Expand Down Expand Up @@ -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")
},
Expand Down
13 changes: 13 additions & 0 deletions pkg/commands/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,19 @@ func (c *OSCommand) ExecutableFromString(commandStr string) *exec.Cmd {
return cmd
}

// ShellCommandFromString takes a string like `git commit` and returns an executable shell command for it
func (c *OSCommand) ShellCommandFromString(commandStr string) *exec.Cmd {
quotedCommand := ""
// Windows does not seem to like quotes around the command
if c.Platform.os == "windows" {
quotedCommand = commandStr
} else {
quotedCommand = c.Quote(commandStr)
}

return c.ExecutableFromString(fmt.Sprintf("%s %s %s", c.Platform.shell, c.Platform.shellArg, quotedCommand))
}

// RunCommandWithOutputLive runs RunCommandWithOutputLiveWrapper
func (c *OSCommand) RunCommandWithOutputLive(command string, output func(string) string) error {
return RunCommandWithOutputLiveWrapper(c, command, output)
Expand Down