{"record":{"id":"2f4bc7e01c721afc","repo":"Yeachan-Heo/oh-my-codex","slug":"worktree-status-failed","errorCode":"worktree_status_failed","errorMessage":"worktree_status_failed:${worktreePath}","messagePattern":"worktree_status_failed:(.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/team/worktree.ts","lineNumber":131,"sourceCode":"}\n\nfunction branchExists(repoRoot: string, branchName: string): boolean {\n  const result = spawnSync('git', ['show-ref', '--verify', '--quiet', `refs/heads/${branchName}`], {\n    cwd: repoRoot,\n    encoding: 'utf-8',\n  });\n  return result.status === 0;\n}\n\nexport function isWorktreeDirty(worktreePath: string): boolean {\n  const result = spawnSync('git', ['status', '--porcelain'], {\n    cwd: worktreePath,\n    encoding: 'utf-8',\n      windowsHide: true,\n    });\n  if (result.status !== 0) {\n    const stderr = (result.stderr || '').trim();\n    throw new Error(stderr || `worktree_status_failed:${worktreePath}`);\n  }\n  return (result.stdout || '').trim() !== '';\n}\n\nexport function readWorkspaceStatusLines(cwd: string): string[] {\n  const result = spawnSync('git', ['status', '--porcelain', '--untracked-files=all'], {\n    cwd,\n    encoding: 'utf-8',\n      windowsHide: true,\n    });\n  if (result.status !== 0) {\n    const stderr = (result.stderr || '').trim();\n    throw new Error(stderr || `workspace_status_failed:${cwd}`);\n  }\n  return (result.stdout || '')\n    .split(/\\r?\\n/)\n    .map((line) => line.trimEnd())\n    .filter(Boolean);","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/Yeachan-Heo/oh-my-codex/blob/3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2/src/team/worktree.ts#L113-L149","documentation":"Thrown when `git status --porcelain` inside an existing worktree exits non-zero (and stderr is empty), meaning the library could not determine whether the worktree has uncommitted changes. isWorktreeDirty is used before reusing an existing worktree; if status can't run, reuse is unsafe so it throws.","triggerScenarios":"ensureWorktree finds an existing worktree at the planned path and calls isWorktreeDirty, but `git status` fails: worktree directory deleted out from under git, corrupt index (.git file pointing to a missing gitdir), git missing from PATH, or permission issues.","commonSituations":"A previously created worktree was `rm -rf`'d manually without `git worktree prune`, leaving stale metadata; concurrent processes pruned the worktree; broken `.git` file in the worktree after moving the repo; git not on PATH in GUI/CI environments.","solutions":["Run `git worktree prune` from the repo root to clear stale worktree metadata, then retry","If the worktree directory is corrupted, remove it (`git worktree remove --force <path>` or delete the dir) and let the library recreate it","Verify the worktree's `.git` file points to an existing gitdir; re-create the worktree if not","Confirm git is installed and accessible from the process environment"],"exampleFix":"# before: stale/corrupt worktree causes worktree_status_failed\n# after: prune and recreate\ngit worktree prune\ngit worktree remove --force .omx/worktrees/<name> || true\n# then re-run the team command","handlingStrategy":"try-catch","validationCode":"import { existsSync, readFileSync } from 'node:fs';\nimport { join } from 'node:path';\n\nfunction worktreeLooksHealthy(p: string): boolean {\n  if (!existsSync(p)) return false;\n  const dot = join(p, '.git');\n  if (!existsSync(dot)) return false;\n  if (!dot.endsWith('.git')) return true; // real .git dir\n  const gitdir = readFileSync(dot, 'utf-8').match(/gitdir: (.+)/)?.[1];\n  return !!gitdir && existsSync(gitdir);\n}","typeGuard":null,"tryCatchPattern":"try { ensureWorktree(plan, {}); } catch (e) { if (String(e?.message).startsWith('worktree_status_failed:')) { spawnSync('git', ['worktree','prune'], { cwd: plan.repoRoot }); /* optionally remove path and retry once */ } else throw e; }","preventionTips":["Never rm -rf worktree dirs manually; use `git worktree remove` / `git worktree prune`","Health-check the worktree's .git file before reuse","Run `git worktree prune` at the start of team runs"],"tags":["git","worktree","git-status","corruption"],"backgroundTag":"git-worktree-prune-stale","analyzedSha":"3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2","analyzedAt":"2026-08-27T22:18:39.783Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}