{"record":{"id":"a261361285bcdcaa","repo":"golang/go","slug":"s-exists-but-is-not-a-directory","errorCode":null,"errorMessage":"%s exists but is not a directory","messagePattern":"(.+?) exists but is not a directory","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/modfetch/codehost/git.go","lineNumber":59,"sourceCode":"}\n\nfunc (e notExistError) Error() string   { return e.err.Error() }\nfunc (notExistError) Is(err error) bool { return err == fs.ErrNotExist }\n\nconst gitWorkDirType = \"git3\"\n\nfunc newGitRepo(ctx context.Context, remote string, local bool) (Repo, error) {\n\tr := &gitRepo{remote: remote, local: local}\n\tif local {\n\t\tif strings.Contains(remote, \"://\") { // Local flag, but URL provided\n\t\t\treturn nil, fmt.Errorf(\"git remote (%s) lookup disabled\", remote)\n\t\t}\n\t\tinfo, err := os.Stat(remote)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tif !info.IsDir() {\n\t\t\treturn nil, fmt.Errorf(\"%s exists but is not a directory\", remote)\n\t\t}\n\t\tr.dir = remote\n\t\tr.mu.Path = r.dir + \".lock\"\n\t\tr.sha256Hashes = r.checkConfigSHA256(ctx)\n\t\treturn r, nil\n\t}\n\t// This is a remote path lookup.\n\tif !strings.Contains(remote, \"://\") { // No URL scheme, could be host:path\n\t\tif strings.Contains(remote, \":\") {\n\t\t\treturn nil, fmt.Errorf(\"git remote (%s) must not be local directory (use URL syntax not host:path syntax)\", remote)\n\t\t}\n\t\treturn nil, fmt.Errorf(\"git remote (%s) must not be local directory\", remote)\n\t}\n\tvar err error\n\tr.dir, r.mu.Path, err = WorkDir(ctx, gitWorkDirType, r.remote)\n\tif err != nil {\n\t\treturn nil, err\n\t}","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modfetch/codehost/git.go#L41-L77","documentation":"Thrown by newGitRepo in local mode when os.Stat(remote) succeeds (the path exists) but info.IsDir() is false — the 'remote' is a regular file, not a git checkout directory. A local git repository must be a directory.","triggerScenarios":"newGitRepo(ctx, remote, local=true) where remote is a path to a file (e.g. a tarball, a .git pack file, or any non-directory) rather than a working tree or bare repo directory.","commonSituations":"A replace directive pointing at a file instead of a directory; a path that was a directory but got replaced by an archive; a typo in the path resolving to a nearby file.","solutions":["Verify the path: 'ls -la <remote>' and confirm it is a directory.","Update the replace directive or path to point at the actual git working directory.","If you meant a remote URL, use URL syntax instead of a local path.","Extract the archive if the source was downloaded as a tarball."],"exampleFix":"# before (go.mod)\nreplace example.com/mod => ./mod.tar.gz\n# after\nmkdir -p ./mod && tar -xzf mod.tar.gz -C ./mod\nreplace example.com/mod => ./mod","handlingStrategy":"validation","validationCode":"func validateLocalRepoPath(path string) error {\n    fi, err := os.Stat(path)\n    if err != nil { return err }\n    if !fi.IsDir() {\n        return fmt.Errorf(\"%q exists but is not a directory\", path)\n    }\n    return nil\n}","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Point replace directives at directories, never at archives.","In setup scripts, os.Stat replace targets and assert IsDir.","Use 'go mod edit -replace' to set correct paths."],"tags":["git","local-mode","filesystem","replace-directive"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}