{"record":{"id":"fddb5480e84b8086","repo":"can1357/oh-my-pi","slug":"origin-remote-is-unavailable-for-this-repository","errorCode":null,"errorMessage":"origin remote is unavailable for this repository.","messagePattern":"origin remote is unavailable for this repository\\.","errorType":"exception","errorClass":"ToolError","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/tools/gh-pr-checkout.ts","lineNumber":154,"sourceCode":"\nexport async function ensurePrRemote(\n\trepoRoot: string,\n\tdata: GhPrViewData,\n\tsignal?: AbortSignal,\n): Promise<{ name: string; url: string }> {\n\treturn ensurePrRemoteWithRepo(repoRoot, data, vcs.requireGit(repoRoot), signal);\n}\n\nasync function ensurePrRemoteWithRepo(\n\trepoRoot: string,\n\tdata: GhPrViewData,\n\trepository: VcsGitRepo,\n\tsignal?: AbortSignal,\n): Promise<{ name: string; url: string }> {\n\tif (!data.isCrossRepository) {\n\t\tconst originUrl = await repository.remoteUrl(\"origin\", signal);\n\t\tif (!originUrl) {\n\t\t\tthrow new ToolError(\"origin remote is unavailable for this repository.\");\n\t\t}\n\n\t\treturn {\n\t\t\tname: \"origin\",\n\t\t\turl: originUrl,\n\t\t};\n\t}\n\n\tconst headRepository = requireNonEmpty(data.headRepository?.nameWithOwner, \"head repository\");\n\tconst pullRepo = parsePullRequestUrl(data.url).repo;\n\tconst pullHost = pullRepo ? parseRepoRef(pullRepo).host : undefined;\n\tconst repoSummary = await github.json<GhRepoViewData>(\n\t\trepoRoot,\n\t\t[\"repo\", \"view\", formatRepoRef(pullHost, headRepository), \"--json\", GH_REPO_CLONE_FIELDS.join(\",\")],\n\t\tsignal,\n\t\t{ repoProvided: true },\n\t);\n\tconst originUrl = await repository.remoteUrl(\"origin\", signal);","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/tools/gh-pr-checkout.ts#L136-L172","documentation":"ensurePrRemoteWithRepo, for same-repository PRs, reuses the `origin` remote URL as the clone/worktree source. If `repository.remoteUrl(\"origin\")` returns null — no origin remote is configured — it throws this ToolError because there is no URL to fetch the PR from.","triggerScenarios":"checkoutPullRequest on a PR whose head is in the same repository, in a repo that has no `origin` remote (cloned from a local path, added as a secondary remote with another name, or initialized locally).","commonSituations":"Repo initialized locally (git init) then PR opened after pushing via a differently named remote; remotes renamed so origin is missing; sparse CI checkouts that strip remotes.","solutions":["Add the origin remote: `git remote add origin <https or ssh GitHub URL>` and retry.","Point the checkout at the correct existing remote by configuring/renaming it to origin (`git remote rename upstream origin`).","If it's a cross-repo PR, ensure headRepository metadata is correct so the fork URL path is taken instead of the origin path."],"exampleFix":"# before\n$ git remote -v   # (empty or only 'upstream')\n# after\n$ git remote add origin https://github.com/owner/repo.git\n$ git fetch origin","handlingStrategy":"validation","validationCode":"import { $ } from \"bun\";\nconst remote = await $`git remote get-url origin`.cwd(cwd).quiet().nothrow();\nif (remote.exitCode !== 0) {\n  throw new Error(\"origin remote missing; add it before PR checkout\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  await checkoutPullRequest({ cwd, pr });\n} catch (err) {\n  if (err instanceof ToolError && err.message.includes(\"origin remote is unavailable\")) {\n    await $`git remote add origin https://github.com/owner/repo.git`.cwd(cwd);\n    // retry checkout\n  } else throw err;\n}","preventionTips":["Always configure an `origin` remote pointing at the GitHub repo.","Avoid renaming origin in shared setups; add extra remotes under other names.","Check `git remote -v` during environment setup."],"tags":["git","remote","github","configuration"],"backgroundTag":"origin-remote-missing","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}