{"record":{"id":"d22226cfe16b2e1e","repo":"EveryInc/compound-engineering-plugin","slug":"failed-to-fetch-branch-branch-fetcherr-tri","errorCode":null,"errorMessage":"Failed to fetch branch '${branch}'. ${fetchErr.trim()}","messagePattern":"Failed to fetch branch '(.+?)'\\. (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/commands/plugin-path.ts","lineNumber":103,"sourceCode":"    stderr: \"pipe\",\n  })\n  const exitCode = await proc.exited\n  const stderr = await new Response(proc.stderr).text()\n  if (exitCode !== 0) {\n    throw new Error(`Failed to clone branch '${branch}' from ${source}. ${stderr.trim()}`)\n  }\n}\n\nasync function fetchAndCheckout(repoDir: string, branch: string): Promise<void> {\n  const fetch = Bun.spawn([\"git\", \"fetch\", \"origin\", branch], {\n    cwd: repoDir,\n    stdout: \"pipe\",\n    stderr: \"pipe\",\n  })\n  const fetchExit = await fetch.exited\n  const fetchErr = await new Response(fetch.stderr).text()\n  if (fetchExit !== 0) {\n    throw new Error(`Failed to fetch branch '${branch}'. ${fetchErr.trim()}`)\n  }\n\n  const reset = Bun.spawn([\"git\", \"reset\", \"--hard\", `origin/${branch}`], {\n    cwd: repoDir,\n    stdout: \"pipe\",\n    stderr: \"pipe\",\n  })\n  const resetExit = await reset.exited\n  const resetErr = await new Response(reset.stderr).text()\n  if (resetExit !== 0) {\n    throw new Error(`Failed to reset to origin/${branch}. ${resetErr.trim()}`)\n  }\n}\n\nfunction resolveGitHubSource(): string {\n  const override = process.env.COMPOUND_PLUGIN_GITHUB_SOURCE\n  if (override && override.trim()) return override.trim()\n  return \"https://github.com/EveryInc/compound-engineering-plugin\"","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/EveryInc/compound-engineering-plugin/blob/c9c10f8c75412c7232cb2bd663e5fd1cea98d84e/src/commands/plugin-path.ts#L85-L121","documentation":"When the requested branch is already present in an existing local clone, `plugin-path` refreshes it with `git fetch origin <branch>` inside the repo and then hard-resets. This error fires when the fetch exits non-zero, with git's stderr embedded — typically because the branch no longer exists on the remote or the remote is unreachable.","triggerScenarios":"Re-running `plugin-path --branch <name>` against a cached clone when: the remote branch was deleted (fetch fails), network/auth failure contacting origin, or the source override changed so 'origin' points somewhere else.","commonSituations":"Feature branch merged and deleted upstream; stale cached clone from a previous run; VPN/proxy down; expired GitHub credentials.","solutions":["Confirm the branch still exists: `git ls-remote --heads <source> <branch>`; if deleted, pick another branch.","Delete the cached clone/target directory so the next run does a fresh clone instead of a fetch.","Fix network/proxy or refresh git credentials, then retry.","If COMPOUND_PLUGIN_GITHUB_SOURCE changed recently, clear the old clone that still points at the previous remote."],"exampleFix":"// before (branch deleted upstream, cached clone fetch fails)\nplugin-path compound-engineering --branch feat/old-branch\n// after\nrm -rf <cached-target-dir> && plugin-path compound-engineering","handlingStrategy":"fallback","validationCode":"// Ensure the remote branch still exists before refreshing a cached clone\nconst out = Bun.spawnSync([\"git\", \"ls-remote\", \"--heads\", source, branch])\nif (!out.stdout.toString().trim()) console.warn(`Branch ${branch} gone from remote; use a fresh clone or another branch`)","typeGuard":null,"tryCatchPattern":"try {\n  const p = await pluginPath(plugin, { branch })\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith(\"Failed to fetch branch\")) {\n    // stale cache: wipe and re-clone\n    fs.rmSync(targetDir, { recursive: true, force: true })\n    return pluginPath(plugin, { branch })\n  } else throw e\n}","preventionTips":["Delete cached clones when switching COMPOUND_PLUGIN_GITHUB_SOURCE or after branch deletions.","Check the branch still exists on the remote before re-running.","Avoid concurrent runs against the same target directory."],"tags":["git","fetch","network","stale-cache"],"backgroundTag":"git-fetch-failed","analyzedSha":"c9c10f8c75412c7232cb2bd663e5fd1cea98d84e","analyzedAt":"2026-08-31T15:18:07.959Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}