Skip to content

Commit 6738955

Browse files
committed
feat: GIT_CONFIG_NOSYSTEM now also affects the installation directory.
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`.
1 parent ec0211a commit 6738955

File tree

3 files changed

+73
-2
lines changed

3 files changed

+73
-2
lines changed

gix-config/src/source.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,15 @@ impl Source {
6565
pub fn storage_location(self, env_var: &mut dyn FnMut(&str) -> Option<OsString>) -> Option<Cow<'static, Path>> {
6666
use Source::*;
6767
match self {
68-
GitInstallation => gix_path::env::installation_config().map(Into::into),
68+
GitInstallation => {
69+
if env_var("GIT_CONFIG_NOSYSTEM").is_some() {
70+
None
71+
} else {
72+
gix_path::env::installation_config().map(Into::into)
73+
}
74+
}
6975
System => {
70-
if env_var("GIT_CONFIG_NO_SYSTEM").is_some() {
76+
if env_var("GIT_CONFIG_NOSYSTEM").is_some() {
7177
None
7278
} else {
7379
env_var("GIT_CONFIG_SYSTEM")

gix-config/tests/config.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ pub use gix_testtools::Result;
22

33
mod file;
44
mod parse;
5+
mod source;
56
mod value;

gix-config/tests/source/mod.rs

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
use gix_config::Source;
2+
use std::path::Path;
3+
4+
#[test]
5+
fn git_config_no_system() {
6+
assert_eq!(
7+
Source::GitInstallation.storage_location(&mut |name| {
8+
assert_eq!(
9+
name, "GIT_CONFIG_NOSYSTEM",
10+
"it only checks this var, and if set, nothing else"
11+
);
12+
Some("1".into())
13+
}),
14+
None
15+
);
16+
assert_eq!(
17+
Source::System.storage_location(&mut |name| {
18+
assert_eq!(
19+
name, "GIT_CONFIG_NOSYSTEM",
20+
"it only checks this var, and if set, nothing else"
21+
);
22+
Some("1".into())
23+
}),
24+
None
25+
);
26+
}
27+
28+
#[test]
29+
fn git_config_system() {
30+
assert_eq!(
31+
Source::System
32+
.storage_location(&mut |name| {
33+
match name {
34+
"GIT_CONFIG_NOSYSTEM" => None,
35+
"GIT_CONFIG_SYSTEM" => Some("alternative".into()),
36+
unexpected => unreachable!("unexpected env var: {unexpected}"),
37+
}
38+
})
39+
.expect("set")
40+
.as_ref(),
41+
Path::new("alternative"),
42+
"we respect the system config variable for overrides"
43+
);
44+
}
45+
46+
#[test]
47+
fn git_config_global() {
48+
for source in [Source::Git, Source::User] {
49+
assert_eq!(
50+
source
51+
.storage_location(&mut |name| {
52+
assert_eq!(
53+
name, "GIT_CONFIG_GLOBAL",
54+
"it only checks this var, and if set, nothing else"
55+
);
56+
Some("alternative".into())
57+
})
58+
.expect("set")
59+
.as_ref(),
60+
Path::new("alternative"),
61+
"we respect the global config variable for 'git' overrides"
62+
);
63+
}
64+
}

0 commit comments

Comments
 (0)