Skip to content

Commit 8e07784

Browse files
committed
Use repository configuration for calling credential helper (#450)
1 parent b978619 commit 8e07784

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

Cargo.lock

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gitoxide-core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ git-config = { version = "^0.7.1", path = "../git-config" }
4444
git-features = { version = "^0.22.4", path = "../git-features" }
4545
serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"] }
4646
anyhow = "1.0.42"
47+
thiserror = "1.0.34"
4748
quick-error = "2.0.0"
4849
bytesize = "1.0.1"
4950
serde_json = { version = "1.0.65", optional = true }

gitoxide-core/src/repository/credential.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,37 @@
11
use git_repository as git;
22
use std::convert::TryInto;
33

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<()> {
615
use git::credentials::program::main::Action::*;
716
git::credentials::program::main(
817
Some(action.as_str().into()),
918
std::io::stdin(),
1019
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
1325
.invoke(
1426
match action {
1527
Get => git::credentials::helper::Action::Get(context),
1628
Erase => git::credentials::helper::Action::Erase(context.to_bstring()),
1729
Store => git::credentials::helper::Action::Store(context.to_bstring()),
1830
},
19-
git::prompt::Options::default().apply_environment(true, true, true),
31+
prompt_options,
2032
)
2133
.map(|outcome| outcome.and_then(|outcome| (&outcome.next).try_into().ok()))
34+
.map_err(Into::into)
2235
},
2336
)
2437
.map_err(Into::into)

0 commit comments

Comments
 (0)