{"record":{"id":"6cb74bf2bab48b1e","repo":"gastownhall/beads","slug":"failed-to-enumerate-merged-into-ref-q-w","errorCode":null,"errorMessage":"failed to enumerate --merged-into ref %q: %w","messagePattern":"failed to enumerate --merged-into ref %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/worktree_cmd.go","lineNumber":1809,"sourceCode":"\tselector string,\n) ([]string, error) {\n\tcandidates := []string{\n\t\t\"refs/\" + selector,\n\t\t\"refs/tags/\" + selector,\n\t\t\"refs/heads/\" + selector,\n\t\t\"refs/remotes/\" + selector,\n\t\t\"refs/remotes/\" + selector + \"/HEAD\",\n\t}\n\tcandidateSet := make(map[string]struct{}, len(candidates))\n\tfor _, candidate := range candidates {\n\t\tcandidateSet[candidate] = struct{}{}\n\t}\n\n\targs := []string{\"for-each-ref\", \"--format=%(refname)\", \"--\"}\n\targs = append(args, candidates...)\n\toutput, err := git.output(ctx, executionRoot, args...)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to enumerate --merged-into ref %q: %w\", selector, err)\n\t}\n\n\tmatchSet := make(map[string]struct{})\n\tfor _, line := range strings.Split(strings.TrimSpace(string(output)), \"\\n\") {\n\t\tref := strings.TrimSpace(line)\n\t\tif _, candidate := candidateSet[ref]; candidate {\n\t\t\tmatchSet[ref] = struct{}{}\n\t\t}\n\t}\n\tmatches := make([]string, 0, len(matchSet))\n\tfor ref := range matchSet {\n\t\tmatches = append(matches, ref)\n\t}\n\tsort.Strings(matches)\n\treturn matches, nil\n}\n\nfunc repositoryObjectIDLength(","sourceCodeStart":1791,"sourceCodeEnd":1827,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/worktree_cmd.go#L1791-L1827","documentation":"`findWorktreeComparatorRefs` runs `git for-each-ref --format=%(refname) -- <candidates>` to enumerate which candidate refs match a `--merged-into` selector. If the git subprocess fails, the error is wrapped with the selector name.","triggerScenarios":"`git for-each-ref` exits non-zero — invalid/malformed candidate ref patterns, git subprocess environment failure, or running outside a repository.","commonSituations":"Corrupt refs directory; repository moved or `.git` broken; git version too old for used flags; a candidate pattern containing characters git rejects.","solutions":["Run `git for-each-ref --format=%(refname) -- <candidate>` manually to see the raw error","Verify you are inside a valid git repository","Repair repository state (`git fsck`) if refs are corrupt","Retry after confirming the `git` binary works and is up to date"],"exampleFix":"// diagnose\ngit for-each-ref --format=%(refname) -- refs/heads/*\n// then retry\nbd worktree remove --merged-into refs/heads/main","handlingStrategy":"try-catch","validationCode":"// shell pre-check\ngit for-each-ref --format='%(refname)' -- refs/heads/ >/dev/null 2>&1 || echo \"for-each-ref broken or not in repo\"","typeGuard":null,"tryCatchPattern":"if err != nil {\n    var ee *exec.ExitError\n    if errors.As(err, nil) || strings.Contains(err.Error(), \"for-each-ref\") {\n        // inspect repository health, retry after git fsck / re-clone\n    }\n}","preventionTips":["Keep the repository healthy (run `git fsck` periodically)","Avoid exotic characters in ref patterns","Ensure bd runs in the repository root or a registered worktree"],"tags":["git","subprocess","for-each-ref","cli"],"backgroundTag":"git-command-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}