alibaba/open-code-review · error
%s is not a git repository
Error message
%s is not a git repository
What it means
When the target directory exists but `git rev-parse --git-dir` fails (or returns nothing) and requireGit is true, resolveWorkingDir rejects it with `<path> is not a git repository`. The review path requires a git repo because it sources diffs and HEAD content via git; the scan path (requireGit=false) tolerates non-repos instead.
Source
Thrown at cmd/opencodereview/shared.go:151
func resolveWorkingDir(input string, requireGit bool) (string, bool, error) {
if input == "" {
wd, err := os.Getwd()
if err != nil {
return "", false, fmt.Errorf("get working directory: %w", err)
}
input = wd
}
absPath, err := filepath.Abs(input)
if err != nil {
return "", false, fmt.Errorf("resolve absolute path: %w", err)
}
if _, statErr := os.Stat(absPath); statErr != nil {
return "", false, fmt.Errorf("stat %s: %w", absPath, statErr)
}
out, err := runGitCmd(absPath, "rev-parse", "--git-dir")
isGit := err == nil && len(out) > 0
if !isGit && requireGit {
return "", false, fmt.Errorf("%s is not a git repository", absPath)
}
// #287: git reports diff and `git show HEAD:<path>` paths relative to the
// repository root, not the current directory. When `ocr review` runs from a
// subdirectory of a monorepo, anchor RepoDir at the git top-level so those
// root-relative paths resolve for both disk reads and git-show reads.
// requireGit is true only for the review path; scan (requireGit=false) keeps
// the CWD so its `git ls-files` walk stays scoped to the subdirectory.
if isGit && requireGit {
// runGitCmdStdout captures stdout only so git stderr notices can't
// pollute the resolved path. --show-toplevel fails (or is empty) when
// there is no work tree — e.g. a bare repo, where --git-dir succeeds so
// isGit is true. Fail loudly there instead of silently reusing the
// subdir, which would reproduce the #287 root-relative-path bug.
top, topErr := runGitCmdStdout(absPath, "rev-parse", "--show-toplevel")
t := strings.TrimSpace(string(top))
if topErr != nil || t == "" {
return "", false, fmt.Errorf("%s is a git repository without a work tree (bare repo?); cannot resolve its top level for review", absPath)
}View on GitHub (pinned to 5cf97d0d15)
Solutions
- Run ocr review from inside a cloned git repository, or pass --dir pointing at one
- If the code came from a ZIP, git clone it instead so .git exists
- Check and unset stray GIT_DIR/GIT_WORK_TREE environment variables
- Repair or re-clone the repository if .git is corrupted
Example fix
// before cd ~/downloads/myrepo-zip && ocr review # no .git // after git clone https://host/myrepo.git && cd myrepo && ocr review
Defensive patterns
Strategy: validation
Validate before calling
out, err := exec.Command("git", "-C", dir, "rev-parse", "--git-dir").Output()
if err != nil || len(bytes.TrimSpace(out)) == 0 {
return fmt.Errorf("%s is not a git repository; clone it first", dir)
} Try / catch
if err != nil {
if strings.Contains(err.Error(), "not a git repository") {
// guide user to git clone instead of failing blind
}
return err
} Prevention
- Never review code extracted from ZIP archives without .git
- Unset GIT_DIR/GIT_WORK_TREE overrides before running
- Clone repositories rather than copying working trees
When it happens
Trigger: Running `ocr review` in a plain directory with no .git, inside a .git directory itself, in a worktree with corrupt git metadata, or with GIT_DIR misconfigured so rev-parse fails.
Common situations: Forgotten clone/downloaded ZIP of a repo (no .git); running from a random project folder; corrupted .git after a failed checkout; CI artifact extraction without git metadata; GIT_DIR/GIT_WORK_TREE env overrides pointing elsewhere.
Related errors
- get diffs: %w
- "%q %s" (+ positional signature, valid values, usage line, e
- read background file %q: %w
- background file %q is a directory, not a file
- background file %q is %d bytes, exceeding the maximum of %d
AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02).
Data as JSON: /api/errors/103dbd5ddc7355f7.
Report an issue: GitHub.