diff --git a/Cargo.lock b/Cargo.lock index 71ff426..c8508dc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1070,11 +1070,26 @@ checksum = "1c42fe03df2bd3c53a3a9c7317ad91d80c81cd1fb0caec8d7cc4cd2bfa10c222" dependencies = [ "cc", "libc", + "libssh2-sys", "libz-sys", "openssl-sys", "pkg-config", ] +[[package]] +name = "libssh2-sys" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "220e4f05ad4a218192533b300327f5150e809b54c4ec83b5a1d91833601811b9" +dependencies = [ + "cc", + "libc", + "libz-sys", + "openssl-sys", + "pkg-config", + "vcpkg", +] + [[package]] name = "libz-sys" version = "1.1.22" diff --git a/Cargo.toml b/Cargo.toml index d065816..cd71fad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ dialoguer = "^0.12.0" env_logger = "0.11.8" futures = "^0.3.31" futures-lite = "^2.6.1" -git2 = { version = "^0.20.2", default-features = false, features = ["https"]} +git2 = { version = "^0.20.2", default-features = false, features = ["https", "ssh"]} git2-ext = "^0.6.3" graphql_client = "^0.14.0" http = "1.3.1" @@ -33,3 +33,6 @@ serde = "^1.0.225" textwrap = "^0.16.2" tokio = { version = "^1.47.1", features = ["macros", "rt", "time"] } unicode-normalization = "^0.1.24" + +[lints.clippy] +used-underscore-binding = "deny" diff --git a/src/git_remote.rs b/src/git_remote.rs index c849f38..40f4c21 100644 --- a/src/git_remote.rs +++ b/src/git_remote.rs @@ -33,9 +33,21 @@ impl GitRemote { { let mut remote = self.repo.remote_anonymous(&self.url)?; let mut cb = git2::RemoteCallbacks::new(); - cb.credentials(move |_url, _username, _allowed_types| { - git2::Cred::userpass_plaintext("spr", &self.auth_token) + cb.credentials(move |url, username, allowed_types| { + debug!( + "remote callback: url={}, username={:?}, allowed={:?}", + url, username, allowed_types + ); + if allowed_types.is_ssh_custom() + || allowed_types.is_ssh_key() + || allowed_types.is_ssh_interactive() + { + git2::Cred::ssh_key_from_agent(username.unwrap()) + } else { + git2::Cred::userpass_plaintext("spr", &self.auth_token) + } }); + let mut connection = remote.connect_auth(dir, Some(cb), None).wrap_err_with(|| { format!("Connection to git remote failed, url: {}", &self.url)