Skip to content

Commit 1fe600e

Browse files
committed
fix: assure that GIT_CONFIG_NOSYTEM is treated as boolean.
That way, it can also be deactivated, which is exactly what `git` does.
1 parent ebd5c6f commit 1fe600e

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

gix-config/src/source.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,26 @@ impl Source {
6666
use Source::*;
6767
match self {
6868
GitInstallation => {
69-
if env_var("GIT_CONFIG_NOSYSTEM").is_some() {
69+
if env_var("GIT_CONFIG_NOSYSTEM")
70+
.map(crate::Boolean::try_from)
71+
.transpose()
72+
.ok()
73+
.flatten()
74+
.map_or(false, |b| b.0)
75+
{
7076
None
7177
} else {
7278
gix_path::env::installation_config().map(Into::into)
7379
}
7480
}
7581
System => {
76-
if env_var("GIT_CONFIG_NOSYSTEM").is_some() {
82+
if env_var("GIT_CONFIG_NOSYSTEM")
83+
.map(crate::Boolean::try_from)
84+
.transpose()
85+
.ok()
86+
.flatten()
87+
.map_or(false, |b| b.0)
88+
{
7789
None
7890
} else {
7991
env_var("GIT_CONFIG_SYSTEM")

gix-config/tests/source/mod.rs

+21
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@ fn git_config_no_system() {
1313
}),
1414
None
1515
);
16+
assert!(
17+
Source::GitInstallation
18+
.storage_location(&mut |name| {
19+
assert_eq!(
20+
name, "GIT_CONFIG_NOSYSTEM",
21+
"it only checks this var, and if set, nothing else"
22+
);
23+
Some("false".into())
24+
})
25+
.is_some(),
26+
"it treats the variable as boolean"
27+
);
1628
assert_eq!(
1729
Source::System.storage_location(&mut |name| {
1830
assert_eq!(
@@ -23,6 +35,15 @@ fn git_config_no_system() {
2335
}),
2436
None
2537
);
38+
assert!(Source::System
39+
.storage_location(&mut |name| {
40+
match name {
41+
"GIT_CONFIG_NOSYSTEM" => Some("false".into()),
42+
"GIT_CONFIG_SYSTEM" => None,
43+
_ => unreachable!("known set"),
44+
}
45+
})
46+
.is_some(),);
2647
}
2748

2849
#[test]

0 commit comments

Comments
 (0)