fix(git): report missing cwd distinctly from missing git binary

A deleted/nonexistent cwd also makes Bun.spawn throw ENOENT; only claim
'git is not installed.' when the working directory actually exists, else
name the missing directory. Addresses the Codex P2 review on #6237.
This commit is contained in:
can1357
2026-07-22 20:42:10 +02:00
parent a4bd7a4df3
commit a07d72f638
2 changed files with 17 additions and 1 deletions
@@ -33,6 +33,15 @@ describe("git helpers with git binary absent (#6169)", () => {
await expect(git.diff.has("/")).rejects.toThrow("git is not installed.");
});
it("does not blame the git binary when the cwd is what is missing", async () => {
vi.spyOn(Bun, "spawn").mockImplementation(throwSpawnEnoent);
// A deleted cwd also makes spawn throw ENOENT; the error must name the
// directory, not falsely claim git is uninstalled.
await expect(git.diff.has("/nonexistent-omp-eval-dir")).rejects.toThrow(
"working directory does not exist: /nonexistent-omp-eval-dir",
);
});
it("repo.root degrades to null instead of throwing ENOENT", async () => {
vi.spyOn(Bun, "spawn").mockImplementation(throwSpawnEnoent);
expect(await git.repo.root("/")).toBeNull();