From 924cd62f7ef74f479114c80cee0db0ba5f522579 Mon Sep 17 00:00:00 2001 From: ralphmodales Date: Tue, 11 Nov 2025 03:54:24 +0800 Subject: [PATCH 1/2] feat: allow credential fill with `gix credential fill` to run without a repo (#2198) --- gitoxide-core/src/repository/credential.rs | 25 ++++++++++++++++++---- src/plumbing/main.rs | 2 +- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/gitoxide-core/src/repository/credential.rs b/gitoxide-core/src/repository/credential.rs index 9684250bd4d..a5648b3d8e0 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, + |_| true, + environment, + false, + )? + } + }; 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, From 41b4a8f74a2310d5c8c02918dc6e842e33eac0e5 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 11 Nov 2025 04:55:30 +0100 Subject: [PATCH 2/2] refactor --- gitoxide-core/src/repository/credential.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gitoxide-core/src/repository/credential.rs b/gitoxide-core/src/repository/credential.rs index a5648b3d8e0..451e453b7c9 100644 --- a/gitoxide-core/src/repository/credential.rs +++ b/gitoxide-core/src/repository/credential.rs @@ -33,10 +33,10 @@ pub fn function(repo: Option, action: gix::credentials::program gix::config::credential_helpers( gix::url::parse(url.as_ref())?, &config, - false, - |_| true, + false, /* lenient config */ + |_| true, /* section filter */ environment, - false, + false, /* use http path (override, uses configuration now)*/ )? } };