summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurence McGlashan <laurence.mcglashan@gmail.com>2021-09-16 11:44:04 +0100
committerLaurence McGlashan <laurence.mcglashan@gmail.com>2021-09-16 11:44:04 +0100
commiteb41276fe08eeedd27509f69d9465cfbdd6cb7f7 (patch)
tree5079cd4216d7b7568edf5947be6e8a3199d01c29 /src
parent7d195b9c3ddffb9f9af94dcabaeb4fc77fafa378 (diff)
downloadlibgit2-eb41276fe08eeedd27509f69d9465cfbdd6cb7f7.tar.gz
Allow proxy options when connecting with a detached remote.
Diffstat (limited to 'src')
-rw-r--r--src/remote.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/remote.c b/src/remote.c
index 154300bd2..9f604c3be 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -888,11 +888,21 @@ static int http_proxy_config(char **out, git_remote *remote, git_net_url *url)
git_buf buf = GIT_BUF_INIT;
git_net_url lookup_url = GIT_NET_URL_INIT;
int error;
+ int cleanup_config = 0;
- if ((error = git_net_url_dup(&lookup_url, url)) < 0 ||
- (error = git_repository_config__weakptr(&cfg, remote->repo)) < 0)
+ if ((error = git_net_url_dup(&lookup_url, url)) < 0)
goto done;
+ if (remote->repo) {
+ if ((error = git_repository_config__weakptr(&cfg, remote->repo)) < 0)
+ goto done;
+ } else {
+ if ((error = git_config_open_default(&cfg)) < 0)
+ goto done;
+
+ cleanup_config = 1;
+ }
+
/* remote.<name>.proxy config setting */
if (remote->name && remote->name[0]) {
git_buf_clear(&buf);
@@ -922,6 +932,9 @@ static int http_proxy_config(char **out, git_remote *remote, git_net_url *url)
error = lookup_config(out, cfg, "http.proxy");
done:
+ if (cleanup_config)
+ git_config_free(cfg);
+
git_buf_dispose(&buf);
git_net_url_dispose(&lookup_url);
return error;
@@ -971,7 +984,6 @@ int git_remote__http_proxy(char **out, git_remote *remote, git_net_url *url)
GIT_ASSERT_ARG(out);
GIT_ASSERT_ARG(remote);
- GIT_ASSERT_ARG(remote->repo);
*out = NULL;