mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-13 22:17:05 +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:
parent
42d21c4bb6
commit
b5404c6159
@ -479,7 +479,7 @@ func (c *GitCommand) Push(branchName string, force bool, upstream string, args s
|
|||||||
|
|
||||||
// CatFile obtains the content of a file
|
// CatFile obtains the content of a file
|
||||||
func (c *GitCommand) CatFile(fileName string) (string, error) {
|
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
|
// StageFile stages a file
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"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) {
|
func TestGitCommandCatFile(t *testing.T) {
|
||||||
|
var osCmd string
|
||||||
|
switch os := runtime.GOOS; os {
|
||||||
|
case "windows":
|
||||||
|
osCmd = "type"
|
||||||
|
default:
|
||||||
|
osCmd = "cat"
|
||||||
|
}
|
||||||
gitCmd := NewDummyGitCommand()
|
gitCmd := NewDummyGitCommand()
|
||||||
gitCmd.OSCommand.command = func(cmd string, args ...string) *exec.Cmd {
|
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)
|
assert.EqualValues(t, []string{"test.txt"}, args)
|
||||||
|
|
||||||
return exec.Command("echo", "-n", "test")
|
return exec.Command("echo", "-n", "test")
|
||||||
|
@ -23,6 +23,7 @@ import (
|
|||||||
// Platform stores the os state
|
// Platform stores the os state
|
||||||
type Platform struct {
|
type Platform struct {
|
||||||
os string
|
os string
|
||||||
|
catCmd string
|
||||||
shell string
|
shell string
|
||||||
shellArg string
|
shellArg string
|
||||||
escapedQuote string
|
escapedQuote string
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
func getPlatform() *Platform {
|
func getPlatform() *Platform {
|
||||||
return &Platform{
|
return &Platform{
|
||||||
os: runtime.GOOS,
|
os: runtime.GOOS,
|
||||||
|
catCmd: "cat",
|
||||||
shell: "bash",
|
shell: "bash",
|
||||||
shellArg: "-c",
|
shellArg: "-c",
|
||||||
escapedQuote: "'",
|
escapedQuote: "'",
|
||||||
|
@ -3,6 +3,7 @@ package commands
|
|||||||
func getPlatform() *Platform {
|
func getPlatform() *Platform {
|
||||||
return &Platform{
|
return &Platform{
|
||||||
os: "windows",
|
os: "windows",
|
||||||
|
catCmd: "type",
|
||||||
shell: "cmd",
|
shell: "cmd",
|
||||||
shellArg: "/c",
|
shellArg: "/c",
|
||||||
escapedQuote: `\"`,
|
escapedQuote: `\"`,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user