GetCoreEditor returns the name of the editor that the user has used to configure git.
()
| 289 | |
| 290 | // GetCoreEditor returns the name of the editor that the user has used to configure git. |
| 291 | func (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. |
| 334 | func (repo *GoGitRepo) GetRemotes() (map[string]string, error) { |
nothing calls this directly
no test coverage detected