Support absolute paths when detecting edit preset from EDITOR env var

This commit is contained in:
Stefan Haller 2026-07-30 17:31:56 +02:00
parent df0943ad33
commit f15f713c68
2 changed files with 13 additions and 1 deletions

View file

@ -2,6 +2,7 @@ package git_commands
import (
"os"
"path/filepath"
"strconv"
"strings"
@ -93,7 +94,7 @@ func (self *FileCommands) guessDefaultEditor() string {
// At this point, it might be more than just the name of the editor;
// e.g. it might be "code -w" or "vim -u myvim.rc". So assume that
// everything up to the first space is the editor name.
editor = strings.Split(editor, " ")[0]
editor = filepath.Base(strings.Split(editor, " ")[0])
}
return editor

View file

@ -203,6 +203,17 @@ func TestGuessDefaultEditor(t *testing.T) {
},
expectedResult: "bbedit",
},
{
gitConfigMockResponses: nil,
getenv: func(env string) string {
if env == "EDITOR" {
return "/usr/bin/nvim"
}
return ""
},
expectedResult: "nvim",
},
}
for _, s := range scenarios {