{"record":{"id":"31b63040148b3e6c","repo":"gastownhall/beads","slug":"git-worktree-registry-is-empty","errorCode":null,"errorMessage":"git worktree registry is empty","messagePattern":"git worktree registry is empty","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/worktree_cmd.go","lineNumber":807,"sourceCode":"\t\t\tcurrent.detached = true\n\t\tcase field == \"bare\":\n\t\t\tcurrent.bare = true\n\t\tcase field == \"locked\":\n\t\t\tcurrent.locked = true\n\t\tcase strings.HasPrefix(field, \"locked \"):\n\t\t\tcurrent.locked = true\n\t\t\tcurrent.lockReason = strings.TrimPrefix(field, \"locked \")\n\t\tcase field == \"prunable\":\n\t\t\tcurrent.prunable = true\n\t\tcase strings.HasPrefix(field, \"prunable \"):\n\t\t\tcurrent.prunable = true\n\t\t\tcurrent.pruneReason = strings.TrimPrefix(field, \"prunable \")\n\t\t}\n\t}\n\tappendCurrent()\n\n\tif len(worktrees) == 0 {\n\t\treturn nil, fmt.Errorf(\"git worktree registry is empty\")\n\t}\n\treturn worktrees, nil\n}\n\nfunc sameWorktreePath(left, right string) bool {\n\tleftAbsolute, leftErr := filepath.Abs(left)\n\trightAbsolute, rightErr := filepath.Abs(right)\n\tif leftErr != nil || rightErr != nil {\n\t\treturn false\n\t}\n\tleftAbsolute = filepath.Clean(leftAbsolute)\n\trightAbsolute = filepath.Clean(rightAbsolute)\n\n\t// When both paths are missing, peel exact components in lockstep until\n\t// existing ancestors can prove physical identity. This accepts equivalent\n\t// ancestor spellings such as a Windows 8.3 alias without ever case-folding\n\t// an unresolved component.\n\tfor {","sourceCodeStart":789,"sourceCodeEnd":825,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/worktree_cmd.go#L789-L825","documentation":"After parsing `git worktree list --porcelain -z`, listRegisteredWorktrees asserts the registry contains at least one entry (git always reports the main working tree). An empty list means git returned success but no worktrees — a logically impossible state signaling repo metadata corruption or an unexpected git output format, so bd fails closed rather than removing anything.","triggerScenarios":"`git worktree list --porcelain -z` succeeds but yields zero parseable worktree entries — e.g. a heavily corrupted repository, a git version producing unexpected porcelain output, or output being swallowed/truncated by an unusual environment (GIT_PAGER or alternative git shim in PATH).","commonSituations":"Git shim/wrapper binaries (e.g. custom gits in PATH) emitting non-porcelain output; corrupted .git where even the main worktree entry is missing; exotic git builds or downgrade to a very old git.","solutions":["Verify git works: run `git worktree list --porcelain` and check output manually","Check which git is in PATH (`which git`) and ensure it's official git, not a shim","Run `git fsck` to check repository integrity; restore from a clone if corrupt","Update git to a current version and retry"],"exampleFix":"// before\nbd worktree remove wt-x   # git worktree registry is empty\n// after\nwhich git   # found nonstandard shim\nexport PATH=/usr/bin:$PATH\nbd worktree remove wt-x","handlingStrategy":"type-guard","validationCode":"n=$(git worktree list --porcelain | grep -c '^worktree ' || true)\n[ \"$n\" -ge 1 ] || { echo \"registry unexpectedly empty\"; exit 1; }","typeGuard":"if len(worktrees) == 0 {\n    // fail closed: refuse removal when the registry is unparseable/empty\n    return fmt.Errorf(\"git worktree registry is empty\")\n}","tryCatchPattern":"worktrees, err := listRegisteredWorktrees(ctx, g, root)\nif err != nil || len(worktrees) == 0 {\n    return fmt.Errorf(\"cannot verify worktree registry; aborting removal\")\n}","preventionTips":["Use official git builds, not PATH shims/wrappers","Run `git fsck` if the repo behaves oddly","Keep git reasonably current","Never bypass bd's removal preflight checks"],"tags":["go","git","worktree","corruption"],"backgroundTag":"git-worktree-registry-empty","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}