{"record":{"id":"d5c1bb2fd28ef2ac","repo":"gastownhall/beads","slug":"failed-to-inspect-created-worktree-cleanliness-w","errorCode":null,"errorMessage":"failed to inspect created worktree cleanliness: %w\n%s","messagePattern":"failed to inspect created worktree cleanliness: %w\n(.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/worktree_cmd.go","lineNumber":451,"sourceCode":"\tfmt.Printf(\"  Main repo: %s\\n\", mainRepoRoot)\n\tif redirectInfo.IsRedirected {\n\t\tfmt.Printf(\"  Beads: redirects to %s\\n\", redirectInfo.TargetDir)\n\t} else {\n\t\tfmt.Printf(\"  Beads: local (no redirect)\\n\")\n\t}\n\n\treturn nil\n}\n\n// Helper functions\n\nvar checkCreatedWorktreeClean = ensureCreatedWorktreeClean\n\nfunc ensureCreatedWorktreeClean(ctx context.Context, worktreePath string) error {\n\tgitCmd := gitCmdInDir(ctx, worktreePath, \"status\", \"--porcelain=v1\", \"--untracked-files=all\")\n\toutput, err := gitCmd.CombinedOutput()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to inspect created worktree cleanliness: %w\\n%s\", err, string(output))\n\t}\n\n\tif status := strings.TrimSpace(string(output)); status != \"\" {\n\t\treturn fmt.Errorf(\"created worktree is dirty after checkout; refusing to continue: %s\\n%s\", worktreePath, status)\n\t}\n\n\treturn nil\n}\n\n// gitCmdInDir creates a git command that runs in the specified directory.\n// This is used for worktree operations that need to run in a specific location\n// (either the CWD repo root or a specific worktree path).\n//\n// Security: Sets core.hooksPath and GIT_TEMPLATE_DIR to disable hooks/templates\n// for defense-in-depth, matching the pattern in RepoContext.GitCmd().\nfunc gitCmdInDir(ctx context.Context, dir string, args ...string) *exec.Cmd {\n\tgitArgs := append([]string{\"-c\", \"core.hooksPath=\"}, args...)\n\tcmd := exec.CommandContext(ctx, \"git\", gitArgs...)","sourceCodeStart":433,"sourceCodeEnd":469,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/worktree_cmd.go#L433-L469","documentation":"After `bd worktree create` checks out a new worktree, ensureCreatedWorktreeClean runs `git status --porcelain=v1 --untracked-files=all` inside it to verify the checkout succeeded. If the git subprocess itself exits non-zero (rather than reporting a dirty status), this error wraps the exec error plus the combined stdout/stderr of git. It is a safety gate: bd refuses to continue without confidence the new worktree is clean.","triggerScenarios":"`git status` returning non-zero in the freshly created worktree path — e.g. the worktree directory is corrupt, .git metadata missing, a git hook (hooks are suppressed but config aliases/smudge filters can still fail), or the checkout left git in a bad state.","commonSituations":"Broken git configuration (e.g. a global filter driver like git-lfs that fails on checkout); antivirus/index locks interfering on Windows; disk full during checkout; worktree path created but registration with the main repo failed.","solutions":["Read the appended git output in the error message to see the actual git failure cause","Run `git status --porcelain=v1` manually inside the worktree path to reproduce","Fix the underlying git issue (e.g. git-lfs: run `git lfs install`; locks: remove index.lock)","Remove the bad worktree and re-create it: `git worktree remove <path> --force` then `bd worktree create ...`"],"exampleFix":"// reproduce/diagnose\ncd /path/to/new-worktree && git status --porcelain=v1\n// if git-lfs filter fails\ngit lfs install && git worktree remove --force . && bd worktree create .","handlingStrategy":"try-catch","validationCode":"cd <worktreePath> && git status --porcelain=v1 --untracked-files=all\n# expect exit 0 and empty output before/after bd worktree create","typeGuard":null,"tryCatchPattern":"out, err := exec.Command(\"git\", \"-C\", wtPath, \"status\", \"--porcelain=v1\").CombinedOutput()\nif err != nil {\n    return fmt.Errorf(\"git status failed in %s: %w\\n%s\", wtPath, err, out)\n}","preventionTips":["Install/configure git filters (git-lfs) before creating worktrees","Keep .gitignore complete so generated files don't dirty checkouts","Never leave stale files at the target worktree path","Watch disk space during checkout operations"],"tags":["go","git","worktree","subprocess"],"backgroundTag":"git-command-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}