{"record":{"id":"f9462a2c42f91713","repo":"thedotmack/claude-mem","slug":"git-operation-failed-git-c-cwd-args-join","errorCode":null,"errorMessage":"Git operation failed: git -C ${cwd} ${args.join(' ')}","messagePattern":"Git operation failed: git -C (.+?) (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/services/infrastructure/WorktreeAdoption.ts","lineNumber":65,"sourceCode":"    this.name = 'DryRunRollback';\n  }\n}\n\nfunction gitCapture(cwd: string, args: string[]): string | null {\n  const startTime = Date.now();\n  const r = spawnSync('git', ['-C', cwd, ...args], {\n    encoding: 'utf8',\n    timeout: GIT_TIMEOUT_MS,\n    windowsHide: true\n  });\n  const duration = Date.now() - startTime;\n  \n  if (duration > 1000) {\n    logger.debug('GIT', `Slow git operation: git -C ${cwd} ${args.join(' ')} took ${duration}ms`);\n  }\n\n  if (r.error) {\n    logger.warn('GIT', `Git operation failed: git -C ${cwd} ${args.join(' ')}`, {\n      error: r.error.message,\n      timedOut: r.error.name === 'ETIMEDOUT' || (r.status === null && r.signal === 'SIGTERM')\n    });\n    return null;\n  }\n\n  if (r.status !== 0) {\n    logger.debug('GIT', `Git returned non-zero exit code ${r.status}: git -C ${cwd} ${args.join(' ')}`, {\n      stderr: r.stderr?.toString().trim()\n    });\n    return null;\n  }\n  return (r.stdout ?? '').trim();\n}\n\nfunction resolveMainRepoPath(cwd: string): string | null {\n  const commonDir = gitCapture(cwd, [\n    'rev-parse',","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/e2d1df569a8f04075d40e92461128ece7cf04c82/src/services/infrastructure/WorktreeAdoption.ts#L47-L83","documentation":"WorktreeAdoption shells out to git via spawnSync with a timeout and logs slow operations over 1s. This warning fires when r.error is set — git could not be spawned at all (ENOENT: git not installed or not on PATH) or the command exceeded GIT_TIMEOUT_MS and was killed (ETIMEDOUT/SIGTERM). The helper returns null and git-dependent adoption is skipped; ordinary non-zero git exits are logged separately at debug level.","triggerScenarios":"spawnSync('git', ...) errors: 'git' absent from the PATH of the claude-mem process (ENOENT), the command exceeding GIT_TIMEOUT_MS on a huge or hung repo (ETIMEDOUT, SIGTERM), or an invalid cwd making the spawn fail.","commonSituations":"git not on PATH for GUI-launched or service contexts where PATH differs from the shell; CI containers without git; network filesystems making git status hang; a credential helper prompting indefinitely on a private remote.","solutions":["Confirm `git --version` works in the environment claude-mem runs in — services and GUI apps inherit a different PATH than your shell.","If the log's timedOut flag is true, identify the slow operation (large repo, hung remote, locked index) and fix or prune it.","Install git or add its directory to PATH, then restart the worker.","For hanging credential prompts, configure a non-interactive credential helper (cache or store)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// prove git is invokable from this process before adoption runs\nimport { spawnSync } from 'node:child_process';\n\nconst probe = spawnSync('git', ['--version'], { encoding: 'utf8' });\nif (probe.error || probe.status !== 0) {\n  throw new Error('git not available on PATH of this process');\n}","typeGuard":null,"tryCatchPattern":"const r = spawnSync('git', args, { timeout: GIT_TIMEOUT_MS });\nif (r.error || r.status !== 0) {\n  // null result means 'skip git-dependent work', not a crash\n  skipAdoptionFor(cwd);\n}","preventionTips":["For GUI/service contexts, set PATH system-wide, not only in the shell profile.","Keep repos off network mounts that make git hang, or raise GIT_TIMEOUT_MS.","Use non-interactive git credential helpers so private remotes never block."],"tags":["git","spawn","timeout","path"],"backgroundTag":"git-command-failed","analyzedSha":"e2d1df569a8f04075d40e92461128ece7cf04c82","analyzedAt":"2026-08-20T23:58:13.836Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}