Skip to content

Commit 334281c

Browse files
committed
fix: ignore empty core.askpass settings
This is the same as what `git` does, it's explicit per value, which means that other paths might be flagged as empty automatically.
1 parent db0c401 commit 334281c

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

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)