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 — with an optional `GIT` e
()
| 432 | /// front — with an optional `GIT` env override — removes the per-spawn PATH |
| 433 | /// walk and makes the lookup deterministic. |
| 434 | pub fn git_program() -> std::ffi::OsString { |
| 435 | use std::sync::OnceLock; |
| 436 | static GIT: OnceLock<std::ffi::OsString> = OnceLock::new(); |
| 437 | GIT.get_or_init(|| { |
| 438 | if let Some(explicit) = std::env::var_os("GIT") { |
| 439 | return explicit; |
| 440 | } |
| 441 | let exe_name = if cfg!(windows) { "git.exe" } else { "git" }; |
| 442 | if let Some(paths) = std::env::var_os("PATH") { |
| 443 | for dir in std::env::split_paths(&paths) { |
| 444 | let candidate = dir.join(exe_name); |
| 445 | if candidate.is_file() { |
| 446 | return candidate.into_os_string(); |
| 447 | } |
| 448 | } |
| 449 | } |
| 450 | std::ffi::OsString::from("git") |
| 451 | }) |
| 452 | .clone() |
| 453 | } |
| 454 | |
| 455 | #[cfg(unix)] |
| 456 | pub fn daemon_socket_path(home: &Path) -> PathBuf { |