{"record":{"id":"35c5cc44ff6f2b75","repo":"alibaba/open-code-review","slug":"s-is-not-a-git-repository-code-review-requires-a","errorCode":null,"errorMessage":"%s is not a git repository, code review requires a valid git repository","messagePattern":"(.+?) is not a git repository, code review requires a valid git repository","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/opencodereview/review_cmd.go","lineNumber":454,"sourceCode":"\n// resolveRepoDir resolves the repo dir for `ocr rules check`. It delegates to\n// resolveWorkingDir(requireGit=true) so it anchors at the git top-level just\n// like the review path — keeping rule resolution consistent when run from a\n// monorepo subdirectory (#287).\nfunc resolveRepoDir(input string) (string, error) {\n\tabsPath, _, err := resolveWorkingDir(input, true)\n\treturn absPath, err\n}\n\n// requireGitRepo validates that the given directory is part of a git repository.\nfunc requireGitRepo(dir string) error {\n\trepoDir, err := filepath.Abs(dir)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"resolve path: %w\", err)\n\t}\n\tout, err := runGitCmd(repoDir, \"rev-parse\", \"--git-dir\")\n\tif err != nil || len(out) == 0 {\n\t\treturn fmt.Errorf(\"%s is not a git repository, code review requires a valid git repository\", repoDir)\n\t}\n\treturn nil\n}\n\n// validateReviewRefs rejects ref-option injection (#112): any --from/--to/\n// --commit value must be a real commit ref and must not start with '-'.\nfunc validateReviewRefs(repoDir string, opts reviewOptions) error {\n\trefs := []struct {\n\t\tflag string\n\t\tref  string\n\t}{\n\t\t{\"--from\", opts.from},\n\t\t{\"--to\", opts.to},\n\t\t{\"--commit\", opts.commit},\n\t}\n\tfor _, item := range refs {\n\t\tif item.ref == \"\" {\n\t\t\tcontinue","sourceCodeStart":436,"sourceCodeEnd":472,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/cmd/opencodereview/review_cmd.go#L436-L472","documentation":"requireGitRepo runs `git rev-parse --git-dir` in the given directory; if the command fails or returns empty output, the directory is not inside a git repository and this error is thrown. Code review (diffing) fundamentally requires a git repo, so the tool refuses to proceed.","triggerScenarios":"Executing any review/rules command whose --repo or working directory is not inside a git work tree (no .git, bare parent, or git not installed so the probe fails).","commonSituations":"Running `ocr review` in a plain folder downloaded as a zip/tarball; pointing --repo at a non-repo subdirectory; missing git binary in a CI container.","solutions":["Run `git init` in the directory if it should be a repository.","Point --repo (or cd) at a directory that is actually inside a git work tree.","Confirm git is installed and on PATH (`git --version`) — a missing binary also makes the probe fail.","If the code came from an archive, clone it with git instead of downloading a snapshot."],"exampleFix":"// before\ncd /tmp/source-snapshot && ocr review --commit HEAD\n// after\ngit clone https://example.com/repo && cd repo && ocr review --commit HEAD","handlingStrategy":"validation","validationCode":"func inGitRepo(dir string) bool {\n    out, err := exec.Command(\"git\", \"-C\", dir, \"rev-parse\", \"--git-dir\").Output()\n    return err == nil && len(bytes.TrimSpace(out)) > 0\n}","typeGuard":null,"tryCatchPattern":"if err := requireGitRepo(dir); err != nil {\n    fmt.Fprintf(os.Stderr, \"hint: run inside a git work tree or pass --repo <path>\\n\")\n    os.Exit(1)\n}","preventionTips":["Clone repos with git instead of downloading archives when you plan to run reviews.","Verify `git --version` works in CI images (git must be on PATH).","Run `git init` early in scratch projects if you intend to review them."],"tags":["git","repository","validation"],"backgroundTag":"not-a-git-repository","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}