Skip to content

Commit 130db3b

Browse files
authored
Merge pull request #1583 from EliahKagan/config-origin-env
Don't read "installation" config from `GIT_CONFIG`
2 parents d00235a + eb72d31 commit 130db3b

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

gix-path/src/env/git/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,11 @@ fn git_cmd(executable: PathBuf) -> Command {
140140
// scope. Although `GIT_CONFIG_NOSYSTEM` will suppress this as well, passing --system omits it.
141141
cmd.args(["config", "-lz", "--show-origin", "--name-only"])
142142
.current_dir(cwd)
143-
.env_remove("GIT_COMMON_DIR") // We are setting `GIT_DIR`.
143+
.env_remove("GIT_CONFIG")
144144
.env_remove("GIT_DISCOVERY_ACROSS_FILESYSTEM")
145+
.env_remove("GIT_OBJECT_DIRECTORY")
146+
.env_remove("GIT_ALTERNATE_OBJECT_DIRECTORIES")
147+
.env_remove("GIT_COMMON_DIR")
145148
.env("GIT_DIR", NULL_DEVICE) // Avoid getting local-scope config.
146149
.env("GIT_WORK_TREE", NULL_DEVICE) // Avoid confusion when debugging.
147150
.stdin(Stdio::null())

gix-path/src/env/git/tests.rs

+47
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,13 @@ mod exe_info {
453453
check_exe_info();
454454
}
455455

456+
#[test]
457+
#[serial]
458+
fn tolerates_git_config_env_var() {
459+
let _env = gix_testtools::Env::new().set("GIT_CONFIG", NULL_DEVICE);
460+
check_exe_info();
461+
}
462+
456463
#[test]
457464
#[serial]
458465
fn same_result_with_broken_temp() {
@@ -480,6 +487,19 @@ mod exe_info {
480487
assert_eq!(with_unmodified_env, with_oversanitized_env);
481488
}
482489

490+
#[test]
491+
#[serial]
492+
fn same_result_with_git_config_env_var() {
493+
let with_unmodified_env = exe_info();
494+
495+
let with_git_config_env_var = {
496+
let _env = gix_testtools::Env::new().set("GIT_CONFIG", NULL_DEVICE);
497+
exe_info()
498+
};
499+
500+
assert_eq!(with_unmodified_env, with_git_config_env_var);
501+
}
502+
483503
#[test]
484504
#[serial]
485505
#[cfg(not(target_os = "macos"))] // Assumes no higher "unknown" scope. The `nosystem` case works.
@@ -556,6 +576,33 @@ mod exe_info {
556576
);
557577
}
558578

579+
#[test]
580+
#[serial]
581+
fn never_from_git_config_env_var() {
582+
let repo = gix_testtools::scripted_fixture_read_only("local_config.sh").expect("script succeeds");
583+
584+
// Get an absolute path to a config file that is non-UNC if possible so any Git accepts it.
585+
let config_path = std::env::current_dir()
586+
.expect("got CWD")
587+
.join(repo)
588+
.join(".git")
589+
.join("config")
590+
.to_str()
591+
.expect("valid UTF-8")
592+
.to_owned();
593+
594+
let _env = gix_testtools::Env::new()
595+
.set("GIT_CONFIG_NOSYSTEM", "1")
596+
.set("GIT_CONFIG_GLOBAL", NULL_DEVICE)
597+
.set("GIT_CONFIG", config_path);
598+
599+
let maybe_path = exe_info();
600+
assert_eq!(
601+
maybe_path, None,
602+
"Should find no config path from GIT_CONFIG (even if nonempty)"
603+
);
604+
}
605+
559606
#[test]
560607
fn first_file_from_config_with_origin() {
561608
let macos =

0 commit comments

Comments
 (0)