diff --git a/gitoxide-core/src/repository/credential.rs b/gitoxide-core/src/repository/credential.rs index 9684250bd4d..451e453b7c9 100644 --- a/gitoxide-core/src/repository/credential.rs +++ b/gitoxide-core/src/repository/credential.rs @@ -6,9 +6,11 @@ enum Error { Configuration(#[from] gix::config::credential_helpers::Error), #[error(transparent)] Protocol(#[from] gix::credentials::protocol::Error), + #[error(transparent)] + ConfigLoad(#[from] gix::config::file::init::from_paths::Error), } -pub fn function(repo: gix::Repository, action: gix::credentials::program::main::Action) -> anyhow::Result<()> { +pub fn function(repo: Option, action: gix::credentials::program::main::Action) -> anyhow::Result<()> { use gix::credentials::program::main::Action::*; gix::credentials::program::main( Some(action.as_str().into()), @@ -20,9 +22,24 @@ pub fn function(repo: gix::Repository, action: gix::credentials::program::main:: .clone() .or_else(|| context.to_url()) .ok_or(Error::Protocol(gix::credentials::protocol::Error::UrlMissing))?; - let (mut cascade, _action, prompt_options) = repo - .config_snapshot() - .credential_helpers(gix::url::parse(url.as_ref())?)?; + + let (mut cascade, _action, prompt_options) = match repo { + Some(ref repo) => repo + .config_snapshot() + .credential_helpers(gix::url::parse(url.as_ref())?)?, + None => { + let config = gix::config::File::from_globals()?; + let environment = gix::open::permissions::Environment::all(); + gix::config::credential_helpers( + gix::url::parse(url.as_ref())?, + &config, + false, /* lenient config */ + |_| true, /* section filter */ + environment, + false, /* use http path (override, uses configuration now)*/ + )? + } + }; cascade .invoke( match action { diff --git a/src/plumbing/main.rs b/src/plumbing/main.rs index 4b62fa626c2..1ff9821d904 100644 --- a/src/plumbing/main.rs +++ b/src/plumbing/main.rs @@ -658,7 +658,7 @@ pub fn main() -> Result<()> { } Subcommands::ConfigTree => show_progress(), Subcommands::Credential(cmd) => core::repository::credential( - repository(Mode::StrictWithGitInstallConfig)?, + repository(Mode::StrictWithGitInstallConfig).ok(), match cmd { credential::Subcommands::Fill => gix::credentials::program::main::Action::Get, credential::Subcommands::Approve => gix::credentials::program::main::Action::Store,