From 92cbfb4d2431bdc53dc03507aea2dc5b8e932e40 Mon Sep 17 00:00:00 2001 From: cooper-oai Date: Mon, 10 Aug 2026 15:43:25 +0000 Subject: [PATCH] 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 --- codex-rs/git-utils/src/apply.rs | 7 ++++--- codex-rs/git-utils/src/git_process.rs | 3 ++- codex-rs/git-utils/src/lib.rs | 4 ---- codex-rs/git-utils/src/operations.rs | 4 +++- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/codex-rs/git-utils/src/apply.rs b/codex-rs/git-utils/src/apply.rs index 56bd416914..72b5fba1f5 100644 --- a/codex-rs/git-utils/src/apply.rs +++ b/codex-rs/git-utils/src/apply.rs @@ -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 { .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. diff --git a/codex-rs/git-utils/src/git_process.rs b/codex-rs/git-utils/src/git_process.rs index d6af3fd26e..3ce0431434 100644 --- a/codex-rs/git-utils/src/git_process.rs +++ b/codex-rs/git-utils/src/git_process.rs @@ -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); diff --git a/codex-rs/git-utils/src/lib.rs b/codex-rs/git-utils/src/lib.rs index 99fe12f4e9..1c75e7e7da 100644 --- a/codex-rs/git-utils/src/lib.rs +++ b/codex-rs/git-utils/src/lib.rs @@ -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); -} diff --git a/codex-rs/git-utils/src/operations.rs b/codex-rs/git-utils/src/operations.rs index 0dce4524b8..f03b5450d7 100644 --- a/codex-rs/git-utils/src/operations.rs +++ b/codex-rs/git-utils/src/operations.rs @@ -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();