{"record":{"id":"f570c341f0f0e4e5","repo":"gastownhall/beads","slug":"failed-to-read-git-worktree-registry-w","errorCode":null,"errorMessage":"failed to read git worktree registry: %w","messagePattern":"failed to read git worktree registry: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/worktree_cmd.go","lineNumber":762,"sourceCode":"\theadOID     string\n\tbranch      string\n\tdetached    bool\n\tbare        bool\n\tlocked      bool\n\tlockReason  string\n\tprunable    bool\n\tpruneReason string\n\tisMain      bool\n}\n\nfunc listRegisteredWorktrees(\n\tctx context.Context,\n\tgit *worktreeRemovalGit,\n\texecutionRoot string,\n) ([]registeredWorktree, error) {\n\toutput, err := git.output(ctx, executionRoot, \"worktree\", \"list\", \"--porcelain\", \"-z\")\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to read git worktree registry: %w\", err)\n\t}\n\n\tvar worktrees []registeredWorktree\n\tvar current registeredWorktree\n\tappendCurrent := func() {\n\t\tif current.path == \"\" {\n\t\t\treturn\n\t\t}\n\t\tcurrent.isMain = len(worktrees) == 0\n\t\tworktrees = append(worktrees, current)\n\t\tcurrent = registeredWorktree{}\n\t}\n\n\tfor _, field := range strings.Split(string(output), \"\\x00\") {\n\t\tif field == \"\" {\n\t\t\tcontinue\n\t\t}\n\t\tswitch {","sourceCodeStart":744,"sourceCodeEnd":780,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/worktree_cmd.go#L744-L780","documentation":"listRegisteredWorktrees reads the git worktree registry via `git worktree list --porcelain -z` before any removal, to validate the target. If the git call fails (non-zero exit with stderr, per the output() wrapper), the failure is wrapped with this message. bd needs the authoritative registry to safely prune the right worktree.","triggerScenarios":"prepareWorktreeRemoval / revalidation / removal-failure observation call listRegisteredWorktrees and the underlying `git worktree list --porcelain -z` exits non-zero — corrupt repo, locked index, invalid GIT_DIR remnants, or git binary failure.","commonSituations":"Broken .git/worktrees metadata after interrupted operations; concurrent git processes holding locks; running with a scrubbed environment in a directory that isn't a repository.","solutions":["Run `git worktree list` manually in the repo to see git's error","Clear stale locks (rm .git/index.lock) if a crash left them behind","Run `git worktree prune` to clean dangling registrations, then retry","Verify the execution root is the repository (not a deleted worktree path)"],"exampleFix":"// before\nbd worktree remove wt-x   # failed to read git worktree registry: ... index.lock\n// after\nrm -f .git/index.lock\ngit worktree prune\nbd worktree remove wt-x","handlingStrategy":"try-catch","validationCode":"git worktree list --porcelain >/dev/null 2>&1 || { echo \"worktree registry unreadable\"; exit 1; }","typeGuard":null,"tryCatchPattern":"if _, err := listRegisteredWorktrees(ctx, g, root); err != nil {\n    var ee *exec.ExitError\n    if errors.As(err, &ee) {\n        // inspect git stderr embedded by the output() wrapper, fix, then retry\n    }\n    return err\n}","preventionTips":["Clean stale locks after crashes (rm .git/index.lock)","Run `git worktree prune` after manually deleting worktrees","Never kill bd mid-removal; let revalidation complete","Keep git up to date for stable -z porcelain output"],"tags":["go","git","worktree","registry"],"backgroundTag":"git-command-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}