EveryInc/compound-engineering-plugin · error · Error

Failed to reset to origin/${branch}. ${resetErr.trim()}

Error message

Failed to reset to origin/${branch}. ${resetErr.trim()}

What it means

After a successful fetch, `plugin-path` runs `git reset --hard origin/<branch>` to move the working tree to the remote branch tip. Non-zero exit from that reset raises this error with git's stderr. This usually means origin/<branch> reference does not exist locally even after fetching, or the repo is in an inconsistent state.

Source

Thrown at src/commands/plugin-path.ts:114

    cwd: repoDir,
    stdout: "pipe",
    stderr: "pipe",
  })
  const fetchExit = await fetch.exited
  const fetchErr = await new Response(fetch.stderr).text()
  if (fetchExit !== 0) {
    throw new Error(`Failed to fetch branch '${branch}'. ${fetchErr.trim()}`)
  }

  const reset = Bun.spawn(["git", "reset", "--hard", `origin/${branch}`], {
    cwd: repoDir,
    stdout: "pipe",
    stderr: "pipe",
  })
  const resetExit = await reset.exited
  const resetErr = await new Response(reset.stderr).text()
  if (resetExit !== 0) {
    throw new Error(`Failed to reset to origin/${branch}. ${resetErr.trim()}`)
  }
}

function resolveGitHubSource(): string {
  const override = process.env.COMPOUND_PLUGIN_GITHUB_SOURCE
  if (override && override.trim()) return override.trim()
  return "https://github.com/EveryInc/compound-engineering-plugin"
}

View on GitHub (pinned to c9c10f8c75)

Solutions

  1. Delete the target/cached repo directory and re-run for a clean clone.
  2. Remove a stale lock: check for `<repo>/.git/index.lock` and delete it if no git process is running.
  3. Inspect git's stderr in the message for the precise cause and address it in the cached repo.
  4. Avoid running two plugin-path invocations for the same branch/target concurrently.

Example fix

// before
plugin-path compound-engineering --branch feat/x   # fails: index.lock
// after
rm -f <target-dir>/.git/index.lock && plugin-path compound-engineering --branch feat/x
Defensive patterns

Strategy: fallback

Validate before calling

// If a cached repo exists, make sure it is healthy before plugin-path uses it
if (existsSync(targetDir)) {
  const r = Bun.spawnSync(["git", "-C", targetDir, "status"])
  if (r.exitCode !== 0) { fs.rmSync(targetDir, { recursive: true, force: true }) }
}

Try / catch

try {
  const p = await pluginPath(plugin, { branch })
} catch (e) {
  if (e instanceof Error && e.message.includes("Failed to reset to origin/")) {
    fs.rmSync(targetDir, { recursive: true, force: true }) // nuke broken cache
    return pluginPath(plugin, { branch })
  } else throw e
}

Prevention

When it happens

Trigger: Fetch succeeded but `origin/<branch>` ref is absent (unusual fetch behavior / partial clone), the repo directory was manually modified or corrupted (e.g. interrupted previous run), or git refuses reset because of an index.lock left behind by a concurrent process.

Common situations: Two plugin-path runs racing on the same target directory (index.lock); a previous run was killed mid-clone leaving a broken repo; branch renamed with the old cached ref still expected.

Related errors


AI-assisted analysis of EveryInc/compound-engineering-plugin@c9c10f8c75 (2026-08-31). Data as JSON: /api/errors/16aae90fd754066e. Report an issue: GitHub.