summaryrefslogtreecommitdiffstats
path: root/pkg/commands
diff options
context:
space:
mode:
authorRyooooooga <eial5q265e5@gmail.com>2021-08-23 22:35:19 +0900
committerJesse Duffield <jessedduffield@gmail.com>2021-08-25 21:32:48 +1000
commitc3d7de1c183ddf2bea39647114403d16825fdd9d (patch)
tree57a4ead9c3cdc0ce3a54cc697bf847953b29ff11 /pkg/commands
parent711bd5a670f5321495700a55503e4d4a9742f7ae (diff)
Change not to use cat command
Diffstat (limited to 'pkg/commands')
-rw-r--r--pkg/commands/files.go7
-rw-r--r--pkg/commands/files_test.go23
-rw-r--r--pkg/commands/oscommands/os.go13
-rw-r--r--pkg/commands/oscommands/os_default_platform.go1
-rw-r--r--pkg/commands/oscommands/os_windows.go1
5 files changed, 6 insertions, 39 deletions
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: `\"`,