diff --git a/gix-path/src/env/git/mod.rs b/gix-path/src/env/git/mod.rs index f32f06eef2f..03d7a000aed 100644 --- a/gix-path/src/env/git/mod.rs +++ b/gix-path/src/env/git/mod.rs @@ -140,8 +140,11 @@ fn git_cmd(executable: PathBuf) -> Command { // scope. Although `GIT_CONFIG_NOSYSTEM` will suppress this as well, passing --system omits it. cmd.args(["config", "-lz", "--show-origin", "--name-only"]) .current_dir(cwd) - .env_remove("GIT_COMMON_DIR") // We are setting `GIT_DIR`. + .env_remove("GIT_CONFIG") .env_remove("GIT_DISCOVERY_ACROSS_FILESYSTEM") + .env_remove("GIT_OBJECT_DIRECTORY") + .env_remove("GIT_ALTERNATE_OBJECT_DIRECTORIES") + .env_remove("GIT_COMMON_DIR") .env("GIT_DIR", NULL_DEVICE) // Avoid getting local-scope config. .env("GIT_WORK_TREE", NULL_DEVICE) // Avoid confusion when debugging. .stdin(Stdio::null()) diff --git a/gix-path/src/env/git/tests.rs b/gix-path/src/env/git/tests.rs index e02fdb349f0..0b2bf195af9 100644 --- a/gix-path/src/env/git/tests.rs +++ b/gix-path/src/env/git/tests.rs @@ -453,6 +453,13 @@ mod exe_info { check_exe_info(); } + #[test] + #[serial] + fn tolerates_git_config_env_var() { + let _env = gix_testtools::Env::new().set("GIT_CONFIG", NULL_DEVICE); + check_exe_info(); + } + #[test] #[serial] fn same_result_with_broken_temp() { @@ -480,6 +487,19 @@ mod exe_info { assert_eq!(with_unmodified_env, with_oversanitized_env); } + #[test] + #[serial] + fn same_result_with_git_config_env_var() { + let with_unmodified_env = exe_info(); + + let with_git_config_env_var = { + let _env = gix_testtools::Env::new().set("GIT_CONFIG", NULL_DEVICE); + exe_info() + }; + + assert_eq!(with_unmodified_env, with_git_config_env_var); + } + #[test] #[serial] #[cfg(not(target_os = "macos"))] // Assumes no higher "unknown" scope. The `nosystem` case works. @@ -556,6 +576,33 @@ mod exe_info { ); } + #[test] + #[serial] + fn never_from_git_config_env_var() { + let repo = gix_testtools::scripted_fixture_read_only("local_config.sh").expect("script succeeds"); + + // Get an absolute path to a config file that is non-UNC if possible so any Git accepts it. + let config_path = std::env::current_dir() + .expect("got CWD") + .join(repo) + .join(".git") + .join("config") + .to_str() + .expect("valid UTF-8") + .to_owned(); + + let _env = gix_testtools::Env::new() + .set("GIT_CONFIG_NOSYSTEM", "1") + .set("GIT_CONFIG_GLOBAL", NULL_DEVICE) + .set("GIT_CONFIG", config_path); + + let maybe_path = exe_info(); + assert_eq!( + maybe_path, None, + "Should find no config path from GIT_CONFIG (even if nonempty)" + ); + } + #[test] fn first_file_from_config_with_origin() { let macos =