mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-28 16:02:01 +03:00
Edit command as user OS config option
This commit is contained in:
committed by
Jesse Duffield
parent
cb78cf7de4
commit
60468d2e17
@ -318,7 +318,11 @@ func (c *GitCommand) ResetAndClean() error {
|
||||
}
|
||||
|
||||
func (c *GitCommand) EditFileCmdStr(filename string) (string, error) {
|
||||
editor := c.GetConfigValue("core.editor")
|
||||
editor := c.Config.GetUserConfig().OS.EditCommand
|
||||
|
||||
if editor == "" {
|
||||
editor = c.GetConfigValue("core.editor")
|
||||
}
|
||||
|
||||
if editor == "" {
|
||||
editor = c.OSCommand.Getenv("GIT_EDITOR")
|
||||
|
@ -720,6 +720,7 @@ func TestGitCommandRemoveUntrackedFiles(t *testing.T) {
|
||||
func TestEditFileCmdStr(t *testing.T) {
|
||||
type scenario struct {
|
||||
filename string
|
||||
configEditCommand string
|
||||
command func(string, ...string) *exec.Cmd
|
||||
getenv func(string) string
|
||||
getGitConfigValue func(string) (string, error)
|
||||
@ -729,6 +730,7 @@ func TestEditFileCmdStr(t *testing.T) {
|
||||
scenarios := []scenario{
|
||||
{
|
||||
"test",
|
||||
"",
|
||||
func(name string, arg ...string) *exec.Cmd {
|
||||
return secureexec.Command("exit", "1")
|
||||
},
|
||||
@ -744,6 +746,25 @@ func TestEditFileCmdStr(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"test",
|
||||
"nano",
|
||||
func(name string, args ...string) *exec.Cmd {
|
||||
assert.Equal(t, "which", name)
|
||||
return secureexec.Command("echo")
|
||||
},
|
||||
func(env string) string {
|
||||
return ""
|
||||
},
|
||||
func(cf string) (string, error) {
|
||||
return "", nil
|
||||
},
|
||||
func(cmdStr string, err error) {
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "nano \"test\"", cmdStr)
|
||||
},
|
||||
},
|
||||
{
|
||||
"test",
|
||||
"",
|
||||
func(name string, arg ...string) *exec.Cmd {
|
||||
assert.Equal(t, "which", name)
|
||||
return secureexec.Command("exit", "1")
|
||||
@ -761,6 +782,7 @@ func TestEditFileCmdStr(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"test",
|
||||
"",
|
||||
func(name string, arg ...string) *exec.Cmd {
|
||||
assert.Equal(t, "which", name)
|
||||
return secureexec.Command("exit", "1")
|
||||
@ -781,6 +803,7 @@ func TestEditFileCmdStr(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"test",
|
||||
"",
|
||||
func(name string, arg ...string) *exec.Cmd {
|
||||
assert.Equal(t, "which", name)
|
||||
return secureexec.Command("exit", "1")
|
||||
@ -802,6 +825,7 @@ func TestEditFileCmdStr(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"test",
|
||||
"",
|
||||
func(name string, arg ...string) *exec.Cmd {
|
||||
assert.Equal(t, "which", name)
|
||||
return secureexec.Command("echo")
|
||||
@ -819,6 +843,7 @@ func TestEditFileCmdStr(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"file/with space",
|
||||
"",
|
||||
func(name string, args ...string) *exec.Cmd {
|
||||
assert.Equal(t, "which", name)
|
||||
return secureexec.Command("echo")
|
||||
@ -838,6 +863,7 @@ func TestEditFileCmdStr(t *testing.T) {
|
||||
|
||||
for _, s := range scenarios {
|
||||
gitCmd := NewDummyGitCommand()
|
||||
gitCmd.Config.GetUserConfig().OS.EditCommand = s.configEditCommand
|
||||
gitCmd.OSCommand.Command = s.command
|
||||
gitCmd.OSCommand.Getenv = s.getenv
|
||||
gitCmd.getGitConfigValue = s.getGitConfigValue
|
||||
|
Reference in New Issue
Block a user