Skip to content

Commit 01188bf

Browse files
committed
fix: prefer proxy url in .gitconfig
git2_curl seems only automatically get the proxy url from http_proxy/https_proxy environment variables add a manual url fetch from the config file
1 parent 9ee8c5f commit 01188bf

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/util/git.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use std::sync::{LazyLock as Lazy, Once};
66
use anyhow::Context as ResultExt;
77
use curl::easy::Easy;
88
use git2::{
9-
BranchType, Cred, CredentialType, Error, FetchOptions, Oid, RemoteCallbacks, Repository,
10-
ResetType, SubmoduleUpdateOptions,
9+
BranchType, Config, Cred, CredentialType, Error, FetchOptions, Oid, RemoteCallbacks,
10+
Repository, ResetType, SubmoduleUpdateOptions,
1111
};
1212
use url::Url;
1313

@@ -33,17 +33,27 @@ where
3333
))
3434
});
3535

36-
// Try to auto-detect the proxy from the git configuration so that
37-
// Sheldon can be used behind a proxy.
36+
// Prefer proxies set in Git config, then fallback to auto detection that will use environment variables.
3837
let mut proxy_opts = git2::ProxyOptions::new();
39-
proxy_opts.auto();
38+
if let Some(proxy_url) = proxy_url_from_git_config() {
39+
proxy_opts.url(&proxy_url);
40+
} else {
41+
proxy_opts.auto();
42+
}
4043

4144
let mut opts = FetchOptions::new();
4245
opts.remote_callbacks(rcb);
4346
opts.proxy_options(proxy_opts);
4447
f(opts)
4548
}
4649

50+
fn proxy_url_from_git_config() -> Option<String> {
51+
let cfg = Config::open_default().ok()?;
52+
53+
// Use the standard git http.proxy setting.
54+
cfg.get_string("http.proxy").ok()
55+
}
56+
4757
fn ensure_git_curl_transport_registered() {
4858
static REGISTER: Once = Once::new();
4959

0 commit comments

Comments
 (0)