Skip to content

Commit

Permalink
feat: GIT_CONFIG_NOSYSTEM now also affects the installation directory.
Browse files Browse the repository at this point in the history
It makes sense to consider it part of the 'system', and allows for proper
isolation of `gix` operations, for example in tests.

This is also a fix, as previously it checked for `...NO_SYSTEM`, instead of `NOSYSTEM`.
  • Loading branch information
Byron committed Dec 7, 2023
1 parent ec0211a commit 6738955
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 2 deletions.
10 changes: 8 additions & 2 deletions gix-config/src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,15 @@ impl Source {
pub fn storage_location(self, env_var: &mut dyn FnMut(&str) -> Option<OsString>) -> Option<Cow<'static, Path>> {
use Source::*;
match self {
GitInstallation => gix_path::env::installation_config().map(Into::into),
GitInstallation => {
if env_var("GIT_CONFIG_NOSYSTEM").is_some() {
None
} else {
gix_path::env::installation_config().map(Into::into)
}
}
System => {
if env_var("GIT_CONFIG_NO_SYSTEM").is_some() {
if env_var("GIT_CONFIG_NOSYSTEM").is_some() {
None
} else {
env_var("GIT_CONFIG_SYSTEM")
Expand Down
1 change: 1 addition & 0 deletions gix-config/tests/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ pub use gix_testtools::Result;

mod file;
mod parse;
mod source;
mod value;
64 changes: 64 additions & 0 deletions gix-config/tests/source/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
use gix_config::Source;
use std::path::Path;

#[test]
fn git_config_no_system() {
assert_eq!(
Source::GitInstallation.storage_location(&mut |name| {
assert_eq!(
name, "GIT_CONFIG_NOSYSTEM",
"it only checks this var, and if set, nothing else"
);
Some("1".into())
}),
None
);
assert_eq!(
Source::System.storage_location(&mut |name| {
assert_eq!(
name, "GIT_CONFIG_NOSYSTEM",
"it only checks this var, and if set, nothing else"
);
Some("1".into())
}),
None
);
}

#[test]
fn git_config_system() {
assert_eq!(
Source::System
.storage_location(&mut |name| {
match name {
"GIT_CONFIG_NOSYSTEM" => None,
"GIT_CONFIG_SYSTEM" => Some("alternative".into()),
unexpected => unreachable!("unexpected env var: {unexpected}"),
}
})
.expect("set")
.as_ref(),
Path::new("alternative"),
"we respect the system config variable for overrides"
);
}

#[test]
fn git_config_global() {
for source in [Source::Git, Source::User] {
assert_eq!(
source
.storage_location(&mut |name| {
assert_eq!(
name, "GIT_CONFIG_GLOBAL",
"it only checks this var, and if set, nothing else"
);
Some("alternative".into())
})
.expect("set")
.as_ref(),
Path::new("alternative"),
"we respect the global config variable for 'git' overrides"
);
}
}

0 comments on commit 6738955

Please sign in to comment.