SSH: Fall back to ~/.ssh/id_rsa when no agent available

This commit is contained in:
2021-12-23 18:33:14 +01:00
parent fcc22791e5
commit 552b3a6aad

View File

@@ -1007,7 +1007,16 @@ impl RemoteHandle<'_> {
Ok(())
});
callbacks.credentials(|_url, username_from_url, _allowed_types| {
git2::Cred::ssh_key_from_agent(username_from_url.unwrap())
let username = match username_from_url {
Some(username) => username,
None => panic!("Could not get username. This is a bug"),
};
git2::Cred::ssh_key_from_agent(username).or_else(|_| git2::Cred::ssh_key(
username,
None,
&crate::env_home().join(".ssh/id_rsa"),
None,
))
});
let mut push_options = git2::PushOptions::new();