diff --git a/asyncgit/src/sync/remotes/mod.rs b/asyncgit/src/sync/remotes/mod.rs index d79a1da5..c241f235 100644 --- a/asyncgit/src/sync/remotes/mod.rs +++ b/asyncgit/src/sync/remotes/mod.rs @@ -13,7 +13,7 @@ use crate::{ ProgressPercent, }; use crossbeam_channel::Sender; -use git2::{BranchType, FetchOptions, Repository}; +use git2::{BranchType, FetchOptions, ProxyOptions, Repository}; use scopetime::scope_time; use utils::bytes2string; @@ -25,6 +25,13 @@ use super::RepoPath; /// origin pub const DEFAULT_REMOTE_NAME: &str = "origin"; +/// +pub fn proxy_auto<'a>() -> ProxyOptions<'a> { + let mut proxy = ProxyOptions::new(); + proxy.auto(); + proxy +} + /// pub fn get_remotes(repo_path: &RepoPath) -> Result> { scope_time!("get_remotes"); @@ -92,6 +99,7 @@ fn fetch_from_remote( let mut options = FetchOptions::new(); let callbacks = Callbacks::new(progress_sender, basic_credential); options.prune(git2::FetchPrune::On); + options.proxy_options(proxy_auto()); options.download_tags(git2::AutotagOption::All); options.remote_callbacks(callbacks.callbacks()); remote.fetch(&[] as &[&str], Some(&mut options), None)?; @@ -161,6 +169,7 @@ pub(crate) fn fetch( options.download_tags(git2::AutotagOption::All); let callbacks = Callbacks::new(progress_sender, basic_credential); options.remote_callbacks(callbacks.callbacks()); + options.proxy_options(proxy_auto()); remote.fetch(&[branch], Some(&mut options), None)?; diff --git a/asyncgit/src/sync/remotes/push.rs b/asyncgit/src/sync/remotes/push.rs index 7559adeb..12413526 100644 --- a/asyncgit/src/sync/remotes/push.rs +++ b/asyncgit/src/sync/remotes/push.rs @@ -2,8 +2,11 @@ use crate::{ error::{Error, Result}, progress::ProgressPercent, sync::{ - branch::branch_set_upstream, cred::BasicAuthCredential, - remotes::Callbacks, repository::repo, CommitId, RepoPath, + branch::branch_set_upstream, + cred::BasicAuthCredential, + remotes::{proxy_auto, Callbacks}, + repository::repo, + CommitId, RepoPath, }, }; use crossbeam_channel::Sender; @@ -143,6 +146,7 @@ pub fn push_raw( let mut remote = repo.find_remote(remote)?; let mut options = PushOptions::new(); + options.proxy_options(proxy_auto()); let callbacks = Callbacks::new(progress_sender, basic_credential); options.remote_callbacks(callbacks.callbacks()); diff --git a/asyncgit/src/sync/remotes/tags.rs b/asyncgit/src/sync/remotes/tags.rs index 61f89dfd..7c7ffddf 100644 --- a/asyncgit/src/sync/remotes/tags.rs +++ b/asyncgit/src/sync/remotes/tags.rs @@ -5,8 +5,10 @@ use crate::{ error::Result, progress::ProgressPercent, sync::{ - cred::BasicAuthCredential, remotes::Callbacks, - repository::repo, RepoPath, + cred::BasicAuthCredential, + remotes::{proxy_auto, Callbacks}, + repository::repo, + RepoPath, }, }; use crossbeam_channel::Sender; @@ -59,7 +61,7 @@ fn remote_tag_refs( let conn = remote.connect_auth( Direction::Fetch, Some(callbacks.callbacks()), - None, + Some(proxy_auto()), )?; let remote_heads = conn.list()?; @@ -133,6 +135,7 @@ pub fn push_tags( Callbacks::new(None, basic_credential.clone()); options.remote_callbacks(callbacks.callbacks()); options.packbuilder_parallelism(0); + options.proxy_options(proxy_auto()); remote.push(&[tag.as_str()], Some(&mut options))?; progress_sender.as_ref().map(|sender| {