gitoxide_core/repository/
credential.rs

1#[derive(Debug, thiserror::Error)]
2enum Error {
3    #[error(transparent)]
4    UrlParse(#[from] gix::url::parse::Error),
5    #[error(transparent)]
6    Configuration(#[from] gix::config::credential_helpers::Error),
7    #[error(transparent)]
8    Protocol(#[from] gix::credentials::protocol::Error),
9}
10
11pub fn function(repo: gix::Repository, action: gix::credentials::program::main::Action) -> anyhow::Result<()> {
12    use gix::credentials::program::main::Action::*;
13    gix::credentials::program::main(
14        Some(action.as_str().into()),
15        std::io::stdin(),
16        std::io::stdout(),
17        |action, context| -> Result<_, Error> {
18            let (mut cascade, _action, prompt_options) = repo.config_snapshot().credential_helpers(gix::url::parse(
19                context.url.as_ref().expect("framework assures URL is present").as_ref(),
20            )?)?;
21            cascade
22                .invoke(
23                    match action {
24                        Get => gix::credentials::helper::Action::Get(context),
25                        Erase => gix::credentials::helper::Action::Erase(context.to_bstring()),
26                        Store => gix::credentials::helper::Action::Store(context.to_bstring()),
27                    },
28                    prompt_options,
29                )
30                .map(|outcome| outcome.and_then(|outcome| (&outcome.next).try_into().ok()))
31                .map_err(Into::into)
32        },
33    )
34    .map_err(Into::into)
35}