Skip to content

Commit 53e855e

Browse files
author
Stephan Dilly
committed
use auto proxy option
1 parent bfba218 commit 53e855e

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

asyncgit/src/sync/remotes/mod.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::{
1313
ProgressPercent,
1414
};
1515
use crossbeam_channel::Sender;
16-
use git2::{BranchType, FetchOptions, Repository};
16+
use git2::{BranchType, FetchOptions, ProxyOptions, Repository};
1717
use scopetime::scope_time;
1818
use utils::bytes2string;
1919

@@ -25,6 +25,13 @@ use super::RepoPath;
2525
/// origin
2626
pub const DEFAULT_REMOTE_NAME: &str = "origin";
2727

28+
///
29+
pub fn proxy_auto<'a>() -> ProxyOptions<'a> {
30+
let mut proxy = ProxyOptions::new();
31+
proxy.auto();
32+
proxy
33+
}
34+
2835
///
2936
pub fn get_remotes(repo_path: &RepoPath) -> Result<Vec<String>> {
3037
scope_time!("get_remotes");
@@ -92,6 +99,7 @@ fn fetch_from_remote(
9299
let mut options = FetchOptions::new();
93100
let callbacks = Callbacks::new(progress_sender, basic_credential);
94101
options.prune(git2::FetchPrune::On);
102+
options.proxy_options(proxy_auto());
95103
options.download_tags(git2::AutotagOption::All);
96104
options.remote_callbacks(callbacks.callbacks());
97105
remote.fetch(&[] as &[&str], Some(&mut options), None)?;
@@ -161,6 +169,7 @@ pub(crate) fn fetch(
161169
options.download_tags(git2::AutotagOption::All);
162170
let callbacks = Callbacks::new(progress_sender, basic_credential);
163171
options.remote_callbacks(callbacks.callbacks());
172+
options.proxy_options(proxy_auto());
164173

165174
remote.fetch(&[branch], Some(&mut options), None)?;
166175

asyncgit/src/sync/remotes/push.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ use crate::{
22
error::{Error, Result},
33
progress::ProgressPercent,
44
sync::{
5-
branch::branch_set_upstream, cred::BasicAuthCredential,
6-
remotes::Callbacks, repository::repo, CommitId, RepoPath,
5+
branch::branch_set_upstream,
6+
cred::BasicAuthCredential,
7+
remotes::{proxy_auto, Callbacks},
8+
repository::repo,
9+
CommitId, RepoPath,
710
},
811
};
912
use crossbeam_channel::Sender;
@@ -143,6 +146,7 @@ pub fn push_raw(
143146
let mut remote = repo.find_remote(remote)?;
144147

145148
let mut options = PushOptions::new();
149+
options.proxy_options(proxy_auto());
146150

147151
let callbacks = Callbacks::new(progress_sender, basic_credential);
148152
options.remote_callbacks(callbacks.callbacks());

asyncgit/src/sync/remotes/tags.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ use crate::{
55
error::Result,
66
progress::ProgressPercent,
77
sync::{
8-
cred::BasicAuthCredential, remotes::Callbacks,
9-
repository::repo, RepoPath,
8+
cred::BasicAuthCredential,
9+
remotes::{proxy_auto, Callbacks},
10+
repository::repo,
11+
RepoPath,
1012
},
1113
};
1214
use crossbeam_channel::Sender;
@@ -59,7 +61,7 @@ fn remote_tag_refs(
5961
let conn = remote.connect_auth(
6062
Direction::Fetch,
6163
Some(callbacks.callbacks()),
62-
None,
64+
Some(proxy_auto()),
6365
)?;
6466

6567
let remote_heads = conn.list()?;
@@ -133,6 +135,7 @@ pub fn push_tags(
133135
Callbacks::new(None, basic_credential.clone());
134136
options.remote_callbacks(callbacks.callbacks());
135137
options.packbuilder_parallelism(0);
138+
options.proxy_options(proxy_auto());
136139
remote.push(&[tag.as_str()], Some(&mut options))?;
137140

138141
progress_sender.as_ref().map(|sender| {

0 commit comments

Comments
 (0)