Skip to content

Commit 9c528dc

Browse files
committed
Merge branch 'path-config'
2 parents afb1960 + 334281c commit 9c528dc

File tree

5 files changed

+63
-1
lines changed

5 files changed

+63
-1
lines changed

gix-config/tests/file/access/read_only.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ fn get_value_for_all_provided_values() -> crate::Result {
2626
other-quoted = "hello world"
2727
location = ~/tmp
2828
location-quoted = "~/quoted"
29+
empty-implicit
30+
empty-equals =
31+
empty-explicit = ""
2932
"#;
3033
for lossy in [false, true] {
3134
let config = File::from_bytes_no_includes(
@@ -54,6 +57,34 @@ fn get_value_for_all_provided_values() -> crate::Result {
5457
None,
5558
"unset values are not present"
5659
);
60+
assert_eq!(
61+
config.string("core", None, "empty-implicit"),
62+
None,
63+
"mere presence is at most a boolean"
64+
);
65+
assert_eq!(
66+
config.path("core", None, "empty-implicit"),
67+
None,
68+
"mere presence is at most a boolean"
69+
);
70+
assert_eq!(
71+
config.string("core", None, "empty-equals"),
72+
Some(cow_str("")),
73+
"mere presence with equal sign is always the empty implicit string"
74+
);
75+
assert!(
76+
config.path("core", None, "empty-equals").is_some(),
77+
"this is an empty path…"
78+
);
79+
assert_eq!(
80+
config.string("core", None, "empty-explicit"),
81+
Some(cow_str("")),
82+
"and so is an explicit empty string"
83+
);
84+
assert!(
85+
config.path("core", None, "empty-explicit").is_some(),
86+
"and so is an explicit empty path"
87+
);
5788
assert_eq!(
5889
config.strings("core", None, "bool-implicit").expect("present"),
5990
&[cow_str("")],

gix/src/config/cache/util.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ pub trait ApplyLeniency {
120120
fn with_leniency(self, is_lenient: bool) -> Self;
121121
}
122122

123+
pub trait IgnoreEmptyPath {
124+
fn ignore_empty(self) -> Self;
125+
}
126+
123127
pub trait ApplyLeniencyDefault {
124128
fn with_lenient_default(self, is_lenient: bool) -> Self;
125129
}
@@ -138,6 +142,16 @@ impl<T, E> ApplyLeniency for Result<Option<T>, E> {
138142
}
139143
}
140144

145+
impl IgnoreEmptyPath for Result<Option<std::borrow::Cow<'_, std::path::Path>>, gix_config::path::interpolate::Error> {
146+
fn ignore_empty(self) -> Self {
147+
match self {
148+
Ok(maybe_path) => Ok(maybe_path),
149+
Err(gix_config::path::interpolate::Error::Missing { .. }) => Ok(None),
150+
Err(err) => Err(err),
151+
}
152+
}
153+
}
154+
141155
impl<T, E> ApplyLeniencyDefault for Result<T, E>
142156
where
143157
T: Default,

gix/src/config/snapshot/credential_helpers.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::{borrow::Cow, convert::TryFrom};
22

33
pub use error::Error;
44

5+
use crate::config::cache::util::IgnoreEmptyPath;
56
use crate::{
67
bstr::{ByteSlice, ByteVec},
78
config::{
@@ -140,7 +141,8 @@ impl Snapshot<'_> {
140141
let prompt_options = gix_prompt::Options {
141142
askpass: self
142143
.trusted_path(Core::ASKPASS.logical_name().as_str())
143-
.transpose()?
144+
.transpose()
145+
.ignore_empty()?
144146
.map(|c| Cow::Owned(c.into_owned())),
145147
..Default::default()
146148
}

gix/tests/fixtures/make_remote_repos.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,3 +370,8 @@ git clone one-commit-with-symref one-commit-with-symref-missing-branch
370370
(cd one-commit-with-symref-missing-branch
371371
git branch valid-locally
372372
)
373+
374+
git init empty-core-askpass
375+
(cd empty-core-askpass
376+
echo " askpass =" >> .git/config
377+
)

gix/tests/repository/config/config_snapshot/credential_helpers.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::remote;
12
use gix_testtools::Env;
23

34
mod baseline {
@@ -205,3 +206,12 @@ fn invalid_urls_are_rejected_early() {
205206
baseline::works_but_we_dont_parse_invalid_url("ssh://host:21");
206207
baseline::works_but_we_dont_parse_invalid_url("git://host.org");
207208
}
209+
210+
#[test]
211+
fn empty_core_askpass_is_ignored() -> crate::Result {
212+
let repo = remote::repo("empty-core-askpass");
213+
let _ = repo
214+
.config_snapshot()
215+
.credential_helpers("does-not-matter".try_into()?)?;
216+
Ok(())
217+
}

0 commit comments

Comments
 (0)