{"record":{"id":"c2c8e3835c9d87c2","repo":"facebook/docusaurus","slug":"failed-to-retrieve-git-history-for-file-becau","errorCode":null,"errorMessage":"Failed to retrieve git history for \"${file}\" because git is not installed.","messagePattern":"Failed to retrieve git history for \"(.+?)\" because git is not installed\\.","errorType":"exception","errorClass":"GitNotFoundError","httpStatus":null,"severity":"error","filePath":"packages/docusaurus-utils/src/vcs/gitUtils.ts","lineNumber":131,"sourceCode":"  author: string;\n}>;\n\nexport async function getFileCommitDate(\n  file: string,\n  {\n    age = 'oldest',\n    includeAuthor = false,\n  }: {\n    age?: 'oldest' | 'newest';\n    includeAuthor?: boolean;\n  },\n): Promise<{\n  date: Date;\n  timestamp: number;\n  author?: string;\n}> {\n  if (!hasGit()) {\n    throw new GitNotFoundError(\n      `Failed to retrieve git history for \"${file}\" because git is not installed.`,\n    );\n  }\n\n  if (!(await fs.pathExists(file))) {\n    throw new Error(\n      `Failed to retrieve git history for \"${file}\" because the file does not exist.`,\n    );\n  }\n\n  // We add a \"RESULT:\" prefix to make parsing easier\n  // See why: https://github.com/facebook/docusaurus/pull/10022\n  const resultFormat = includeAuthor ? 'RESULT:%ct,%an' : 'RESULT:%ct';\n\n  const result = (await GitCommandQueue.add(() => {\n    return execa(\n      'git',\n      [","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/facebook/docusaurus/blob/3f483e80e326cc646b54b83d564b3f0c4881b9a6/packages/docusaurus-utils/src/vcs/gitUtils.ts#L113-L149","documentation":"Thrown as a GitNotFoundError by getFileCommitDate() when hasGit() returns false — i.e. running `git --version` did not exit 0 (git binary missing from PATH). getFileCommitDate is the engine behind showLastUpdateTime / showLastUpdateAuthor / enableUpdateTimepot features, all of which require git. The custom error class lets upstream code (getGitCommitInfo) detect this specific case and emit a single warning instead of crashing.","triggerScenarios":"Building Docusaurus with showLastUpdateTime: true (or similar) in an environment without git installed: a fresh CI image, a minimal Docker container, a sandboxed server. hasGit() is memoized so once it returns false every subsequent call short-circuits to this throw.","commonSituations":"Alpine-based Docker images that do not include git by default. CI containers where git is installed in a later stage but the build runs in an earlier stage. Local machines where git is not on PATH. Detached environments (some serverless build runners) that omit git intentionally.","solutions":["Install git in the build environment (e.g. apt-get install git, apk add git, dnf install git) and confirm `git --version` succeeds.","If git is not needed, disable the features that trigger it: set showLastUpdateTime, showLastUpdateAuthor, and enableUpdateTimepot to false in plugin options.","Ensure the build container's PATH includes the directory containing the git binary.","Re-run the build; hasGit is memoized per-process so a fresh process is required after installing git."],"exampleFix":"# before — Dockerfile omits git\nFROM node:20-alpine\nRUN pnpm build\n\n# after\nFROM node:20-alpine\nRUN apk add --no-cache git\nRUN pnpm build","handlingStrategy":"fallback","validationCode":"import { execaSync } from 'execa';\n\nfunction isGitAvailable(): boolean {\n  try { return execaSync('git', ['--version']).exitCode === 0; }\n  catch { return false; }\n}\n\nif (!isGitAvailable() && siteConfig.showLastUpdateTime) {\n  console.warn('Git not found; disabling showLastUpdateTime for this build.');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await getFileCommitDate(file, { age: 'newest' });\n} catch (err) {\n  if (err instanceof GitNotFoundError) {\n    // git missing: warn once and disable time-related features for the build\n  }\n  throw err;\n}","preventionTips":["Install git in every environment that runs the build (add it to Dockerfiles, CI images).","If a build environment legitimately lacks git, disable showLastUpdateTime / showLastUpdateAuthor / enableUpdateTimepot.","In custom Dockerfiles, prefer images that ship git or add it explicitly (apk add git, apt-get install git)."],"tags":["git","environment","dependency","docker","ci"],"backgroundTag":null,"analyzedSha":"3f483e80e326cc646b54b83d564b3f0c4881b9a6","analyzedAt":"2026-08-12T13:25:04.382Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}