{"record":{"id":"c1438f2de9a42893","repo":"yamadashy/repomix","slug":"failed-to-get-git-diffs-error-message","errorCode":null,"errorMessage":"Failed to get git diffs: ${error.message}","messagePattern":"Failed to get git diffs: (.+?)","errorType":"exception","errorClass":"RepomixError","httpStatus":null,"severity":"error","filePath":"src/core/git/gitDiffHandle.ts","lineNumber":88,"sourceCode":"  let gitDiffResult: GitDiffResult | undefined;\n\n  if (config.output.git?.includeDiffs) {\n    try {\n      // Use the first directory as the git repository root\n      // Usually this would be the root of the project\n      const gitRoot = rootDirs[0] || config.cwd;\n      const [workTreeDiffContent, stagedDiffContent] = await Promise.all([\n        deps.getWorkTreeDiff(gitRoot),\n        deps.getStagedDiff(gitRoot),\n      ]);\n\n      gitDiffResult = {\n        workTreeDiffContent,\n        stagedDiffContent,\n      };\n    } catch (error) {\n      if (error instanceof Error) {\n        throw new RepomixError(`Failed to get git diffs: ${error.message}`);\n      }\n    }\n  }\n\n  return gitDiffResult;\n};\n","sourceCodeStart":70,"sourceCodeEnd":95,"githubUrl":"https://github.com/yamadashy/repomix/blob/f465ad909315a22120636baf03fa5e28701a50cb/src/core/git/gitDiffHandle.ts#L70-L95","documentation":"getGitDiffs runs `git diff` commands for the work tree and the staged area, then wraps any underlying failure (non-zero exit, git missing, not a repo) into a single RepomixError with this message. The original git error text is appended so the concrete cause (e.g. 'not a git repository', 'fatal: bad object') is visible in the message.","triggerScenarios":"Calling getGitDiffs (or the --include-diffs code path) when the target directory is not a git repository, git is not installed or not on PATH, or the git diff subprocess exits non-zero for any reason.","commonSituations":"Running repomix on a plain directory that was downloaded as a zip (no .git); a stripped-down Docker/CI image without git; corrupted index or lock file making `git diff` fail.","solutions":["Run repomix inside a git repository (or `git init` / `git clone` the project) — `git diff` requires a repo.","Install git and confirm `git --version` works in the same shell/environment.","Read the appended cause in the message and fix that underlying git error (e.g. remove stale .git/index.lock, repair the repo)."],"exampleFix":"// before (plain zip download)\nnpx repomix --include-diffs ./project-zip\n// after\nnpm install -g repomix\ncd project-zip && git init && git add -A && git commit -m init\nnpx repomix --include-diffs","handlingStrategy":"try-catch","validationCode":"import { execFileSync } from 'node:child_process';\nconst isGitRepo = (dir: string) => {\n  try { execFileSync('git', ['-C', dir, 'rev-parse', '--is-inside-work-tree'], { stdio: 'ignore' }); return true; }\n  catch { return false; }\n};\nif (!isGitRepo(targetDir)) throw new Error('Target is not a git repository; diffs unavailable.');","typeGuard":"const isRepomixDiffError = (e: unknown): e is RepomixError & { message: string } =>\n  e instanceof RepomixError && e.message.startsWith('Failed to get git diffs:');","tryCatchPattern":"try {\n  const diffs = await getGitDiffs(...);\n} catch (error) {\n  if (error instanceof RepomixError && error.message.startsWith('Failed to get git diffs:')) {\n    console.warn('Git diffs skipped:', error.message);\n  } else throw error;\n}","preventionTips":["Ensure git is installed and on PATH in every environment (CI images, Docker) where diffs are requested.","Only enable diff options when operating on a real git working tree.","Pin a recent git version; very old gits lack flags the tool may rely on."],"tags":["git","subprocess","diff"],"backgroundTag":"git-command-failed","analyzedSha":"f465ad909315a22120636baf03fa5e28701a50cb","analyzedAt":"2026-08-29T01:27:42.024Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}