//! Where `git` is on a Mac — THE ONE DECLARATION, for every crate that asks.//!//! ## Why it is here and not beside either caller//!//! Three places need the same four absolute paths and they cannot share a//! function://!//! * **`CottonHost`** (`HelperPaths.gitCandidates`) resolves it at launch and//! exports [`PROGRAM_ENV`] BEFORE `cotton_open`, so there is no core to ask//! yet. Its list is Swift and must be a literal twin.//! * **`cotton-client`** (`git::discover`) answers the Serving page and picks//! the `git` a credential is written with.//! * **`cotton-server`** (`repos::git`) needs the same answer for a bare//! `cotton-server` on a Linux box and for its own suite.//!//! There were THREE Rust copies of the list, and only one pair was guarded//! (`scripts/__tests__/swift-mac.test.ts`, Swift ⇄ `cotton-server`);//! `cotton-client`'s could drift in silence. Both crates already depend on//! this one, so the list lives here and both `pub use` it — the shape that//! cannot rot. Swift stays a literal twin, held against THIS file by that same//! guard.//!//! ## Why a ladder and not `which`//!//! Measured on macOS 27: `/usr/bin/git` is a 200 KB hardlinked stub (link//! count 78 — the same inode serves `/usr/bin/clang` and `/usr/bin/make`)//! whose one import is `_xcselect_invoke_xcrun`, signed//! `com.apple.dt.xcode_select.tool-shim-public`. It exists on every Mac//! whether git is installed or not, so `which -a git` answers it on a machine//! with no git at all. With no Command Line Tools it exits 1 AND posts *"The//! 'git' command requires the command line developer tools"* into the caller's//! Aqua session — from a LaunchAgent, which is what this app's helper is.//! Homebrew guards the same call for the same reason (`brew.sh`: *"Don't check//! xcrun if Xcode and the CLT aren't installed, as that opens a popup//! window"*). There is no suppression environment variable.//!//! `xcrun --find git` is worse — it shells out to `xcodebuild` and HANGS for//! ever when `xcode-select -p` is `/`. `xcode-select -p` itself is safe but is//! not a validity check: with `DEVELOPER_DIR=/nonexistent` it prints//! `/nonexistent/Developer` and exits 0.//!//! **Stat-ing absolute paths is the only thing that cannot prompt**, so that is//! what every caller does with this list. The stat-ing itself stays with the//! callers, because each has a different answer to "and what does absent//! mean": a sentence on the Serving page in the client, a row's//! `last_bundle_error` in the server, a `COTTON_GIT` nobody exports in the app.//!//! **ABSENCE IS A STATE**, never an error and never a retry against the shim./// Every path a Mac may find `git` at, in the order it is looked for.////// **ORDER IS THE DECISION, not a set.** Homebrew first, because a person who/// installed git chose that git; `/usr/local/bin` next for an Intel Homebrew/// or a hand-built one; then the Command Line Tools' real 3.8 MB binary; then/// Xcode's copy of the same thing.////// [`SHIM`] is not on the list and must never be added — both crates and both/// apps assert that separately, so putting it back means deleting four stated/// rules rather than one comment.pubconst CANDIDATES: [&str; 4] = [// A person who installed git chose that git."/opt/homebrew/bin/git",// Intel Homebrew, or a hand-built one."/usr/local/bin/git",// The Command Line Tools' real binary — what// `com.apple.pkg.CLTools_Executables` actually ships."/Library/Developer/CommandLineTools/usr/bin/git",// Xcode's copy of the same thing."/Applications/Xcode.app/Contents/Developer/usr/bin/git",];/// The path that is NEVER a candidate, named so every guard can say why.////// Refused BY NAME even when something set [`PROGRAM_ENV`] to it deliberately:/// there is no configuration in which running the shim is the right answer, and/// a variable is exactly how it would arrive by accident.pubconst SHIM: &str = "/usr/bin/git";/// The environment variable the answer travels in.////// A variable and not a field on a config struct, for `HelperPaths::litestream`'s/// reason: where a person's git happens to live is not something the FFI ABI/// should grow a field for, and the Mac has to export it before the core/// exists.pubconst PROGRAM_ENV: &str = "COTTON_GIT";#[cfg(test)]#[path = "git_tests.rs"]mod tests;/// Non-Apple git discovery: Linux's /usr/bin/git is a real executable./// Only absolute PATH entries are admitted, so a service never executes a/// repository file through a relative working directory.pubfn git_on_path(path: Option<&std::ffi::OsStr>) -> Option<std::path::PathBuf> {use std::os::unix::fs::PermissionsExt; std::env::split_paths(path?).filter(|p| p.is_absolute()).map(|p| p.join("git")) .find(|p| std::fs::metadata(p).is_ok_and(|m| m.is_file() && m.permissions().mode() & 0o111 != 0))}