{"record":{"id":"03436c071a8c12f2","repo":"mislav/hub","slug":"can-t-load-git-var-git-editor","errorCode":null,"errorMessage":"Can't load git var: GIT_EDITOR","messagePattern":"Can't load git var: GIT_EDITOR","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"git/git.go","lineNumber":112,"sourceCode":"\t\treturn false\n\t}\n\n\ts := []string{dir}\n\ts = append(s, segments...)\n\tpath := filepath.Join(s...)\n\tif _, err := os.Stat(path); err == nil {\n\t\treturn true\n\t}\n\n\treturn false\n}\n\nfunc Editor() (string, error) {\n\tvarCmd := gitCmd(\"var\", \"GIT_EDITOR\")\n\tvarCmd.Stderr = nil\n\toutput, err := varCmd.Output()\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"Can't load git var: GIT_EDITOR\")\n\t}\n\n\treturn os.ExpandEnv(firstLine(output)), nil\n}\n\nfunc Head() (string, error) {\n\treturn SymbolicRef(\"HEAD\")\n}\n\n// SymbolicRef reads a branch name from a ref such as \"HEAD\"\nfunc SymbolicRef(ref string) (string, error) {\n\trefCmd := gitCmd(\"symbolic-ref\", ref)\n\trefCmd.Stderr = nil\n\toutput, err := refCmd.Output()\n\treturn firstLine(output), err\n}\n\n// SymbolicFullName reads a branch name from a ref such as \"@{upstream}\"","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/mislav/hub/blob/5c547ed804368763064e51f3990851e267e88edd/git/git.go#L94-L130","documentation":"Editor() runs `git var GIT_EDITOR` to resolve which editor git would use, then expands any env vars in the result. The error is thrown when that subprocess fails — i.e. git could not resolve GIT_EDITOR (often because neither GIT_EDITOR, core.editor, VISUAL, EDITOR is set and git falls back to a check that fails).","triggerScenarios":"Calling git.Editor() (directly or via TestGitEditor/NewEditor) in an environment where `git var GIT_EDITOR` exits non-zero: no editor env var configured and no sensible default available.","commonSituations":"CI/headless servers with no EDITOR or GIT_EDITOR set; Docker containers; running under a service account with a minimal environment; git versions where `git var` errors instead of returning a default.","solutions":["Export an editor: export GIT_EDITOR=vim (or core.editor in git config)","Set EDITOR/VISUAL in the environment (e.g. in Dockerfile or CI setup step)","Verify with `git var GIT_EDITOR` in the same shell","Alternatively use the EDITOR env var directly if the library consumer controls it"],"exampleFix":"// before: assume editor resolves\neditor, _ := git.Editor()\n// after: ensure an editor is configured\nif os.Getenv(\"GIT_EDITOR\") == \"\" && os.Getenv(\"EDITOR\") == \"\" {\n    os.Setenv(\"GIT_EDITOR\", \"vim\")\n}\neditor, err := git.Editor()","handlingStrategy":"fallback","validationCode":"if os.Getenv(\"GIT_EDITOR\") == \"\" && os.Getenv(\"EDITOR\") == \"\" && os.Getenv(\"VISUAL\") == \"\" {\n    os.Setenv(\"GIT_EDITOR\", \"vim\") // or vi/nano depending on platform\n}","typeGuard":null,"tryCatchPattern":"editor, err := git.Editor()\nif err != nil {\n    editor = os.Getenv(\"EDITOR\")\n    if editor == \"\" { editor = \"vi\" }\n}","preventionTips":["Set GIT_EDITOR or EDITOR in CI images and containers","Configure core.editor in git config for reproducible behavior","Use non-interactive editors (true/vim -e) in automated flows","Test `git var GIT_EDITOR` in deployment environments"],"tags":["git","editor","environment","configuration"],"backgroundTag":"missing-env-var","analyzedSha":"5c547ed804368763064e51f3990851e267e88edd","analyzedAt":"2026-09-01T03:34:15.525Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}