{"record":{"id":"10f40fbcba7e72af","repo":"can1357/oh-my-pi","slug":"current-git-head-is-unavailable-pass-run-explic","errorCode":null,"errorMessage":"Current git HEAD is unavailable. Pass `run` explicitly.","messagePattern":"Current git HEAD is unavailable\\. Pass `run` explicitly\\.","errorType":"exception","errorClass":"ToolError","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/tools/gh-common.ts","lineNumber":125,"sourceCode":"\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}`;\n\tif (author.name) return author.name;\n\treturn undefined;\n}\n\nexport function formatLabels(labels: GhLabel[] | undefined): string | undefined {\n\tconst names = labels?.map(label => label.name).filter((value): value is string => Boolean(value)) ?? [];\n\tif (names.length === 0) return undefined;\n\treturn names.join(\", \");\n}\n","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/tools/gh-common.ts#L107-L143","documentation":"requireCurrentGitHead resolves the current HEAD commit SHA from the local git repo and throws when it cannot (no repo, or headSha lookup failed). The message directs the caller to pass `run` explicitly since the SHA cannot be inferred.","triggerScenarios":"executeRunWatch() (or similar gh run tooling) called without a run identifier in a directory where vcs.git(cwd) returns null or repo.headSha() rejects/returns null — non-repo cwd, empty repo with no commits, git failure.","commonSituations":"Watching a GitHub Actions run from a freshly initialized repo with zero commits; running outside a repo; detached/broken HEAD.","solutions":["Pass the run explicitly (run URL or run id) instead of relying on HEAD resolution.","Run inside a git repository that has at least one commit.","Check `git rev-parse HEAD` manually to confirm HEAD is resolvable."],"exampleFix":"// before\nawait executeRunWatch({ cwd });\n// after\nawait executeRunWatch({ cwd, run: \"https://github.com/owner/repo/actions/runs/123\" });","handlingStrategy":"validation","validationCode":"import { $ } from \"bun\";\nconst head = await $`git rev-parse HEAD`.cwd(cwd).quiet().nothrow();\nif (head.exitCode !== 0) {\n  // repo missing/empty: supply the run id explicitly\n}","typeGuard":null,"tryCatchPattern":"try {\n  await executeRunWatch({ cwd });\n} catch (err) {\n  if (err instanceof ToolError && err.message.includes(\"Current git HEAD is unavailable\")) {\n    await executeRunWatch({ cwd, run: runUrlOrId });\n  } else throw err;\n}","preventionTips":["In CI or fresh clones, always pass the run identifier explicitly.","Ensure the repo has at least one commit before relying on HEAD inference.","Verify `git rev-parse HEAD` succeeds in the target directory."],"tags":["git","head","github","arguments"],"backgroundTag":"git-branch-unavailable","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}