{"record":{"id":"b7d97a362f6cd184","repo":"can1357/oh-my-pi","slug":"current-git-repository-is-unavailable","errorCode":null,"errorMessage":"Current git repository is unavailable.","messagePattern":"Current git repository is unavailable\\.","errorType":"exception","errorClass":"ToolError","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/tools/gh-pr-checkout.ts","lineNumber":68,"sourceCode":"\t\t.toLowerCase()\n\t\t.replace(/[^a-z0-9]+/g, \"-\")\n\t\t.replace(/^-+/g, \"\")\n\t\t.replace(/-+$/g, \"\");\n\treturn sanitized.length > 0 ? `fork-${sanitized}` : \"fork\";\n}\n\n/** Maximum disambiguation suffixes we try before giving up on a worktree path. */\nexport const WORKTREE_PATH_MAX_SUFFIX = 100;\n\nexport function toLocalBranchRef(value: string): string {\n\treturn `refs/heads/${value}`;\n}\n\nexport async function requireGitRepoRoot(cwd: string, signal?: AbortSignal): Promise<string> {\n\tsignal?.throwIfAborted();\n\tconst repoRoot = vcs.git(cwd)?.info().repoRoot;\n\tif (!repoRoot) {\n\t\tthrow new ToolError(\"Current git repository is unavailable.\");\n\t}\n\n\treturn repoRoot;\n}\n\nexport async function requirePrimaryGitRepoRoot(cwd: string, signal?: AbortSignal): Promise<string> {\n\tsignal?.throwIfAborted();\n\tconst primaryRepoRoot = vcs.git(cwd)?.primaryRoot();\n\tif (!primaryRepoRoot) {\n\t\tthrow new ToolError(\"Current git repository is unavailable.\");\n\t}\n\n\treturn primaryRepoRoot;\n}\n\n/**\n * Resolve a worktree path that is free of conflicts.\n *","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/tools/gh-pr-checkout.ts#L50-L86","documentation":"requireGitRepoRoot resolves the enclosing git repository root via vcs.git(cwd)?.info().repoRoot and throws this ToolError when null — i.e. the working directory is not inside a git repository (or the vcs wrapper failed). PR checkout needs a repo root to anchor worktree paths.","triggerScenarios":"Calling repoRoot() (backed by requireGitRepoRoot) from a directory outside any git work tree, or where git info cannot report a repoRoot (bare path, git unavailable, aborted signal).","commonSituations":"Agent launched in a temp/home directory; project not yet git-initialized; git binary missing or broken so info() fails silently to null.","solutions":["Run the PR checkout from inside a git repository.","Run `git init` if the project should be a repo, or `git clone` it first.","Confirm `git rev-parse --show-toplevel` succeeds in the target cwd."],"exampleFix":"// before\nawait checkoutPullRequest({ cwd: \"/tmp/not-a-repo\", pr: 12 });\n// after\ncwd = \"/home/user/project\"; // a git repo\nawait checkoutPullRequest({ cwd, pr: 12 });","handlingStrategy":"validation","validationCode":"import { $ } from \"bun\";\nconst root = await $`git rev-parse --show-toplevel`.cwd(cwd).quiet().nothrow();\nif (root.exitCode !== 0) {\n  throw new Error(`${cwd} is not a git repository`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  const repoRoot = await repoRoot(cwd);\n} catch (err) {\n  if (err instanceof ToolError && err.message.includes(\"git repository is unavailable\")) {\n    // clone/init the repo or relocate cwd before retrying\n  } else throw err;\n}","preventionTips":["Verify the cwd is inside a git repo before PR checkout operations.","Run `git init`/`git clone` as part of environment setup.","Ensure the git binary is installed and on PATH in the execution environment."],"tags":["git","repository","environment"],"backgroundTag":"not-a-git-repository","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}