{"record":{"id":"e8163b9b412e468e","repo":"can1357/oh-my-pi","slug":"current-git-branch-is-unavailable-pass-branch-o","errorCode":null,"errorMessage":"Current git branch is unavailable. Pass `branch` or `run` explicitly.","messagePattern":"Current git branch is unavailable\\. Pass `branch` or `run` explicitly\\.","errorType":"exception","errorClass":"ToolError","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/tools/gh-common.ts","lineNumber":115,"sourceCode":" * can never be redirected: with `GH_HOST` set elsewhere, even a github.com\n * checkout keeps its host.\n */\nexport function repoFromUrl(value: string | undefined): string | undefined {\n\tconst match = REPO_URL_PATTERN.exec(value?.trim() ?? \"\");\n\tif (!match) return undefined;\n\tconst host = match[1].toLowerCase();\n\tconst slug = `${match[2]}/${match[3]}`;\n\treturn host === defaultGhHost() ? slug : formatRepoRef(host, slug);\n}\n\nexport const PR_URL_PATTERN = /^https:\\/\\/([^/]+)\\/([^/]+\\/[^/]+)\\/pull\\/(\\d+)(?:\\/.*)?$/;\nexport const ISSUE_URL_PATTERN = /^https:\\/\\/([^/]+)\\/([^/]+\\/[^/]+)\\/issues\\/(\\d+)(?:\\/.*)?$/;\n\nexport async function requireCurrentGitBranch(cwd: string, signal?: AbortSignal): Promise<string> {\n\tconst repo = vcs.git(cwd);\n\tconst branch = repo ? await repo.currentBranch(signal).catch(() => null) : null;\n\tif (!branch) {\n\t\tthrow new ToolError(\"Current git branch is unavailable. Pass `branch` or `run` explicitly.\");\n\t}\n\n\treturn branch;\n}\n\nexport async function requireCurrentGitHead(cwd: string, signal?: AbortSignal): Promise<string> {\n\tconst repo = vcs.git(cwd);\n\tconst headSha = repo ? await repo.headSha(signal).catch(() => null) : null;\n\tif (!headSha) {\n\t\tthrow new ToolError(\"Current git HEAD is unavailable. Pass `run` explicitly.\");\n\t}\n\n\treturn headSha;\n}\n\nexport function formatAuthor(author: GhUser | null | undefined): string | undefined {\n\tif (!author) return undefined;\n\tif (author.login) return `@${author.login}`;","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/tools/gh-common.ts#L97-L133","documentation":"requireCurrentGitBranch asks the local git repo for the current branch and throws this ToolError when neither a repo nor a branch can be determined. It exists so gh tools fail with a clear message telling the caller to supply `branch` (or `run`) explicitly instead of guessing.","triggerScenarios":"Calling localBranch() or executeRunWatch() in a directory that is not a git repo, or where `git rev-parse --abbrev-ref HEAD`-style lookup fails or returns null (detached HEAD flows in some wrappers, bare repo, git missing).","commonSituations":"Running the gh pr/pull tool from a non-repo directory; a detached HEAD state; corrupted or missing git binary; CI checkouts without a branch ref.","solutions":["Run the tool from inside a git repository with an active branch.","Pass the branch explicitly via the `branch` option (or a `run` URL that encodes it).","Verify git is installed and the directory has a .git (or parent repo) — check `git rev-parse --is-inside-work-tree`."],"exampleFix":"// before\nconst branch = await localBranch({ cwd });\n// after\nconst branch = await localBranch({ cwd, branch: \"feature/x\" });","handlingStrategy":"validation","validationCode":"import { $ } from \"bun\";\nconst inside = await $`git rev-parse --abbrev-ref HEAD`.cwd(cwd).quiet().nothrow();\nif (inside.exitCode !== 0) {\n  // pass branch explicitly or move to a repo\n}","typeGuard":null,"tryCatchPattern":"try {\n  const branch = await localBranch({ cwd });\n} catch (err) {\n  if (err instanceof ToolError && err.message.includes(\"Current git branch is unavailable\")) {\n    return localBranch({ cwd, branch: explicitBranch });\n  }\n  throw err;\n}","preventionTips":["Always run gh tools from inside a git repository with an active branch.","Prefer passing `branch` (or a run URL) explicitly in scripts and CI.","Check `git rev-parse --is-inside-work-tree` when the cwd is dynamic."],"tags":["git","branch","github","arguments"],"backgroundTag":"git-branch-unavailable","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}