Skip to main content

fallow_engine/
git_env.rs

1//! Git process environment helpers owned by the engine boundary.
2
3use std::process::Command;
4
5/// Environment variables that describe an enclosing git operation's repository
6/// state and should not leak into fallow-owned git subprocesses.
7pub const AMBIENT_GIT_ENV_VARS: &[&str] = &[
8    "GIT_DIR",
9    "GIT_WORK_TREE",
10    "GIT_INDEX_FILE",
11    "GIT_OBJECT_DIRECTORY",
12    "GIT_COMMON_DIR",
13    "GIT_PREFIX",
14];
15
16/// Strip ambient git repository-state environment variables from a `Command`.
17///
18/// Returns the `Command` for fluent chaining alongside `.args()` and
19/// `.current_dir()`.
20pub fn clear_ambient_git_env(cmd: &mut Command) -> &mut Command {
21    for var in AMBIENT_GIT_ENV_VARS {
22        cmd.env_remove(var);
23    }
24    cmd
25}