From 552b3a6aadeddfda0ae772e7367c1b1e1030986a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20K=C3=B6rber?= Date: Thu, 23 Dec 2021 18:33:14 +0100 Subject: [PATCH] SSH: Fall back to ~/.ssh/id_rsa when no agent available --- src/repo.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/repo.rs b/src/repo.rs index 682ae9d..cba2011 100644 --- a/src/repo.rs +++ b/src/repo.rs @@ -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();