mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-23 00:39:13 +02:00
Change not to use cat command
This commit is contained in:
committed by
Jesse Duffield
parent
711bd5a670
commit
c3d7de1c18
@ -2,6 +2,7 @@ package commands
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -15,7 +16,11 @@ import (
|
|||||||
|
|
||||||
// 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.CatFile(fileName)
|
buf, err := ioutil.ReadFile(fileName)
|
||||||
|
if err != nil {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
return string(buf), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *GitCommand) OpenMergeToolCmd() string {
|
func (c *GitCommand) OpenMergeToolCmd() string {
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||||
@ -13,28 +12,6 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"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.
|
// TestGitCommandStageFile is a function.
|
||||||
func TestGitCommandStageFile(t *testing.T) {
|
func TestGitCommandStageFile(t *testing.T) {
|
||||||
gitCmd := NewDummyGitCommand()
|
gitCmd := NewDummyGitCommand()
|
||||||
|
@ -24,7 +24,6 @@ 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
|
||||||
@ -217,18 +216,6 @@ func (c *OSCommand) RunCommandWithOutputLive(command string, output func(string)
|
|||||||
return RunCommandWithOutputLiveWrapper(c, command, output)
|
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
|
// 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
|
// 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
|
// The promptUserForCredential argument will be "username", "password" or "passphrase" and expects the user's password/passphrase or username back
|
||||||
|
@ -9,7 +9,6 @@ import (
|
|||||||
func getPlatform() *Platform {
|
func getPlatform() *Platform {
|
||||||
return &Platform{
|
return &Platform{
|
||||||
OS: runtime.GOOS,
|
OS: runtime.GOOS,
|
||||||
CatCmd: []string{"cat"},
|
|
||||||
Shell: "bash",
|
Shell: "bash",
|
||||||
ShellArg: "-c",
|
ShellArg: "-c",
|
||||||
EscapedQuote: `"`,
|
EscapedQuote: `"`,
|
||||||
|
@ -3,7 +3,6 @@ package oscommands
|
|||||||
func getPlatform() *Platform {
|
func getPlatform() *Platform {
|
||||||
return &Platform{
|
return &Platform{
|
||||||
OS: "windows",
|
OS: "windows",
|
||||||
CatCmd: []string{"cmd", "/c", "type"},
|
|
||||||
Shell: "cmd",
|
Shell: "cmd",
|
||||||
ShellArg: "/c",
|
ShellArg: "/c",
|
||||||
EscapedQuote: `\"`,
|
EscapedQuote: `\"`,
|
||||||
|
Reference in New Issue
Block a user