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
//! Isolated git command builder.
//!
//! Every `Command::new("git")` in this codebase should use [`git_cmd`] instead.
//! It strips inherited `GIT_*` environment variables that leak repo context
//! from parent processes (hooks, worktrees, editors). Without this, a `git init`
//! in a temp directory can silently commit to the real repository.
use Command;
/// Environment variables that leak parent repo context into child git processes.
const GIT_ENV_VARS: & = &;
/// Create a `Command` for git with inherited repo context stripped.
///
/// Use this instead of `Command::new("git")` everywhere — production and test code alike.
/// The caller still needs to set `.current_dir()` and `.args()` as usual.
///
/// ```ignore
/// use crate::git::cmd::git_cmd;
///
/// let output = git_cmd()
/// .args(["diff", "HEAD", "--stat"])
/// .current_dir(&repo_root)
/// .output()?;
/// ```