@@ -6,8 +6,8 @@ use std::sync::{LazyLock as Lazy, Once};
66use anyhow:: Context as ResultExt ;
77use curl:: easy:: Easy ;
88use 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} ;
1212use 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+
4757fn ensure_git_curl_transport_registered ( ) {
4858 static REGISTER : Once = Once :: new ( ) ;
4959
0 commit comments