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