alibaba/open-code-review · error
get diffs: %w
Error message
get diffs: %w
What it means
loadDiffs obtains the diff via a provider (commit, range, or workspace) and wraps any provider.GetDiff failure with this message. The error means the git-level diff computation failed before any review work started: git itself errored, the repository/refs do not exist, or the context was cancelled.
Source
Thrown at internal/agent/agent.go:546
case commit != "":
commit = s.ResolvedHead
case s.ResolvedBase != "":
from, to = s.ResolvedBase, s.ResolvedHead
}
}
switch {
case commit != "":
provider = diff.NewCommitProvider(a.args.RepoDir, commit, a.args.GitRunner)
case from != "" && to != "":
provider = diff.NewProvider(a.args.RepoDir, from, to, a.args.GitRunner)
default:
provider = diff.NewWorkspaceProvider(a.args.RepoDir, a.args.GitRunner)
}
parsed, err := provider.GetDiff(ctx)
if err != nil {
return fmt.Errorf("get diffs: %w", err)
}
a.diffs = parsed
// Freeze this run's real commit endpoints and repository identity while the
// git-backed provider and a live context are in hand; finalizeManifest reads
// these (never re-resolving) so the manifest records the input as it was at
// dispatch time, even on a later skipped or failed path.
a.inputResolution = provider.ResolveInput(ctx)
a.repoRemoteIdentity = provider.RemoteIdentity(ctx)
for i := range parsed {
d := &parsed[i]
a.totalInsertions += d.Insertions
a.totalDeletions += d.Deletions
}
return nilView on GitHub (pinned to 5cf97d0d15)
Solutions
- Run `git -C <RepoDir> status` and `git rev-parse <ref>` manually to reproduce the underlying git error.
- Verify the commit/range refs exist and the repo is a valid clone (fetch missing refs if shallow).
- Confirm RepoDir points at the repository root and git is on PATH.
- For workspace mode, ensure there are readable worktree changes and the index is not locked (.git/index.lock).
Example fix
// before: 'get diffs: exit status 128 - fatal: bad revision main..feat/x' ocr review --from main --to featx // typo // after ocr review --from main --to feat/x // correct ref, after `git fetch origin`
Defensive patterns
Strategy: validation
Validate before calling
// validate repo and refs before calling Run
cmd := exec.Command("git", "-C", repoDir, "rev-parse", "--verify", ref)
if err := cmd.Run(); err != nil { return fmt.Errorf("ref %s missing in %s", ref, repoDir) }
// and confirm it is a work tree:
exec.Command("git", "-C", repoDir, "rev-parse", "--is-inside-work-tree").Run() Prevention
- Always fetch the base branch in CI (shallow clones need git fetch --depth or unshallow for range diffs).
- Validate commit/range arguments with git rev-parse before invoking the tool.
- Run the tool with RepoDir set to the repository root.
- Ensure git is installed and GIT_* env vars don't redirect to another repository.
When it happens
Trigger: Agent.Run() or ResolveIdentity() with a RepoDir that is not a git repository; --commit or --from/--to refs that do not resolve; an empty repository; git binary missing; context cancelled during GetDiff.
Common situations: Typo in a commit SHA or branch name; running outside a repo; shallow clone missing the requested ref; detached CI checkout lacking the base branch; GIT_DIR/GIT_WORK_TREE env conflicts; git not installed in the container.
Related errors
- %s is not a git repository
- "%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/e2a308bbd1ebd133.
Report an issue: GitHub.