Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't read "installation" config from GIT_CONFIG #1583

Merged
merged 4 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading