Use the shared environment scrubber in git-utils (#37843)

Call `scrub_non_inheritable_env_vars` directly from each Git command path and
remove the redundant crate-local forwarding helper.

GitOrigin-RevId: 9e4125dc538ea888626bde3cb3646a90712206a2
This commit is contained in:
cooper-oai
2026-08-10 15:50:53 +00:00
committed by copyberry
parent 8b1b065719
commit 92cbfb4d24
4 changed files with 9 additions and 9 deletions
+4 -3
View File
@@ -6,6 +6,7 @@
//! mode via [`ApplyGitRequest::preflight`] and inspect the resulting paths to
//! learn what would change before applying for real.
use codex_protocol::shell_environment::scrub_non_inheritable_env_vars;
use once_cell::sync::Lazy;
use regex::Regex;
use std::ffi::OsStr;
@@ -130,7 +131,7 @@ fn resolve_git_root(cwd: &Path) -> io::Result<PathBuf> {
.arg("rev-parse")
.arg("--show-toplevel")
.current_dir(cwd);
crate::scrub_non_inheritable_environment(&mut command);
scrub_non_inheritable_env_vars(&mut command);
let out = command.output()?;
let code = out.status.code().unwrap_or(-1);
if code != 0 {
@@ -160,7 +161,7 @@ fn run_git(cwd: &Path, git_cfg: &[String], args: &[String]) -> io::Result<(i32,
for a in args {
cmd.arg(a);
}
crate::scrub_non_inheritable_environment(&mut cmd);
scrub_non_inheritable_env_vars(&mut cmd);
let out = cmd.current_dir(cwd).output()?;
let code = out.status.code().unwrap_or(-1);
let stdout = String::from_utf8_lossy(&out.stdout).into_owned();
@@ -341,7 +342,7 @@ pub fn stage_paths(git_root: &Path, diff: &str) -> io::Result<()> {
for p in &existing {
cmd.arg(OsStr::new(p));
}
crate::scrub_non_inheritable_environment(&mut cmd);
scrub_non_inheritable_env_vars(&mut cmd);
let out = cmd.current_dir(git_root).output()?;
let _code = out.status.code().unwrap_or(-1);
// We do not hard fail staging; best-effort is OK. Return Ok even on non-zero.
+2 -1
View File
@@ -2,6 +2,7 @@ use std::process::Output;
use std::process::Stdio;
use std::time::Duration;
use codex_protocol::shell_environment::scrub_non_inheritable_env_vars;
#[cfg(windows)]
use codex_utils_pty::JobObject;
#[cfg(unix)]
@@ -29,7 +30,7 @@ impl Drop for KillGitProcessTreeOnDrop {
}
fn spawn_git_command(command: &mut Command) -> Option<(Child, KillGitProcessTreeOnDrop)> {
crate::scrub_non_inheritable_environment(command.as_std_mut());
scrub_non_inheritable_env_vars(command.as_std_mut());
#[cfg(unix)]
command.process_group(0);
command.kill_on_drop(true);
-4
View File
@@ -48,7 +48,3 @@ pub use info::recent_commits;
pub use info::resolve_root_git_project_for_trust;
pub use platform::create_symlink;
pub use status::get_has_changes_in_repo;
pub(crate) fn scrub_non_inheritable_environment(command: &mut std::process::Command) {
codex_protocol::shell_environment::scrub_non_inheritable_env_vars(command);
}
+3 -1
View File
@@ -4,6 +4,8 @@ use std::path::Path;
use std::path::PathBuf;
use std::process::Command;
use codex_protocol::shell_environment::scrub_non_inheritable_env_vars;
use crate::GitToolingError;
const DISABLED_HOOKS_PATH: &str = if cfg!(windows) { "NUL" } else { "/dev/null" };
@@ -120,7 +122,7 @@ where
}
}
command.args(&args_vec);
crate::scrub_non_inheritable_environment(&mut command);
scrub_non_inheritable_env_vars(&mut command);
let output = command.output()?;
if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr).trim().to_string();