Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add the gitoxide.credentials.terminalPrompt key to represent the GIT_TERMINAL_PROMPT (#1090) #1093

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions gix/src/config/cache/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,15 @@ fn apply_environment_overrides(
},
],
),
(
"gitoxide",
Some(Cow::Borrowed("credentials".into())),
git_prefix,
&[{
let key = &gitoxide::Credentials::TERMINAL_PROMPT;
(env(key), key.name)
}],
),
(
"gitoxide",
Some(Cow::Borrowed("committer".into())),
Expand Down
8 changes: 6 additions & 2 deletions gix/src/config/snapshot/credential_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{borrow::Cow, convert::TryFrom};
pub use error::Error;

use crate::config::cache::util::IgnoreEmptyPath;
use crate::config::tree::gitoxide::Credentials;
use crate::{
bstr::{ByteSlice, ByteVec},
config::{
Expand Down Expand Up @@ -144,9 +145,12 @@ impl Snapshot<'_> {
.transpose()
.ignore_empty()?
.map(|c| Cow::Owned(c.into_owned())),
..Default::default()
mode: self
.boolean(Credentials::TERMINAL_PROMPT.logical_name().as_str())
.and_then(|val| (!val).then_some(gix_prompt::Mode::Disable))
.unwrap_or_default(),
}
.apply_environment(allow_git_env, allow_ssh_env, allow_git_env);
.apply_environment(allow_git_env, allow_ssh_env, false /* terminal prompt */);
Ok((
gix_credentials::helper::Cascade {
programs,
Expand Down
28 changes: 27 additions & 1 deletion gix/src/config/tree/sections/gitoxide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ impl Gitoxide {
pub const COMMIT: Commit = Commit;
/// The `gitoxide.committer` section.
pub const COMMITTER: Committer = Committer;
/// The `gitoxide.credentials` section.
pub const CREDENTIALS: Credentials = Credentials;
/// The `gitoxide.http` section.
pub const HTTP: Http = Http;
/// The `gitoxide.https` section.
Expand Down Expand Up @@ -427,6 +429,30 @@ mod subsections {
}
}

/// The `credentials` sub-section.
#[derive(Copy, Clone, Default)]
pub struct Credentials;
impl Credentials {
/// The `gitoxide.credentials.terminalPrompt` key.
pub const TERMINAL_PROMPT: keys::Boolean = keys::Boolean::new_boolean("terminalPrompt", &Gitoxide::CREDENTIALS)
.with_note("This is a custom addition to provide an alternative to the respective environment variable.")
.with_environment_override("GIT_TERMINAL_PROMPT");
}

impl Section for Credentials {
fn name(&self) -> &str {
"credentials"
}

fn keys(&self) -> &[&dyn Key] {
&[&Self::TERMINAL_PROMPT]
}

fn parent(&self) -> Option<&dyn Section> {
Some(&Tree::GITOXIDE)
}
}

/// The `commit` sub-section.
#[derive(Copy, Clone, Default)]
pub struct Commit;
Expand Down Expand Up @@ -454,7 +480,7 @@ mod subsections {
}
}
}
pub use subsections::{Allow, Author, Commit, Committer, Core, Http, Https, Objects, Pathspec, Ssh, User};
pub use subsections::{Allow, Author, Commit, Committer, Core, Credentials, Http, Https, Objects, Pathspec, Ssh, User};

pub mod validate {
use std::error::Error;
Expand Down
2 changes: 2 additions & 0 deletions gix/tests/gix-init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ mod with_overrides {
.set("GIT_GLOB_PATHSPECS", "pathspecs-glob")
.set("GIT_NOGLOB_PATHSPECS", "pathspecs-noglob")
.set("GIT_ICASE_PATHSPECS", "pathspecs-icase")
.set("GIT_TERMINAL_PROMPT", "42")
.set("GIT_SHALLOW_FILE", "shallow-file-env");
let mut opts = gix::open::Options::isolated()
.cli_overrides([
Expand Down Expand Up @@ -234,6 +235,7 @@ mod with_overrides {
("gitoxide.pathspec.glob", "pathspecs-glob"),
("gitoxide.pathspec.noglob", "pathspecs-noglob"),
("gitoxide.pathspec.literal", "pathspecs-literal"),
("gitoxide.credentials.terminalPrompt", "42"),
] {
assert_eq!(
config
Expand Down
Loading