MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / git_program

Function git_program

src/mcp/hook_events.rs:353–373  ·  view source on GitHub ↗

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,

()

Source from the content-addressed store, hash-verified

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

Callers 3

run_gitFunction · 0.70
git_changed_pathsFunction · 0.50
gitFunction · 0.50

Calls

no outgoing calls

Tested by 1

gitFunction · 0.40