Files
orca/src/main/git/git-availability.ts
T
Jinjing 775a932651 fix(git): distinguish binary absence from missing cwd on spawn ENOENT (#20798)
* fix(repos): preserve unknown Git availability

* fix(git): distinguish binary absence from missing cwd on spawn ENOENT

Node reports ENOENT for both a missing git binary and a missing working directory
during spawn. The fix checks specifically for spawn syscall, then verifies the cwd
exists to disambiguate. This prevents reporting "no Git" when the error is actually
a missing working directory. Centralizes probe logic in a reusable function; other
failures cause rejection so callers preserve the unknown status instead of collapsing
to false.
2026-09-15 00:22:15 -07:00

32 lines
846 B
TypeScript

import { access } from 'node:fs/promises'
import { isMissingCommandBinaryError } from './exec-error'
type GitVersionExec = (
args: string[],
options: { cwd: string; timeout: number }
) => Promise<unknown>
/**
* Resolves `false` only when the spawn proved Git absent; every other failure rejects so callers
* keep an unknown answer instead of reporting a host with no Git.
*/
export async function probeGitAvailability(
exec: GitVersionExec,
options: { cwd: string; timeout: number }
): Promise<boolean> {
try {
await exec(['--version'], options)
return true
} catch (err) {
if (isMissingCommandBinaryError(err)) {
try {
await access(options.cwd)
return false
} catch {
// Node reports the same spawn ENOENT for a missing binary and a missing cwd.
}
}
throw err
}
}