diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2023-02-17 11:53:34 +0100 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2023-03-03 16:21:17 +0100 |
commit | 4f130dd015a275c6ae0eebd5692f8777820549a7 (patch) | |
tree | 162c0fe2aca62aa6cd042070f0093a7e9c2a03d8 /src | |
parent | 66a6e5186ffd12679b8c3ca6980e11efd74d2f00 (diff) | |
download | justbuild-4f130dd015a275c6ae0eebd5692f8777820549a7.tar.gz |
GitRepoRemote: Correctly honor proxy settings in fetch and commit update
Diffstat (limited to 'src')
-rw-r--r-- | src/other_tools/git_operations/git_repo_remote.cpp | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/src/other_tools/git_operations/git_repo_remote.cpp b/src/other_tools/git_operations/git_repo_remote.cpp index f599c108..557d381b 100644 --- a/src/other_tools/git_operations/git_repo_remote.cpp +++ b/src/other_tools/git_operations/git_repo_remote.cpp @@ -175,8 +175,22 @@ auto GitRepoRemote::GetCommitFromRemote(std::shared_ptr<git_config> cfg, git_proxy_options proxy_opts{}; git_proxy_options_init(&proxy_opts, GIT_PROXY_OPTIONS_VERSION); - // set the option to auto-detect proxy settings - proxy_opts.type = GIT_PROXY_AUTO; + // set the proxy information + auto proxy_info = + GitConfigSettings::GetProxySettings(cfg, canonical_url, logger); + if (not proxy_info) { + // error occurred while handling the url + return std::nullopt; + } + if (proxy_info.value()) { + // found proxy + proxy_opts.type = GIT_PROXY_SPECIFIED; + proxy_opts.url = proxy_info.value().value().c_str(); + } + else { + // no proxy + proxy_opts.type = GIT_PROXY_NONE; + } if (git_remote_connect(remote.get(), GIT_DIRECTION_FETCH, @@ -283,8 +297,22 @@ auto GitRepoRemote::FetchFromRemote(std::shared_ptr<git_config> cfg, git_fetch_options fetch_opts{}; git_fetch_options_init(&fetch_opts, GIT_FETCH_OPTIONS_VERSION); - // set the option to auto-detect proxy settings - fetch_opts.proxy_opts.type = GIT_PROXY_AUTO; + // set the proxy information + auto proxy_info = + GitConfigSettings::GetProxySettings(cfg, canonical_url, logger); + if (not proxy_info) { + // error occurred while handling the url + return false; + } + if (proxy_info.value()) { + // found proxy + fetch_opts.proxy_opts.type = GIT_PROXY_SPECIFIED; + fetch_opts.proxy_opts.url = proxy_info.value().value().c_str(); + } + else { + // no proxy + fetch_opts.proxy_opts.type = GIT_PROXY_NONE; + } // set custom SSL verification callback; use canonicalized url if (not cfg) { |