Skip to content

Commit 340ff37

Browse files
committed
Start testing that installation config is not from GIT_CONFIG
These tests should not pass yet, because we currently do allow `GIT_CONFIG` to be read. Although the optimization that reads `EXEPATH` will sometimes prevent it from being used, it will usually be used, becuase `EXEPATH` is usually not set on Windows (and outside of Windows, that optimization is inapplicable). Furthermore, the tests in `gix-path/src/env/git/tests.rs` bypass that optimization. Two of the three new tests rightly fail. But one of them, `never_from_git_config_env_var`, wrongly passes, due to a big in the test, described in the comments there.
1 parent 01a412f commit 340ff37

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

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

Lines changed: 48 additions & 0 deletions
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,34 @@ 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+
// FIXME: exe_info() changes directory, so this is not seen, which results in this test
585+
// wrongly passing even if exe_info() does not really ensure GIT_CONFIG is ignore. So
586+
// either make this path an absolute non-UNC path (non-UNC to ensure all versions of Git
587+
// accept it) or use a newly created temporary file rather than the fixture.
588+
let config_path = repo
589+
.join(".git")
590+
.join("config")
591+
.to_str()
592+
.expect("valid UTF-8")
593+
.to_owned();
594+
595+
let _env = gix_testtools::Env::new()
596+
.set("GIT_CONFIG_NOSYSTEM", "1")
597+
.set("GIT_CONFIG_GLOBAL", NULL_DEVICE)
598+
.set("GIT_CONFIG", config_path);
599+
600+
let maybe_path = exe_info();
601+
assert_eq!(
602+
maybe_path, None,
603+
"Should find no config path from GIT_CONFIG (even if nonempty)"
604+
);
605+
}
606+
559607
#[test]
560608
fn first_file_from_config_with_origin() {
561609
let macos =

0 commit comments

Comments
 (0)