{"record":{"id":"1576063fc09a246b","repo":"alibaba/open-code-review","slug":"s-is-a-git-repository-without-a-work-tree-bare-r","errorCode":null,"errorMessage":"%s is a git repository without a work tree (bare repo?); cannot resolve its top level for review","messagePattern":"(.+?) is a git repository without a work tree \\(bare repo\\?\\); cannot resolve its top level for review","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/opencodereview/shared.go","lineNumber":168,"sourceCode":"\tif !isGit && requireGit {\n\t\treturn \"\", false, fmt.Errorf(\"%s is not a git repository\", absPath)\n\t}\n\t// #287: git reports diff and `git show HEAD:<path>` paths relative to the\n\t// repository root, not the current directory. When `ocr review` runs from a\n\t// subdirectory of a monorepo, anchor RepoDir at the git top-level so those\n\t// root-relative paths resolve for both disk reads and git-show reads.\n\t// requireGit is true only for the review path; scan (requireGit=false) keeps\n\t// the CWD so its `git ls-files` walk stays scoped to the subdirectory.\n\tif isGit && requireGit {\n\t\t// runGitCmdStdout captures stdout only so git stderr notices can't\n\t\t// pollute the resolved path. --show-toplevel fails (or is empty) when\n\t\t// there is no work tree — e.g. a bare repo, where --git-dir succeeds so\n\t\t// isGit is true. Fail loudly there instead of silently reusing the\n\t\t// subdir, which would reproduce the #287 root-relative-path bug.\n\t\ttop, topErr := runGitCmdStdout(absPath, \"rev-parse\", \"--show-toplevel\")\n\t\tt := strings.TrimSpace(string(top))\n\t\tif topErr != nil || t == \"\" {\n\t\t\treturn \"\", false, fmt.Errorf(\"%s is a git repository without a work tree (bare repo?); cannot resolve its top level for review\", absPath)\n\t\t}\n\t\tabsPath = t\n\t}\n\treturn absPath, isGit, nil\n}\n\n// llmRuntime bundles the LLM-side state both subcommands need once they've\n// decided to actually run a session: tool definitions, an app-language\n// adjusted template (mutated in place via ApplyLanguage), the LLM client,\n// the resolved model name, and a fresh comment collector.\ntype llmRuntime struct {\n\tClient       llm.LLMClient\n\tModel        string\n\tProvider     string // resolved provider name (non-secret label; empty for non-provider endpoints)\n\tPlanToolDefs []llm.ToolDef\n\tMainToolDefs []llm.ToolDef\n\tCollector    *tool.CommentCollector\n\t// RetryCollector observes every LLM HTTP attempt this run makes. It is","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/cmd/opencodereview/shared.go#L150-L186","documentation":"When the path IS a git repository but `git rev-parse --show-toplevel` fails or returns empty, resolveWorkingDir concludes there is no work tree (a bare repo) and refuses to review. Bare repos have an object database but no checkout, so the #287 root-relative-path anchoring cannot resolve and diffs have no files on disk to read.","triggerScenarios":"Running `ocr review` against a bare clone (`git clone --bare`, server-side repos like /srv/git/project.git) with requireGit=true.","commonSituations":"Pointing ocr at a gitolite/Gitea server-side repo directory; using a --bare clone as CI workspace; shared bare mirror used for backups.","solutions":["Run ocr review against a normal (non-bare) clone: `git clone /srv/git/project.git` and point --dir at the clone","If you must review a bare repo's content, create a temporary worktree: `git -C <bare> worktree add /tmp/wt` and review /tmp/wt","Verify with `git -C <path> rev-parse --show-toplevel` before invoking"],"exampleFix":"// before\nocr review --dir /srv/git/project.git   # bare\n// after\ngit clone /srv/git/project.git /tmp/project && ocr review --dir /tmp/project","handlingStrategy":"validation","validationCode":"top, err := exec.Command(\"git\", \"-C\", dir, \"rev-parse\", \"--show-toplevel\").Output()\nif err != nil || len(bytes.TrimSpace(top)) == 0 {\n\treturn fmt.Errorf(\"%s has no work tree (bare repo); use a normal clone\", dir)\n}","typeGuard":null,"tryCatchPattern":"if err != nil {\n\t// fall back: create a temp worktree from the bare repo\n\t// git -C <bare> worktree add /tmp/wt && review /tmp/wt\n\treturn err\n}","preventionTips":["Point ocr at working clones, never server-side bare repos","git clone --bare is for hosting only; use a normal clone for CI review","Pre-check with git rev-parse --show-toplevel in wrapper scripts"],"tags":["go","git","bare-repository"],"backgroundTag":"bare-git-repository","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}