Skip to content

Commit 924cd62

Browse files
ralphmodalesByron
authored andcommitted
feat: allow credential fill with gix credential fill to run without a repo (#2198)
1 parent 3c2b422 commit 924cd62

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

gitoxide-core/src/repository/credential.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ enum Error {
66
Configuration(#[from] gix::config::credential_helpers::Error),
77
#[error(transparent)]
88
Protocol(#[from] gix::credentials::protocol::Error),
9+
#[error(transparent)]
10+
ConfigLoad(#[from] gix::config::file::init::from_paths::Error),
911
}
1012

11-
pub fn function(repo: gix::Repository, action: gix::credentials::program::main::Action) -> anyhow::Result<()> {
13+
pub fn function(repo: Option<gix::Repository>, action: gix::credentials::program::main::Action) -> anyhow::Result<()> {
1214
use gix::credentials::program::main::Action::*;
1315
gix::credentials::program::main(
1416
Some(action.as_str().into()),
@@ -20,9 +22,24 @@ pub fn function(repo: gix::Repository, action: gix::credentials::program::main::
2022
.clone()
2123
.or_else(|| context.to_url())
2224
.ok_or(Error::Protocol(gix::credentials::protocol::Error::UrlMissing))?;
23-
let (mut cascade, _action, prompt_options) = repo
24-
.config_snapshot()
25-
.credential_helpers(gix::url::parse(url.as_ref())?)?;
25+
26+
let (mut cascade, _action, prompt_options) = match repo {
27+
Some(ref repo) => repo
28+
.config_snapshot()
29+
.credential_helpers(gix::url::parse(url.as_ref())?)?,
30+
None => {
31+
let config = gix::config::File::from_globals()?;
32+
let environment = gix::open::permissions::Environment::all();
33+
gix::config::credential_helpers(
34+
gix::url::parse(url.as_ref())?,
35+
&config,
36+
false,
37+
|_| true,
38+
environment,
39+
false,
40+
)?
41+
}
42+
};
2643
cascade
2744
.invoke(
2845
match action {

src/plumbing/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ pub fn main() -> Result<()> {
658658
}
659659
Subcommands::ConfigTree => show_progress(),
660660
Subcommands::Credential(cmd) => core::repository::credential(
661-
repository(Mode::StrictWithGitInstallConfig)?,
661+
repository(Mode::StrictWithGitInstallConfig).ok(),
662662
match cmd {
663663
credential::Subcommands::Fill => gix::credentials::program::main::Action::Get,
664664
credential::Subcommands::Approve => gix::credentials::program::main::Action::Store,

0 commit comments

Comments
 (0)