summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRandshot <randshot@norealm.xyz>2020-07-13 16:00:00 +0200
committerJesse Duffield <jessedduffield@gmail.com>2020-07-14 08:26:53 +1000
commit014e06eefd2a779e3458c23cdd1525b13f697526 (patch)
treee36bdc2c86d0f2213845e88edb0c04efd189485f
parent39a2122dc00651267c864647abf2c88cfd9d1e43 (diff)
factor out duplicate code into 'ShellCommandFromString'v0.20.8
Signed-off-by: Randshot <randshot@norealm.xyz>
-rw-r--r--pkg/commands/git.go20
-rw-r--r--pkg/commands/os.go13
2 files changed, 15 insertions, 18 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go
index 05d42b433..3599f7b39 100644
--- a/pkg/commands/git.go
+++ b/pkg/commands/git.go
@@ -453,15 +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() {
- 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 c.OSCommand.ShellCommandFromString(command), nil
}
return nil, c.OSCommand.RunCommand(command)
@@ -478,15 +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() {
- 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 c.OSCommand.ShellCommandFromString(command), nil
}
return nil, c.OSCommand.RunCommand(command)
diff --git a/pkg/commands/os.go b/pkg/commands/os.go
index a27196f34..b3358b170 100644
--- a/pkg/commands/os.go
+++ b/pkg/commands/os.go
@@ -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)