{"record":{"id":"7a99ecd0899d61a7","repo":"gastownhall/beads","slug":"failed-to-resolve-target-git-directory-w","errorCode":null,"errorMessage":"failed to resolve target git directory: %w","messagePattern":"failed to resolve target git directory: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/worktree_cmd.go","lineNumber":957,"sourceCode":"\tdetached             bool\n\tbare                 bool\n\tlocked               bool\n\tlockReason           string\n\tprunable             bool\n\tpruneReason          string\n\tstatus               string\n\tstatusFingerprint    string\n\tregistryID           string\n}\n\nfunc inspectWorktreeTarget(\n\tctx context.Context,\n\tgit *worktreeRemovalGit,\n\tworktree registeredWorktree,\n) (pinnedWorktreeTarget, error) {\n\tgitDirOutput, err := git.output(ctx, worktree.path, \"rev-parse\", \"--absolute-git-dir\")\n\tif err != nil {\n\t\treturn pinnedWorktreeTarget{}, fmt.Errorf(\"failed to resolve target git directory: %w\", err)\n\t}\n\tgitDir := filepath.Clean(strings.TrimSpace(string(gitDirOutput)))\n\tcommonDirOutput, err := git.output(\n\t\tctx,\n\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\",","sourceCodeStart":939,"sourceCodeEnd":975,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/worktree_cmd.go#L939-L975","documentation":"inspectWorktreeTarget runs `git rev-parse --absolute-git-dir` inside the target worktree to pin its git directory. If that command fails, this wrapped error is returned. It means git could not determine the .git directory for the worktree — the worktree is broken, missing, or git itself errored.","triggerScenarios":"Removal or revalidation on a registered worktree whose directory was deleted or corrupted, so git cannot resolve its git dir; git missing from PATH; the worktree's `.git` file points to a nonexistent gitdir; context cancellation kills the git subprocess.","commonSituations":"Someone deleted the worktree with rm -rf but the registry still lists it; a network-mounted worktree became unreadable; the main repo was moved so the .git file's gitdir pointer dangles; interrupted worktree creation.","solutions":["Inspect the wrapped git error; reproduce with `git -C <path> rev-parse --absolute-git-dir` to see the raw failure.","If the directory is gone, run `git worktree prune` and clean the bd registry entry, then retry.","If the .git file's gitdir pointer dangles (repo was moved), recreate the worktree with `git worktree add` and re-register it.","Verify git is on PATH and the path is readable by the current user."],"exampleFix":"// before\nbd worktree remove feature-x\n// error: failed to resolve target git directory: ... (directory deleted)\n// after\ngit worktree prune\nbd worktree remove feature-x   # registry now clean","handlingStrategy":"try-catch","validationCode":"const probe = Bun.spawnSync([\"git\", \"-C\", worktreePath, \"rev-parse\", \"--absolute-git-dir\"]);\nif (probe.exitCode !== 0) {\n  throw new Error(`worktree broken, prune instead: ${probe.stderr.toString()}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await bd(\"worktree\", \"remove\", path);\n} catch (e) {\n  if (String(e.message).includes(\"failed to resolve target git directory\")) {\n    execSync(\"git worktree prune\");\n  } else throw e;\n}","preventionTips":["Never rm -rf worktree directories; use `git worktree remove`.","Check `git worktree list` health before scripted removals.","Keep git on PATH and reasonably modern (>= 2.31).","Avoid moving the main repo after creating worktrees."],"tags":["worktree","git","rev-parse","broken-worktree"],"backgroundTag":"broken-git-worktree","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}