MCPcopy Create free account
hub / github.com/git-bug/git-bug / GetCoreEditor

Method GetCoreEditor

repository/gogit.go:291–331  ·  view source on GitHub ↗

GetCoreEditor returns the name of the editor that the user has used to configure git.

()

Source from the content-addressed store, hash-verified

289
290// GetCoreEditor returns the name of the editor that the user has used to configure git.
291func (repo *GoGitRepo) GetCoreEditor() (string, error) {
292 // See https://git-scm.com/docs/git-var
293 // 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.
294
295 if val, ok := os.LookupEnv("GIT_EDITOR"); ok {
296 return val, nil
297 }
298
299 val, err := repo.AnyConfig().ReadString("core.editor")
300 if err == nil && val != "" {
301 return val, nil
302 }
303 if err != nil && !errors.Is(err, ErrNoConfigEntry) {
304 return "", err
305 }
306
307 if val, ok := os.LookupEnv("VISUAL"); ok {
308 return val, nil
309 }
310
311 if val, ok := os.LookupEnv("EDITOR"); ok {
312 return val, nil
313 }
314
315 priorities := []string{
316 "editor",
317 "nano",
318 "vim",
319 "vi",
320 "emacs",
321 }
322
323 for _, cmd := range priorities {
324 if _, err = execabs.LookPath(cmd); err == nil {
325 return cmd, nil
326 }
327
328 }
329
330 return "ed", nil
331}
332
333// GetRemotes returns the configured remotes repositories.
334func (repo *GoGitRepo) GetRemotes() (map[string]string, error) {

Callers

nothing calls this directly

Calls 2

AnyConfigMethod · 0.95
ReadStringMethod · 0.65

Tested by

no test coverage detected