From 4f130dd015a275c6ae0eebd5692f8777820549a7 Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Fri, 17 Feb 2023 11:53:34 +0100 Subject: GitRepoRemote: Correctly honor proxy settings in fetch and commit update --- src/other_tools/git_operations/git_repo_remote.cpp | 36 +++++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) (limited to 'src/other_tools/git_operations/git_repo_remote.cpp') 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 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 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) { -- cgit v1.2.3