{"record":{"id":"c81d911ecb36ee7a","repo":"mislav/hub","slug":"not-a-git-repository-or-any-of-the-parent-directo","errorCode":null,"errorMessage":"Not a git repository (or any of the parent directories): .git","messagePattern":"Not a git repository \\(or any of the parent directories\\): \\.git","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"git/git.go","lineNumber":34,"sourceCode":"\toutput, err := versionCmd.Output()\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"error running git version: %s\", err)\n\t}\n\treturn firstLine(output), nil\n}\n\nvar cachedDir string\n\nfunc Dir() (string, error) {\n\tif cachedDir != \"\" {\n\t\treturn cachedDir, nil\n\t}\n\n\tdirCmd := gitCmd(\"rev-parse\", \"-q\", \"--git-dir\")\n\tdirCmd.Stderr = nil\n\toutput, err := dirCmd.Output()\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"Not a git repository (or any of the parent directories): .git\")\n\t}\n\n\tvar chdir string\n\tfor i, flag := range GlobalFlags {\n\t\tif flag == \"-C\" {\n\t\t\tdir := GlobalFlags[i+1]\n\t\t\tif filepath.IsAbs(dir) {\n\t\t\t\tchdir = dir\n\t\t\t} else {\n\t\t\t\tchdir = filepath.Join(chdir, dir)\n\t\t\t}\n\t\t}\n\t}\n\n\tgitDir := firstLine(output)\n\n\tif !filepath.IsAbs(gitDir) {\n\t\tif chdir != \"\" {","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/mislav/hub/blob/5c547ed804368763064e51f3990851e267e88edd/git/git.go#L16-L52","documentation":"Dir() runs `git rev-parse -q --git-dir` to locate the .git directory; when the command fails, the library concludes the current directory is not inside a git repository and throws this fixed message. It deliberately discards the underlying error to present a single, predictable cause.","triggerScenarios":"Calling git.Dir() (directly or via create, HasFile, TestGitDir, NewEditor, LocalRepo) while the working directory — or any directory given via -C global flags — is outside any git work tree (no .git found walking up parents).","commonSituations":"Running the tool in a brand-new empty project before `git init`; running from $HOME or /tmp; typo in the -C path; running in a submodule-less directory; CI checking out with no history or with detached empty workspaces.","solutions":["Run `git init` in the directory (or cd into an actual repository)","Verify with `git rev-parse --git-dir` in the same directory","Pass a valid path with the -C global flag if relying on GlobalFlags","Check that the repository wasn't cloned with an incomplete/failed checkout"],"exampleFix":"// before\ndir, err := git.Dir()\n// after: guard beforehand\nif _, err := os.Stat(\".git\"); err != nil {\n    if err := run(\"git\", \"init\"); err != nil {\n        return err\n    }\n}\ndir, err := git.Dir()","handlingStrategy":"validation","validationCode":"func inGitRepo() bool {\n    dir, err := filepath.Abs(\".\")\n    if err != nil { return false }\n    for {\n        if fi, err := os.Stat(filepath.Join(dir, \".git\")); err == nil && (fi.IsDir() || fi.Mode().IsRegular()) {\n            return true\n        }\n        parent := filepath.Dir(dir)\n        if parent == dir { return false }\n        dir = parent\n    }\n}","typeGuard":null,"tryCatchPattern":"dir, err := git.Dir()\nif err != nil {\n    return fmt.Errorf(\"this command must run inside a git repository (run `git init` if needed)\")\n}","preventionTips":["Run `git init` before using repo-dependent commands in new projects","Check `git rev-parse --git-dir` succeeds before invoking the tool","Avoid running from $HOME or /tmp by accident","Validate any -C target path exists and is a repo"],"tags":["git","repository","environment","working-directory"],"backgroundTag":"not-a-git-repository","analyzedSha":"5c547ed804368763064e51f3990851e267e88edd","analyzedAt":"2026-09-01T03:34:15.525Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}