Skip to content

Commit

Permalink
Merge pull request #1583 from EliahKagan/config-origin-env
Browse files Browse the repository at this point in the history
Don't read "installation" config from `GIT_CONFIG`
  • Loading branch information
Byron committed Sep 6, 2024
2 parents d00235a + eb72d31 commit 130db3b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
5 changes: 4 additions & 1 deletion gix-path/src/env/git/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
47 changes: 47 additions & 0 deletions gix-path/src/env/git/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 =
Expand Down

0 comments on commit 130db3b

Please sign in to comment.