{"record":{"id":"23f67f564dcf9842","repo":"gastownhall/beads","slug":"w-s-23f67f","errorCode":null,"errorMessage":"%w: %s","messagePattern":"%w: %s","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/worktree_cmd.go","lineNumber":732,"sourceCode":"\n\tcommand := exec.CommandContext(ctx, git.executable, gitArgs...)\n\tcommand.Dir = dir\n\tcommand.Env = append([]string(nil), git.env...)\n\treturn command\n}\n\nfunc (git *worktreeRemovalGit) output(ctx context.Context, dir string, args ...string) ([]byte, error) {\n\tcommand := git.command(ctx, dir, args...)\n\toutput, err := command.Output()\n\tif err == nil {\n\t\treturn output, nil\n\t}\n\n\tvar exitError *exec.ExitError\n\tif errors.As(err, &exitError) {\n\t\tstderr := strings.TrimSpace(string(exitError.Stderr))\n\t\tif stderr != \"\" {\n\t\t\treturn output, fmt.Errorf(\"%w: %s\", err, stderr)\n\t\t}\n\t}\n\treturn output, err\n}\n\nfunc (git *worktreeRemovalGit) combinedOutput(ctx context.Context, dir string, args ...string) ([]byte, error) {\n\treturn git.command(ctx, dir, args...).CombinedOutput()\n}\n\ntype registeredWorktree struct {\n\tpath        string\n\theadOID     string\n\tbranch      string\n\tdetached    bool\n\tbare        bool\n\tlocked      bool\n\tlockReason  string\n\tprunable    bool","sourceCodeStart":714,"sourceCodeEnd":750,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/worktree_cmd.go#L714-L750","documentation":"worktreeRemovalGit.output runs a pinned git command and captures stdout. On failure it checks for exec.ExitError and, if git wrote anything to stderr, appends it: `\"%w: <stderr>\"`. The wrapped error is the exec.ExitError (non-zero git exit status); the message gives git's own diagnostic. All worktree-removal plumbing (list, inspect, ref validation, object-size checks) funnels through here.","triggerScenarios":"Any `git` invocation in the removal pipeline exits non-zero with stderr output — e.g. `git worktree list` in a corrupt repo, invalid ref names, missing objects, locked index, or running outside a work tree.","commonSituations":"Corrupted .git directory; referencing a branch/ref that doesn't exist; concurrent git operations holding index.lock; running the removal from a non-repo directory.","solutions":["Read the stderr text after the colon — it is git's own diagnosis","Fix the git-level issue it names (remove stale index.lock, repair repo, correct ref name)","Reproduce manually: run the same git command in the stated directory","Run `git fsck` if repo corruption is indicated"],"exampleFix":"// before\nbd worktree remove wt-x   # exit status 128: fatal: not a git repository\n// after\ncd /repos/main && bd worktree remove wt-x","handlingStrategy":"try-catch","validationCode":"git -C \"$DIR\" status --porcelain >/dev/null 2>&1 || { echo \"git failing in $DIR\"; exit 1; }","typeGuard":"var exitError *exec.ExitError\nif errors.As(err, &exitError) {\n    stderr := strings.TrimSpace(string(exitError.Stderr))\n    // act on git's stderr diagnostic\n}","tryCatchPattern":"out, err := gitCmd.Output()\nvar ee *exec.ExitError\nif errors.As(err, &ee) {\n    return fmt.Errorf(\"git failed (exit %d): %s\", ee.ExitCode(), strings.TrimSpace(string(ee.Stderr)))\n}","preventionTips":["Read the stderr after the colon — it is git's own diagnosis","Avoid concurrent git operations that create index.lock","Run `git fsck` periodically on active repos","Only invoke from valid repository directories"],"tags":["go","git","subprocess","exit-error"],"backgroundTag":"git-command-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}