From c3d7de1c183ddf2bea39647114403d16825fdd9d Mon Sep 17 00:00:00 2001 From: Ryooooooga Date: Mon, 23 Aug 2021 22:35:19 +0900 Subject: Change not to use cat command --- pkg/commands/files.go | 7 ++++++- pkg/commands/files_test.go | 23 ----------------------- pkg/commands/oscommands/os.go | 13 ------------- pkg/commands/oscommands/os_default_platform.go | 1 - pkg/commands/oscommands/os_windows.go | 1 - 5 files changed, 6 insertions(+), 39 deletions(-) (limited to 'pkg/commands') diff --git a/pkg/commands/files.go b/pkg/commands/files.go index ac508941b..c66ffc5cf 100644 --- a/pkg/commands/files.go +++ b/pkg/commands/files.go @@ -2,6 +2,7 @@ package commands import ( "fmt" + "io/ioutil" "os" "path/filepath" "strconv" @@ -15,7 +16,11 @@ import ( // CatFile obtains the content of a file func (c *GitCommand) CatFile(fileName string) (string, error) { - return c.OSCommand.CatFile(fileName) + buf, err := ioutil.ReadFile(fileName) + if err != nil { + return "", nil + } + return string(buf), nil } func (c *GitCommand) OpenMergeToolCmd() string { diff --git a/pkg/commands/files_test.go b/pkg/commands/files_test.go index 0410c95c2..19a014eaa 100644 --- a/pkg/commands/files_test.go +++ b/pkg/commands/files_test.go @@ -4,7 +4,6 @@ import ( "fmt" "io/ioutil" "os/exec" - "runtime" "testing" "github.com/jesseduffield/lazygit/pkg/commands/models" @@ -13,28 +12,6 @@ import ( "github.com/stretchr/testify/assert" ) -// 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, osCmd, cmd) - assert.EqualValues(t, []string{"test.txt"}, args) - - return secureexec.Command("echo", "-n", "test") - } - - o, err := gitCmd.CatFile("test.txt") - assert.NoError(t, err) - assert.Equal(t, "test", o) -} - // TestGitCommandStageFile is a function. func TestGitCommandStageFile(t *testing.T) { gitCmd := NewDummyGitCommand() diff --git a/pkg/commands/oscommands/os.go b/pkg/commands/oscommands/os.go index cf050cf53..5a35b9278 100644 --- a/pkg/commands/oscommands/os.go +++ b/pkg/commands/oscommands/os.go @@ -24,7 +24,6 @@ import ( // Platform stores the os state type Platform struct { OS string - CatCmd []string Shell string ShellArg string EscapedQuote string @@ -217,18 +216,6 @@ func (c *OSCommand) RunCommandWithOutputLive(command string, output func(string) return RunCommandWithOutputLiveWrapper(c, command, output) } -func (c *OSCommand) CatFile(filename string) (string, error) { - arr := append(c.Platform.CatCmd, filename) - cmdStr := strings.Join(arr, " ") - c.Log.WithField("command", cmdStr).Info("Cat") - cmd := c.Command(arr[0], arr[1:]...) - output, err := sanitisedCommandOutput(cmd.CombinedOutput()) - if err != nil { - c.Log.WithField("command", cmdStr).Error(output) - } - return output, err -} - // DetectUnamePass detect a username / password / passphrase question in a command // promptUserForCredential is a function that gets executed when this function detect you need to fillin a password or passphrase // The promptUserForCredential argument will be "username", "password" or "passphrase" and expects the user's password/passphrase or username back diff --git a/pkg/commands/oscommands/os_default_platform.go b/pkg/commands/oscommands/os_default_platform.go index 3fb579eec..f91cc2651 100644 --- a/pkg/commands/oscommands/os_default_platform.go +++ b/pkg/commands/oscommands/os_default_platform.go @@ -9,7 +9,6 @@ import ( func getPlatform() *Platform { return &Platform{ OS: runtime.GOOS, - CatCmd: []string{"cat"}, Shell: "bash", ShellArg: "-c", EscapedQuote: `"`, diff --git a/pkg/commands/oscommands/os_windows.go b/pkg/commands/oscommands/os_windows.go index 206d50433..611467581 100644 --- a/pkg/commands/oscommands/os_windows.go +++ b/pkg/commands/oscommands/os_windows.go @@ -3,7 +3,6 @@ package oscommands func getPlatform() *Platform { return &Platform{ OS: "windows", - CatCmd: []string{"cmd", "/c", "type"}, Shell: "cmd", ShellArg: "/c", EscapedQuote: `\"`, -- cgit v1.2.3