diff options
author | Tyler Davis <tydavis@gmail.com> | 2020-04-25 03:32:59 +0000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-04-27 19:14:18 +1000 |
commit | b5404c61598a0ccfa8c1fba058f42b4547cbcf5d (patch) | |
tree | 1abd7b92d5569d9d025d407b9beff7fc9d5d4b76 | |
parent | 42d21c4bb68759172c809f2ac20f3f046b61df0f (diff) |
fix issue #640 add catCmd and OS-specific values
Add a catCmd to the Platform struct and set the value to "cat" for
non-windows builds and "type" for windows builds.
-rw-r--r-- | pkg/commands/git.go | 2 | ||||
-rw-r--r-- | pkg/commands/git_test.go | 12 | ||||
-rw-r--r-- | pkg/commands/os.go | 1 | ||||
-rw-r--r-- | pkg/commands/os_default_platform.go | 1 | ||||
-rw-r--r-- | pkg/commands/os_windows.go | 1 |
5 files changed, 14 insertions, 3 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go index f996c01b5..31318fc92 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -479,7 +479,7 @@ func (c *GitCommand) Push(branchName string, force bool, upstream string, args s // CatFile obtains the content of a file func (c *GitCommand) CatFile(fileName string) (string, error) { - return c.OSCommand.RunCommandWithOutput("cat %s", c.OSCommand.Quote(fileName)) + return c.OSCommand.RunCommandWithOutput("%s %s", c.OSCommand.Platform.catCmd, c.OSCommand.Quote(fileName)) } // StageFile stages a file diff --git a/pkg/commands/git_test.go b/pkg/commands/git_test.go index c8b5bf271..b70947534 100644 --- a/pkg/commands/git_test.go +++ b/pkg/commands/git_test.go @@ -6,6 +6,7 @@ import ( "os" "os/exec" "regexp" + "runtime" "testing" "time" @@ -1022,11 +1023,18 @@ func TestGitCommandPush(t *testing.T) { } } -// TestGitCommandCatFile is a function. +// TestGitCommandCatFile tests emitting a file using commands, where commands vary by OS. func TestGitCommandCatFile(t *testing.T) { + var osCmd string + switch os := runtime.GOOS; os { + case "windows": + osCmd = "type" + default: + osCmd = "cat" + } gitCmd := NewDummyGitCommand() gitCmd.OSCommand.command = func(cmd string, args ...string) *exec.Cmd { - assert.EqualValues(t, "cat", cmd) + assert.EqualValues(t, osCmd, cmd) assert.EqualValues(t, []string{"test.txt"}, args) return exec.Command("echo", "-n", "test") diff --git a/pkg/commands/os.go b/pkg/commands/os.go index 98317312d..4689c58d5 100644 --- a/pkg/commands/os.go +++ b/pkg/commands/os.go @@ -23,6 +23,7 @@ import ( // Platform stores the os state type Platform struct { os string + catCmd string shell string shellArg string escapedQuote string diff --git a/pkg/commands/os_default_platform.go b/pkg/commands/os_default_platform.go index 73e453b6b..864b1f3c8 100644 --- a/pkg/commands/os_default_platform.go +++ b/pkg/commands/os_default_platform.go @@ -9,6 +9,7 @@ import ( func getPlatform() *Platform { return &Platform{ os: runtime.GOOS, + catCmd: "cat", shell: "bash", shellArg: "-c", escapedQuote: "'", diff --git a/pkg/commands/os_windows.go b/pkg/commands/os_windows.go index 8fa9ce1c2..fcb498db3 100644 --- a/pkg/commands/os_windows.go +++ b/pkg/commands/os_windows.go @@ -3,6 +3,7 @@ package commands func getPlatform() *Platform { return &Platform{ os: "windows", + catCmd: "type", shell: "cmd", shellArg: "/c", escapedQuote: `\"`, |