{"record":{"id":"85471cead575745b","repo":"gastownhall/beads","slug":"target-head-does-not-resolve-to-a-commit-w","errorCode":null,"errorMessage":"target HEAD does not resolve to a commit: %w","messagePattern":"target HEAD does not resolve to a commit: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/worktree_cmd.go","lineNumber":980,"sourceCode":"\t\tworktree.path,\n\t\t\"rev-parse\",\n\t\t\"--path-format=absolute\",\n\t\t\"--git-common-dir\",\n\t)\n\tif err != nil {\n\t\treturn pinnedWorktreeTarget{}, fmt.Errorf(\"failed to resolve target common git directory: %w\", err)\n\t}\n\theadOutput, err := git.output(\n\t\tctx,\n\t\tworktree.path,\n\t\t\"rev-parse\",\n\t\t\"--verify\",\n\t\t\"--quiet\",\n\t\t\"--end-of-options\",\n\t\t\"HEAD^{commit}\",\n\t)\n\tif err != nil {\n\t\treturn pinnedWorktreeTarget{}, fmt.Errorf(\"target HEAD does not resolve to a commit: %w\", err)\n\t}\n\tstatusOutput, err := git.output(\n\t\tctx,\n\t\tworktree.path,\n\t\t\"status\",\n\t\t\"--porcelain=v1\",\n\t\t\"-z\",\n\t\t\"--untracked-files=all\",\n\t\t\"--ignore-submodules=none\",\n\t\t\"--ignored=matching\",\n\t)\n\tif err != nil {\n\t\treturn pinnedWorktreeTarget{}, fmt.Errorf(\"failed to inspect target cleanliness: %w\", err)\n\t}\n\n\theadOID := strings.TrimSpace(string(headOutput))\n\tif headOID == \"\" || headOID != worktree.headOID {\n\t\treturn pinnedWorktreeTarget{}, fmt.Errorf(","sourceCodeStart":962,"sourceCodeEnd":998,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/worktree_cmd.go#L962-L998","documentation":"inspectWorktreeTarget verifies the worktree's HEAD resolves to a commit via `git rev-parse --verify --quiet HEAD^{commit}`. When HEAD is unborn, corrupt, or unresolvable, this error is thrown before any destructive removal proceeds.","triggerScenarios":"Removing a worktree on an unborn branch (fresh `git worktree add` with a new branch and no commits); HEAD file corrupted; the referenced commit is missing from the object database (shallow/partial clone corruption, gc removed objects); git command failure.","commonSituations":"Worktree created from a brand-new branch never committed to; interrupted clone/checkout left objects missing; aggressive `git gc` or filesystem corruption removed objects; shallow fetch setups.","solutions":["Make at least one commit in the worktree or check out an existing branch so HEAD resolves, then retry removal.","Run `git -C <path> rev-parse HEAD^{commit}` to reproduce and inspect the raw error.","If objects are missing, re-fetch (`git fetch --unshallow` or fetch from origin) to restore them.","If the worktree is disposable, prune it (`git worktree prune`), remove the directory, and clean the registry."],"exampleFix":"// before\nbd worktree remove feature-x\n// error: target HEAD does not resolve to a commit (unborn branch)\n// after\ncd /repo/.worktrees/feature-x && git switch main\nbd worktree remove feature-x","handlingStrategy":"validation","validationCode":"const probe = Bun.spawnSync([\"git\", \"-C\", worktreePath, \"rev-parse\", \"--verify\", \"--quiet\", \"HEAD^{commit}\"]);\nif (probe.exitCode !== 0) {\n  throw new Error(`HEAD unresolvable (unborn branch or corrupt objects): ${worktreePath}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await bd(\"worktree\", \"remove\", path);\n} catch (e) {\n  if (String(e.message).includes(\"does not resolve to a commit\")) {\n    execSync(`git -C ${path} switch main`);\n  } else throw e;\n}","preventionTips":["Commit at least once or check out an existing branch in new worktrees before managing them.","Avoid aggressive gc/shallow setups that can strand objects referenced by HEAD.","Run `git fsck` if object corruption is suspected.","Verify HEAD resolves before scripted removal."],"tags":["worktree","git","head","rev-parse"],"backgroundTag":"unborn-head-no-commit","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}