{"record":{"id":"e2e9fb65aeb78a9f","repo":"facebook/docusaurus","slug":"failed-to-retrieve-the-git-history-for-file-fil","errorCode":null,"errorMessage":"Failed to retrieve the git history for file \"${file}\" with exit code ${result.exitCode}: ${result.stderr}","messagePattern":"Failed to retrieve the git history for file \"(.+?)\" with exit code (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/docusaurus-utils/src/vcs/gitUtils.ts","lineNumber":168,"sourceCode":"        // Do not include GPG signature in the log output\n        // See https://github.com/facebook/docusaurus/pull/10022\n        '-c',\n        'log.showSignature=false',\n        'log',\n        `--format=${resultFormat}`,\n        '--max-count=1',\n        ...(age === 'oldest' ? ['--follow', '--diff-filter=A'] : []),\n        '--',\n        path.basename(file),\n      ],\n      {\n        cwd: path.dirname(file),\n      },\n    );\n  }))!;\n\n  if (result.exitCode !== 0) {\n    throw new Error(\n      `Failed to retrieve the git history for file \"${file}\" with exit code ${result.exitCode}: ${result.stderr}`,\n    );\n  }\n\n  // We only parse the output line starting with our \"RESULT:\" prefix\n  // See why https://github.com/facebook/docusaurus/pull/10022\n  const regex = includeAuthor\n    ? /(?:^|\\n)RESULT:(?<timestamp>\\d+),(?<author>.+)(?:$|\\n)/\n    : /(?:^|\\n)RESULT:(?<timestamp>\\d+)(?:$|\\n)/;\n\n  const output = result.stdout.trim();\n\n  if (!output) {\n    throw new FileNotTrackedError(\n      `Failed to retrieve the git history for file \"${file}\" because the file is not tracked by git.`,\n    );\n  }\n","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/facebook/docusaurus/blob/3f483e80e326cc646b54b83d564b3f0c4881b9a6/packages/docusaurus-utils/src/vcs/gitUtils.ts#L150-L186","documentation":"Thrown by getFileCommitDate() after git log exits with a non-zero code. The error includes the exit code and the contents of stderr captured by execa, which usually reveals why git refused. This is a generic 'git itself failed' branch distinct from 'file not tracked' (empty output) and 'unexpected output' (regex miss).","triggerScenarios":"Running git log inside getFileCommitDate where the repository state causes git to fail: a corrupted .git directory, an interrupted rebase leaving the index locked, an unreadable git object, or a permission error reading the repo. Less commonly, an execa-level issue (signal kill, max buffer) surfaces as a non-zero exit.","commonSituations":"A shallow clone with broken history references. A repo mid-rebase or mid-merge with a locked index. Disk/permission errors on .git internals. A CI environment with a corrupted checkout cache. Concurrent git processes racing on the same repo (mitigated by GitCommandQueue but not eliminated).","solutions":["Read the stderr echoed in the error message — it is git's own explanation of the failure.","If the index is locked ('.git/index.lock' exists), remove the stale lock file or abort the in-progress rebase/merge.","For corrupted history, re-clone the repository or run `git fsck --full` to diagnose and repair.","If running in CI, clear the cached checkout workspace so a fresh clone is performed."],"exampleFix":"# before — stale index.lock from an interrupted rebase\n# error: Another git process seems to be running in this repository\n\n# after\nrm -f .git/index.lock\ngit rebase --abort  # if a rebase is in progress\n# then re-run the build","handlingStrategy":"try-catch","validationCode":"import fs from 'fs-extra';\n\nasync function repoLooksHealthy(repoDir: string): Promise<boolean> {\n  return fs.pathExists(path.join(repoDir, '.git'))\n    && !await fs.pathExists(path.join(repoDir, '.git', 'index.lock'));\n}\n\nif (!(await repoLooksHealthy(repoDir))) {\n  throw new Error('Repository looks unhealthy (missing .git or stale index.lock).');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await getFileCommitDate(file, { age: 'newest' });\n} catch (err) {\n  if (err instanceof Error && err.message.includes('with exit code')) {\n    // err message carries git's stderr; repair the repo or clear CI cache\n  }\n  throw err;\n}","preventionTips":["Keep the repository healthy: abort in-progress rebases/merges and remove stale .git/index.lock files.","In CI, use a fresh checkout rather than a cached workspace when git failures appear.","Run `git fsck --full` periodically on long-lived working copies."],"tags":["git","exit-code","repository","ci"],"backgroundTag":null,"analyzedSha":"3f483e80e326cc646b54b83d564b3f0c4881b9a6","analyzedAt":"2026-08-12T13:25:04.382Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}