1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-02-09 13:47:11 +02:00

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.
This commit is contained in:
Tyler Davis 2020-04-25 03:32:59 +00:00 committed by Jesse Duffield
parent 42d21c4bb6
commit b5404c6159
5 changed files with 14 additions and 3 deletions

View File

@ -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

View File

@ -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")

View File

@ -23,6 +23,7 @@ import (
// Platform stores the os state
type Platform struct {
os string
catCmd string
shell string
shellArg string
escapedQuote string

View File

@ -9,6 +9,7 @@ import (
func getPlatform() *Platform {
return &Platform{
os: runtime.GOOS,
catCmd: "cat",
shell: "bash",
shellArg: "-c",
escapedQuote: "'",

View File

@ -3,6 +3,7 @@ package commands
func getPlatform() *Platform {
return &Platform{
os: "windows",
catCmd: "type",
shell: "cmd",
shellArg: "/c",
escapedQuote: `\"`,