diff options
author | Michael Muré <batolettre@gmail.com> | 2020-09-27 23:14:51 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2020-09-29 20:43:54 +0200 |
commit | 0acb3505ffe71718cb3b6b0e957cc921ea9ce880 (patch) | |
tree | b226c0feb2d96801ae168d134478f675ca544d57 | |
parent | 02146f0b404e3f247c2fcb540b10c42f37630735 (diff) | |
download | git-bug-0acb3505ffe71718cb3b6b0e957cc921ea9ce880.tar.gz |
repo: implement GetCoreEditor for go-git
-rw-r--r-- | repository/gogit.go | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/repository/gogit.go b/repository/gogit.go index 6d3aede9..aac89d4b 100644 --- a/repository/gogit.go +++ b/repository/gogit.go @@ -208,8 +208,30 @@ func (repo *GoGitRepo) GetUserEmail() (string, error) { // GetCoreEditor returns the name of the editor that the user has used to configure git. func (repo *GoGitRepo) GetCoreEditor() (string, error) { + // See https://git-scm.com/docs/git-var + // The order of preference is the $GIT_EDITOR environment variable, then core.editor configuration, then $VISUAL, then $EDITOR, and then the default chosen at compile time, which is usually vi. - panic("implement me") + if val, ok := os.LookupEnv("GIT_EDITOR"); ok { + return val, nil + } + + val, err := repo.AnyConfig().ReadString("core.editor") + if err == nil && val != "" { + return val, nil + } + if err != nil && err != ErrNoConfigEntry { + return "", err + } + + if val, ok := os.LookupEnv("VISUAL"); ok { + return val, nil + } + + if val, ok := os.LookupEnv("EDITOR"); ok { + return val, nil + } + + return "vi", nil } // GetRemotes returns the configured remotes repositories. |