workon/
get_remote_callbacks.rs1use git2::{Config, RemoteCallbacks};
2use git2_credentials::CredentialHandler;
3
4use crate::error::Result;
5use crate::ssh_config::apply_identity_agent;
6
7pub fn get_remote_callbacks<'a>(url: Option<&str>) -> Result<RemoteCallbacks<'a>> {
17 if let Some(url) = url {
18 apply_identity_agent(url);
19 }
20
21 let mut callbacks = RemoteCallbacks::new();
22 let git_config = Config::open_default()?;
23 let mut credential_handler = CredentialHandler::new(git_config);
24
25 callbacks.credentials(move |url, username, allowed| {
26 credential_handler.try_next_credential(url, username, allowed)
27 });
28 Ok(callbacks)
29}