Skip to content

Commit e95bb9f

Browse files
committed
feat: add the gitoxide.credentials.terminalPrompt key to represent the GIT_TERMINAL_PROMPT (#1090)
That way, it's easy to control the usage of terminals without using and environment.
1 parent e47c46d commit e95bb9f

File tree

4 files changed

+44
-3
lines changed

4 files changed

+44
-3
lines changed

gix/src/config/cache/init.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,15 @@ fn apply_environment_overrides(
385385
},
386386
],
387387
),
388+
(
389+
"gitoxide",
390+
Some(Cow::Borrowed("credentials".into())),
391+
git_prefix,
392+
&[{
393+
let key = &gitoxide::Credentials::TERMINAL_PROMPT;
394+
(env(key), key.name)
395+
}],
396+
),
388397
(
389398
"gitoxide",
390399
Some(Cow::Borrowed("committer".into())),

gix/src/config/snapshot/credential_helpers.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::{borrow::Cow, convert::TryFrom};
33
pub use error::Error;
44

55
use crate::config::cache::util::IgnoreEmptyPath;
6+
use crate::config::tree::gitoxide::Credentials;
67
use crate::{
78
bstr::{ByteSlice, ByteVec},
89
config::{
@@ -144,9 +145,12 @@ impl Snapshot<'_> {
144145
.transpose()
145146
.ignore_empty()?
146147
.map(|c| Cow::Owned(c.into_owned())),
147-
..Default::default()
148+
mode: self
149+
.boolean(Credentials::TERMINAL_PROMPT.logical_name().as_str())
150+
.and_then(|val| (!val).then_some(gix_prompt::Mode::Disable))
151+
.unwrap_or_default(),
148152
}
149-
.apply_environment(allow_git_env, allow_ssh_env, allow_git_env);
153+
.apply_environment(allow_git_env, allow_ssh_env, false /* terminal prompt */);
150154
Ok((
151155
gix_credentials::helper::Cascade {
152156
programs,

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ impl Gitoxide {
1414
pub const COMMIT: Commit = Commit;
1515
/// The `gitoxide.committer` section.
1616
pub const COMMITTER: Committer = Committer;
17+
/// The `gitoxide.credentials` section.
18+
pub const CREDENTIALS: Credentials = Credentials;
1719
/// The `gitoxide.http` section.
1820
pub const HTTP: Http = Http;
1921
/// The `gitoxide.https` section.
@@ -427,6 +429,30 @@ mod subsections {
427429
}
428430
}
429431

432+
/// The `credentials` sub-section.
433+
#[derive(Copy, Clone, Default)]
434+
pub struct Credentials;
435+
impl Credentials {
436+
/// The `gitoxide.credentials.terminalPrompt` key.
437+
pub const TERMINAL_PROMPT: keys::Boolean = keys::Boolean::new_boolean("terminalPrompt", &Gitoxide::CREDENTIALS)
438+
.with_note("This is a custom addition to provide an alternative to the respective environment variable.")
439+
.with_environment_override("GIT_TERMINAL_PROMPT");
440+
}
441+
442+
impl Section for Credentials {
443+
fn name(&self) -> &str {
444+
"credentials"
445+
}
446+
447+
fn keys(&self) -> &[&dyn Key] {
448+
&[&Self::TERMINAL_PROMPT]
449+
}
450+
451+
fn parent(&self) -> Option<&dyn Section> {
452+
Some(&Tree::GITOXIDE)
453+
}
454+
}
455+
430456
/// The `commit` sub-section.
431457
#[derive(Copy, Clone, Default)]
432458
pub struct Commit;
@@ -454,7 +480,7 @@ mod subsections {
454480
}
455481
}
456482
}
457-
pub use subsections::{Allow, Author, Commit, Committer, Core, Http, Https, Objects, Pathspec, Ssh, User};
483+
pub use subsections::{Allow, Author, Commit, Committer, Core, Credentials, Http, Https, Objects, Pathspec, Ssh, User};
458484

459485
pub mod validate {
460486
use std::error::Error;

gix/tests/gix-init.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ mod with_overrides {
4848
.set("GIT_GLOB_PATHSPECS", "pathspecs-glob")
4949
.set("GIT_NOGLOB_PATHSPECS", "pathspecs-noglob")
5050
.set("GIT_ICASE_PATHSPECS", "pathspecs-icase")
51+
.set("GIT_TERMINAL_PROMPT", "42")
5152
.set("GIT_SHALLOW_FILE", "shallow-file-env");
5253
let mut opts = gix::open::Options::isolated()
5354
.cli_overrides([
@@ -234,6 +235,7 @@ mod with_overrides {
234235
("gitoxide.pathspec.glob", "pathspecs-glob"),
235236
("gitoxide.pathspec.noglob", "pathspecs-noglob"),
236237
("gitoxide.pathspec.literal", "pathspecs-literal"),
238+
("gitoxide.credentials.terminalPrompt", "42"),
237239
] {
238240
assert_eq!(
239241
config

0 commit comments

Comments
 (0)