{"record":{"id":"f9a2a21b0a9bf321","repo":"Yeachan-Heo/oh-my-codex","slug":"stderr-git-args-join-failed","errorCode":null,"errorMessage":"stderr || `git ${args.join(' ')} failed`","messagePattern":"stderr \\|\\| `git (.+?) failed`","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/autoresearch/runtime.ts","lineNumber":175,"sourceCode":"  return trimmed.length <= max ? trimmed : `${trimmed.slice(0, max)}\\n...`;\n}\n\nfunction readGit(repoPath: string, args: string[]): string {\n  try {\n    return execFileSync('git', args, {\n      cwd: repoPath,\n      encoding: 'utf-8',\n      stdio: ['ignore', 'pipe', 'pipe'],\n      windowsHide: true,\n    }).trim();\n  } catch (error) {\n    const err = error as NodeJS.ErrnoException & { stderr?: string | Buffer };\n    const stderr = typeof err.stderr === 'string'\n      ? err.stderr.trim()\n      : err.stderr instanceof Buffer\n        ? err.stderr.toString('utf-8').trim()\n        : '';\n    throw new Error(stderr || `git ${args.join(' ')} failed`);\n  }\n}\n\nfunction tryResolveGitCommit(worktreePath: string, ref: string): string | null {\n  const result = spawnSync('git', ['rev-parse', '--verify', `${ref}^{commit}`], {\n    cwd: worktreePath,\n    encoding: 'utf-8',\n  });\n  if (result.status !== 0) return null;\n  const resolved = (result.stdout || '').trim();\n  return resolved || null;\n}\n\nasync function writeGitInfoExclude(worktreePath: string, pattern: string): Promise<void> {\n  const excludePath = readGit(worktreePath, ['rev-parse', '--git-path', 'info/exclude']);\n  const existing = existsSync(excludePath)\n    ? await readFile(excludePath, 'utf-8')\n    : '';","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/Yeachan-Heo/oh-my-codex/blob/3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2/src/autoresearch/runtime.ts#L157-L193","documentation":"readGit wraps git subprocess execution and rethrows with the git command's trimmed stderr (or a generic 'git <args> failed' message when stderr is empty). It surfaces any failure of an async git invocation, such as rev-parse, branch lookups, or path exclusions.","triggerScenarios":"Any async git invocation failing: missing ref/commit (rev-parse on an unknown SHA), detached/missing branch, not inside a git repository, git not on PATH for the async execution environment, or permission problems on the repo.","commonSituations":"Running autoresearch in a directory that is not a git worktree, referencing a commit that was garbage-collected, shallow clones missing expected history, or CI environments where git auth/config blocks the command.","solutions":["Run the printed git command manually in the same cwd to see the real failure","Verify the working directory is a valid git repository and the ref/commit exists (git rev-parse <ref>)","Check git is installed and on PATH in the execution environment (CI containers, nix shells)","For auth failures in CI, configure credentials or run with a token that can read the repo"],"exampleFix":"// before\nconst head = await readGit(repoRoot, ['rev-parse', 'HEAD']); // throws 'unknown revision...'\n// after\n// ensure repo has at least one commit\nawait run('git', ['commit', '--allow-empty', '-m', 'init'], { cwd: repoRoot });\nconst head = await readGit(repoRoot, ['rev-parse', 'HEAD']);","handlingStrategy":"try-catch","validationCode":"import { spawnSync } from 'node:child_process';\nfunction gitAvailable(cwd: string): boolean {\n  return spawnSync('git', ['rev-parse', '--is-inside-work-tree'], { cwd }).status === 0;\n}","typeGuard":null,"tryCatchPattern":"try { const sha = await readGit(cwd, ['rev-parse', 'HEAD']); }\ncatch (e) { if (e instanceof Error && /git .* failed|fatal:/.test(e.message)) { /* surface git stderr, validate repo state */ } throw e; }","preventionTips":["Verify the directory is a git repository before invoking autoresearch runtime APIs","Pre-check refs with git rev-parse --verify before passing them to readGit-based helpers","Ensure git is on PATH in CI/containers"],"tags":["git","subprocess","environment","repository"],"backgroundTag":"git-command-failed","analyzedSha":"3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2","analyzedAt":"2026-08-27T22:18:39.783Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}