Skip to content

Commit 6cf73a4

Browse files
committed
feat: use gitoxide.credentials.helperStderr key to control how stderr is handled with helpers.
That way users can configure each repository instance according to their needs, with which includes disabling the `stderr` of credential helpers. Please enter the message for your patch. Lines starting with
1 parent 2189cee commit 6cf73a4

File tree

4 files changed

+33
-7
lines changed

4 files changed

+33
-7
lines changed

gix/src/config/cache/init.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,16 @@ fn apply_environment_overrides(
402402
"gitoxide",
403403
Some(Cow::Borrowed("credentials".into())),
404404
git_prefix,
405-
&[{
406-
let key = &gitoxide::Credentials::TERMINAL_PROMPT;
407-
(env(key), key.name)
408-
}],
405+
&[
406+
{
407+
let key = &gitoxide::Credentials::TERMINAL_PROMPT;
408+
(env(key), key.name)
409+
},
410+
{
411+
let key = &gitoxide::Credentials::HELPER_STDERR;
412+
(env(key), key.name)
413+
},
414+
],
409415
),
410416
(
411417
"gitoxide",

gix/src/config/snapshot/credential_helpers.rs

Lines changed: 13 additions & 2 deletions
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::ApplyLeniency;
56
use crate::{
67
bstr::{ByteSlice, ByteVec},
78
config::{
@@ -25,6 +26,8 @@ mod error {
2526
},
2627
#[error("core.askpass could not be read")]
2728
CoreAskpass(#[from] gix_config::path::interpolate::Error),
29+
#[error(transparent)]
30+
BooleanConfig(#[from] crate::config::boolean::Error),
2831
}
2932
}
3033

@@ -145,7 +148,10 @@ impl Snapshot<'_> {
145148
.ignore_empty()?
146149
.map(|c| Cow::Owned(c.into_owned())),
147150
mode: self
148-
.boolean(Credentials::TERMINAL_PROMPT.logical_name().as_str())
151+
.try_boolean(Credentials::TERMINAL_PROMPT.logical_name().as_str())
152+
.map(|val| Credentials::TERMINAL_PROMPT.enrich_error(val))
153+
.transpose()
154+
.with_leniency(self.repo.config.lenient_config)?
149155
.and_then(|val| (!val).then_some(gix_prompt::Mode::Disable))
150156
.unwrap_or_default(),
151157
}
@@ -156,7 +162,12 @@ impl Snapshot<'_> {
156162
use_http_path,
157163
// The default ssh implementation uses binaries that do their own auth, so our passwords aren't used.
158164
query_user_only: url.scheme == gix_url::Scheme::Ssh,
159-
..Default::default()
165+
stderr: self
166+
.try_boolean(Credentials::HELPER_STDERR.logical_name().as_str())
167+
.map(|val| Credentials::HELPER_STDERR.enrich_error(val))
168+
.transpose()
169+
.with_leniency(self.repo.options.lenient_config)?
170+
.unwrap_or(true),
160171
},
161172
gix_credentials::helper::Action::get_for_url(url.to_bstring()),
162173
prompt_options,

gix/src/config/tree/sections/gitoxide.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,13 @@ mod subsections {
467467
pub const TERMINAL_PROMPT: keys::Boolean = keys::Boolean::new_boolean("terminalPrompt", &Gitoxide::CREDENTIALS)
468468
.with_note("This is a custom addition to provide an alternative to the respective environment variable.")
469469
.with_environment_override("GIT_TERMINAL_PROMPT");
470+
471+
/// The `gitoxide.credentials.helperStderr` key to control what happens with the credential helpers `stderr`.
472+
///
473+
/// If `true`, the default, `stderr` of credential helper programs will be inherited, just like with `git`.
474+
/// If `false`, will be suppressed completely.
475+
pub const HELPER_STDERR: keys::Boolean = keys::Boolean::new_boolean("helperStderr", &Gitoxide::CREDENTIALS)
476+
.with_environment_override("GIX_CREDENTIALS_HELPER_STDERR");
470477
}
471478

472479
impl Section for Credentials {
@@ -475,7 +482,7 @@ mod subsections {
475482
}
476483

477484
fn keys(&self) -> &[&dyn Key] {
478-
&[&Self::TERMINAL_PROMPT]
485+
&[&Self::TERMINAL_PROMPT, &Self::HELPER_STDERR]
479486
}
480487

481488
fn parent(&self) -> Option<&dyn Section> {

gix/tests/gix-init.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ mod with_overrides {
4040
.set("EMAIL", "user email")
4141
.set("GIX_PACK_CACHE_MEMORY", "0")
4242
.set("GIX_OBJECT_CACHE_MEMORY", "5m")
43+
.set("GIX_CREDENTIALS_HELPER_STDERR", "creds-stderr")
4344
.set("GIT_SSL_CAINFO", "./env.pem")
4445
.set("GIT_SSL_VERSION", "tlsv1.3")
4546
.set("GIT_SSH_VARIANT", "ssh-variant-env")
@@ -254,6 +255,7 @@ mod with_overrides {
254255
("gitoxide.pathspec.noglob", "pathspecs-noglob"),
255256
("gitoxide.pathspec.literal", "pathspecs-literal"),
256257
("gitoxide.credentials.terminalPrompt", "42"),
258+
("gitoxide.credentials.helperStderr", "creds-stderr"),
257259
] {
258260
assert_eq!(
259261
config

0 commit comments

Comments
 (0)