From f609ed6e45bb870c2b855ff6e0d4b4d7f36e7bd0 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Fri, 26 Jul 2024 13:38:48 +0100 Subject: fix(remote): authenticate pushes in the future we could implement our own credentials callback function to remove the dependancy --- Cargo.lock | 31 +++++++++++++++++++++++++++++++ Cargo.toml | 1 + src/git_remote_helper.rs | 5 +++-- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d014782..7622dd0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -372,6 +372,17 @@ version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" +[[package]] +name = "auth-git2" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51bd0e4592409df8631ca807716dc1e5caafae5d01ce0157c966c71c7e49c3c" +dependencies = [ + "dirs", + "git2", + "terminal-prompt", +] + [[package]] name = "autocfg" version = "1.2.0" @@ -813,6 +824,15 @@ dependencies = [ "dirs-sys", ] +[[package]] +name = "dirs" +version = "5.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" +dependencies = [ + "dirs-sys", +] + [[package]] name = "dirs-sys" version = "0.4.1" @@ -1747,6 +1767,7 @@ dependencies = [ "anyhow", "assert_cmd", "async-trait", + "auth-git2", "chacha20poly1305", "clap", "console", @@ -3040,6 +3061,16 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "terminal-prompt" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "572818b3472910acbd5dff46a3413715c18e934b071ab2ba464a7b2c2af16376" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "termtree" version = "0.4.1" diff --git a/Cargo.toml b/Cargo.toml index 2ece265..fe0d74a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,7 @@ categories = ["command-line-utilities","git"] [dependencies] anyhow = "1.0.75" async-trait = "0.1.73" +auth-git2 = "0.5.4" chacha20poly1305 = "0.10.1" clap = { version = "4.3.19", features = ["derive"] } console = "0.15.7" diff --git a/src/git_remote_helper.rs b/src/git_remote_helper.rs index 6050d1a..2899fec 100644 --- a/src/git_remote_helper.rs +++ b/src/git_remote_helper.rs @@ -13,6 +13,7 @@ use std::{ }; use anyhow::{bail, Context, Result}; +use auth_git2::GitAuthenticator; #[cfg(not(test))] use client::Connect; use client::{fetching_with_report, get_repo_ref_from_cache}; @@ -97,8 +98,8 @@ async fn main() -> Result<()> { println!(); } ["push", refspec] => { - temp_remote.connect(git2::Direction::Push)?; - temp_remote.push(&[refspec], None)?; + let auth = GitAuthenticator::default(); + auth.push(&git_repo.git_repo, &mut temp_remote, &[refspec])?; temp_remote.disconnect()?; println!(); } -- cgit v1.2.3