{"record":{"id":"e2a308bbd1ebd133","repo":"alibaba/open-code-review","slug":"get-diffs-w","errorCode":null,"errorMessage":"get diffs: %w","messagePattern":"get diffs: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/agent/agent.go","lineNumber":546,"sourceCode":"\t\tcase commit != \"\":\n\t\t\tcommit = s.ResolvedHead\n\t\tcase s.ResolvedBase != \"\":\n\t\t\tfrom, to = s.ResolvedBase, s.ResolvedHead\n\t\t}\n\t}\n\n\tswitch {\n\tcase commit != \"\":\n\t\tprovider = diff.NewCommitProvider(a.args.RepoDir, commit, a.args.GitRunner)\n\tcase from != \"\" && to != \"\":\n\t\tprovider = diff.NewProvider(a.args.RepoDir, from, to, a.args.GitRunner)\n\tdefault:\n\t\tprovider = diff.NewWorkspaceProvider(a.args.RepoDir, a.args.GitRunner)\n\t}\n\n\tparsed, err := provider.GetDiff(ctx)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"get diffs: %w\", err)\n\t}\n\n\ta.diffs = parsed\n\n\t// Freeze this run's real commit endpoints and repository identity while the\n\t// git-backed provider and a live context are in hand; finalizeManifest reads\n\t// these (never re-resolving) so the manifest records the input as it was at\n\t// dispatch time, even on a later skipped or failed path.\n\ta.inputResolution = provider.ResolveInput(ctx)\n\ta.repoRemoteIdentity = provider.RemoteIdentity(ctx)\n\n\tfor i := range parsed {\n\t\td := &parsed[i]\n\t\ta.totalInsertions += d.Insertions\n\t\ta.totalDeletions += d.Deletions\n\t}\n\n\treturn nil","sourceCodeStart":528,"sourceCodeEnd":564,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/internal/agent/agent.go#L528-L564","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"// before: 'get diffs: exit status 128 - fatal: bad revision main..feat/x'\nocr review --from main --to featx   // typo\n// after\nocr review --from main --to feat/x  // correct ref, after `git fetch origin`","handlingStrategy":"validation","validationCode":"// validate repo and refs before calling Run\ncmd := exec.Command(\"git\", \"-C\", repoDir, \"rev-parse\", \"--verify\", ref)\nif err := cmd.Run(); err != nil { return fmt.Errorf(\"ref %s missing in %s\", ref, repoDir) }\n// and confirm it is a work tree:\nexec.Command(\"git\", \"-C\", repoDir, \"rev-parse\", \"--is-inside-work-tree\").Run()","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["git","diff","cli","go"],"backgroundTag":"git-diff-failed","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}