{"record":{"id":"0b6539a97e39783c","repo":"vitest-dev/vitest","slug":"vitest-git-not-found","errorCode":"VITEST_GIT_NOT_FOUND","errorMessage":"Could not find Git root. Have you initialized git with `git init`?","messagePattern":"Could not find Git root\\. Have you initialized git with `git init`\\?","errorType":"exception","errorClass":"GitNotFoundError","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/node/vcs/git.ts","lineNumber":31,"sourceCode":"    try {\n      result = await x('git', args, { nodeOptions: { cwd: this.root } })\n    }\n    catch (e: any) {\n      e.message = e.stderr\n\n      throw e\n    }\n\n    return result.stdout\n      .split('\\n')\n      .filter(s => s !== '')\n      .map(changedPath => resolve(this.root, changedPath))\n  }\n\n  async findChangedFiles(options: VCSProviderOptions): Promise<string[]> {\n    const root = this.root || await this.getRoot(options.root)\n    if (!root) {\n      throw new GitNotFoundError()\n    }\n\n    this.root = root\n\n    const changedSince = options.changedSince\n    if (typeof changedSince === 'string') {\n      const [committed, staged, unstaged] = await Promise.all([\n        this.getFilesSince(changedSince),\n        this.getStagedFiles(),\n        this.getUnstagedFiles(),\n      ])\n      return [...committed, ...staged, ...unstaged]\n    }\n    const [staged, unstaged] = await Promise.all([\n      this.getStagedFiles(),\n      this.getUnstagedFiles(),\n    ])\n    return [...staged, ...unstaged]","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/vitest/src/node/vcs/git.ts#L13-L49","documentation":"`--changed`/`--changedSince` rely on git to diff changed files. `GitVCSProvider.getRoot` runs `git rev-parse --show-cdup`; if that fails (not a git repository, or `git` not installed/on PATH) it returns null, and `findChangedFiles` then throws `GitNotFoundError` (`VITEST_GIT_NOT_FOUND`).","triggerScenarios":"Invoking `vitest --changed` (or `--changedSince <ref>`, or the `changed`/`changedSince` config option) in a directory where `git rev-parse --show-cdup` fails — no `.git`, or `git` binary missing.","commonSituations":"Fresh/uninitialized project; CI checkout that strips `.git`; minimal container without git installed; running inside a sandbox that hides git.","solutions":["Initialize the repository with `git init` and make at least one commit.","Ensure the `git` binary is installed and on `PATH` (`git --version` should succeed in the same environment).","Drop `--changed`/`--changedSince` (and the `changed` config) if the project intentionally doesn't use git."],"exampleFix":"# before\nvitest --changed   # VITEST_GIT_NOT_FOUND\n\n# after\ngit init && git add -A && git commit -m 'init'\nvitest --changed","handlingStrategy":"try-catch","validationCode":"import { x } from 'tinyexec'\nasync function isGitRepo(cwd: string): Promise<boolean> {\n  try {\n    await x('git', ['rev-parse', '--show-cdup'], { nodeOptions: { cwd } })\n    return true\n  } catch {\n    return false\n  }\n}\n// before calling vitest with --changed:\nif (options.changed && !(await isGitRepo(process.cwd()))) {\n  throw new Error('--changed requires a git repository. Run `git init` or drop the flag.')\n}","typeGuard":null,"tryCatchPattern":"import { GitNotFoundError } from 'vitest/node'\ntry {\n  await startVitest('test', [], { changed: 'HEAD~1' }, {})\n} catch (e) {\n  if (e instanceof GitNotFoundError) {\n    // not a git repo: fall back to running the full suite\n    return startVitest('test', [], {}, {})\n  }\n  throw e\n}","preventionTips":["Ensure `git` is installed and on PATH in every environment that uses `--changed`.","Confirm a `.git` directory is present in CI checkouts (don't shallow-strip it).","Gate `--changed`/`--changedSince` on git availability in your test runner script."],"tags":["git","vcs","cli"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}