{"record":{"id":"6730f9c55a748c52","repo":"facebook/docusaurus","slug":"couldn-t-find-the-git-repository-root-directory-fa","errorCode":null,"errorMessage":"Couldn't find the git repository root directory\nFailure while running ${logger.code('git rev-parse --show-toplevel')} from cwd=${logger.path(cwd)}\nThe command executed throws an error: ${error.message}","messagePattern":"Couldn't find the git repository root directory\nFailure while running (.+?) from cwd=(.+?)\nThe command executed throws an error: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/docusaurus-utils/src/vcs/gitUtils.ts","lineNumber":290,"sourceCode":"      `Couldn't check if this directory is within a Git worktree: ${cwd}`,\n      {cause: error},\n    );\n  }\n}\n\nexport async function getGitRepoRoot(cwd: string): Promise<string> {\n  const createErrorMessageBase = () => {\n    return `Couldn't find the git repository root directory\nFailure while running ${logger.code(\n      'git rev-parse --show-toplevel',\n    )} from cwd=${logger.path(cwd)}`;\n  };\n\n  const result = await execa('git', ['rev-parse', '--show-toplevel'], {\n    cwd,\n  }).catch((error) => {\n    // We enter this rejection when cwd is not a dir for example\n    throw new Error(\n      `${createErrorMessageBase()}\nThe command executed throws an error: ${error.message}`,\n      {cause: error},\n    );\n  });\n\n  if (result.exitCode !== 0) {\n    throw new Error(\n      `${createErrorMessageBase()}\nThe command returned exit code ${logger.code(result.exitCode)}: ${logger.subdue(\n        result.stderr,\n      )}`,\n    );\n  }\n\n  return fs.realpath.native(result.stdout.trim());\n}\n","sourceCodeStart":272,"sourceCodeEnd":308,"githubUrl":"https://github.com/facebook/docusaurus/blob/3f483e80e326cc646b54b83d564b3f0c4881b9a6/packages/docusaurus-utils/src/vcs/gitUtils.ts#L272-L308","documentation":"Thrown by getGitRepoRoot when `git rev-parse --show-toplevel` cannot even be spawned or rejects before producing a result (e.g. the cwd does not exist, is not a directory, git is missing, or the OS refuses to spawn the process). This is the rejection path of the execa promise; the exitCode path is a separate error. The original failure is attached via {cause: error}.","triggerScenarios":"Calling getGitRepoRoot(cwd) (directly or transitively via getGitAllRepoRoots / VCS eager init) with a cwd that is not a valid existing directory, when git is not installed, or when spawn hits EACCES/ENOENT.","commonSituations":"Running a build/serve from a directory deleted mid-build, passing a relative or symlink-broken siteDir, running in a CI image without git installed, or invoking Docusaurus inside a container whose cwd was unmounted.","solutions":["Verify the cwd passed to Docusaurus exists and is a directory: `node -e \"require('fs').realpathSync(process.cwd())\"`.","Ensure git is on PATH: `git --version` should succeed in the same shell.","If siteDir is custom, point it at a real checkout rather than a parent or temp path.","Run from the repository root where `.git` lives."],"exampleFix":"// before\nconst root = await getGitRepoRoot(maybeDeletedDir);\n// after\nimport fs from 'fs';\nif (!fs.existsSync(maybeDeletedDir) || !fs.statSync(maybeDeletedDir).isDirectory()) {\n  throw new Error(`cwd is not a directory: ${maybeDeletedDir}`);\n}\nconst root = await getGitRepoRoot(maybeDeletedDir);","handlingStrategy":"validation","validationCode":"import fs from 'fs';\nfunction assertValidCwd(cwd: string) {\n  const real = fs.realpathSync(cwd); // throws ENOENT if missing\n  if (!fs.statSync(real).isDirectory()) throw new Error(`not a directory: ${cwd}`);\n}\n// run before getGitRepoRoot(cwd)","typeGuard":null,"tryCatchPattern":"try {\n  const root = await getGitRepoRoot(cwd);\n} catch (e) {\n  if (/rev-parse --show-toplevel/.test(String(e))) handleInvalidCwdOrMissingGit(e);\n  else throw e;\n}","preventionTips":["Always realpath the cwd before passing it to VCS utilities.","Pin git presence in CI with a `git --version` preflight step.","Avoid launching Docusaurus from ephemeral or temp directories."],"tags":["git","vcs","filesystem","spawn"],"backgroundTag":null,"analyzedSha":"3f483e80e326cc646b54b83d564b3f0c4881b9a6","analyzedAt":"2026-08-12T13:25:04.382Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}