Resolves the `git` executable to an absolute path exactly once per process. Under heavy parallel test load (nextest spawns one process per test, each spawning several `git` subprocesses), a bare `Command::new("git")` PATH lookup can transiently fail the spawn with `ENOENT` ("No such file or directory") even though git is installed. Resolving to an absolute path up front, plus a `GIT` env override,
()
| 351 | /// Resolving to an absolute path up front, plus a `GIT` env override, |
| 352 | /// removes the per-spawn PATH walk and makes the lookup deterministic. |
| 353 | fn git_program() -> std::ffi::OsString { |
| 354 | use std::sync::OnceLock; |
| 355 | static GIT: OnceLock<std::ffi::OsString> = OnceLock::new(); |
| 356 | GIT.get_or_init(|| { |
| 357 | if let Some(explicit) = std::env::var_os("GIT") { |
| 358 | return explicit; |
| 359 | } |
| 360 | let exe_name = if cfg!(windows) { "git.exe" } else { "git" }; |
| 361 | if let Some(paths) = std::env::var_os("PATH") { |
| 362 | for dir in std::env::split_paths(&paths) { |
| 363 | let candidate = dir.join(exe_name); |
| 364 | if candidate.is_file() { |
| 365 | return candidate.into_os_string(); |
| 366 | } |
| 367 | } |
| 368 | } |
| 369 | // Fall back to a bare name and let the OS resolve it. |
| 370 | std::ffi::OsString::from("git") |
| 371 | }) |
| 372 | .clone() |
| 373 | } |
| 374 | |
| 375 | fn run_git(cwd: &Path, args: &[&str]) { |
| 376 | // A cwd that does not yet exist makes the spawn itself fail with |
no outgoing calls