1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//! Hermetic git spawn factory, the ONE owner of the trusted-binary resolution
//! and isolation environment every git invocation needs.
//!
//! This lives OUTSIDE the `git` module because it must be reachable from two
//! independently-gated callers: the full git source (`#[cfg(feature = "git")]`)
//! AND the hosted-git clone path (`#[cfg(any(feature = "github", "gitlab",
//! "bitbucket"))]`). Routing both through here means a hosted clone gets the same
//! `GIT_CONFIG_GLOBAL/SYSTEM` nulling as every other spawn, and the isolation
//! set cannot drift between the two entry points.
use SourceError;
use PathBuf;
use Command;
/// Platform null device. A git config path pointing here reads as "no config"
/// on both Git-for-Windows (`NUL`) and POSIX git (`/dev/null`).
const GIT_NULL_CONFIG: &str = if cfg! else ;
/// Resolve `git` to an absolute path inside a trusted system bin dir.
/// SECURITY (kimi-wave1 audit finding 3.PATH-git): refuses to fall back to
/// `Command::new("git")`, which would let a hostile `$PATH` substitute the git
/// binary at runtime, keyhog feeds git the repo path and scans the blob bytes
/// it returns, so a substituted git could exfiltrate credentials directly.
pub
/// Apply the hermetic isolation env to a git [`Command`]. Nulling the global +
/// system config disables ALL host config (`commit.gpgsign`, `credential.helper`,
/// `core.hooksPath`, …) so no host setting can hook, sign, or block-on-prompt a
/// keyhog git spawn (a latent CI hang; Testing-Contract HOST-INDEPENDENCE).
/// ONE PLACE for the isolation set shared by [`git_command`] and any caller that
/// must build its own `Command` (e.g. the hosted clone, which layers askpass).
pub
/// Build a `git` [`Command`] with the resolved safe binary AND the hermetic
/// environment. ONE PLACE: every git spawn goes through here rather than
/// `Command::new(git_bin()?)`, so the isolation cannot drift per call site.
pub