Skip to content

Commit

Permalink
Fix removing git env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
j178 committed Feb 13, 2025
1 parent 4c26fa2 commit b5bef4c
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub enum Error {

pub static GIT: LazyLock<Result<PathBuf, which::Error>> = LazyLock::new(|| which::which("git"));

static GIT_ENV: LazyLock<Vec<(String, String)>> = LazyLock::new(|| {
static GIT_ENV_REMOVE: LazyLock<()> = LazyLock::new(|| {
let keep = &[
"GIT_EXEC_PATH",
"GIT_SSH",
Expand All @@ -33,20 +33,24 @@ static GIT_ENV: LazyLock<Vec<(String, String)>> = LazyLock::new(|| {
"GIT_ASKPASS",
];

std::env::vars()
let to_remove = std::env::vars()
.filter(|(k, _)| {
!k.starts_with("GIT_")
|| k.starts_with("GIT_CONFIG_KEY_")
|| k.starts_with("GIT_CONFIG_VALUE_")
|| keep.contains(&k.as_str())
})
.collect()
k.starts_with("GIT_")
&& !k.starts_with("GIT_CONFIG_KEY_")
&& !k.starts_with("GIT_CONFIG_VALUE_")
&& !keep.contains(&k.as_str())
});

for (k, _) in to_remove {
unsafe { std::env::remove_var(&k) };
}
});

pub fn git_cmd(summary: &str) -> Result<Cmd, Error> {
let mut cmd = Cmd::new(GIT.as_ref().map_err(|&e| Error::GitNotFound(e))?, summary);
cmd.arg("-c").arg("core.useBuiltinFSMonitor=false");
cmd.envs(GIT_ENV.iter().cloned());

LazyLock::force(&GIT_ENV_REMOVE);

Ok(cmd)
}
Expand Down

0 comments on commit b5bef4c

Please sign in to comment.