| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -884,15 +884,22 @@ static void url_config_trim(git_net_url *url) | |||
| 884 | 884 | ||
| 885 | 885 | static int http_proxy_config(char **out, git_remote *remote, git_net_url *url) | |
| 886 | 886 | { | |
| 887 | - git_config *cfg; | ||
| 887 | + git_config *cfg = NULL; | ||
| 888 | 888 | git_buf buf = GIT_BUF_INIT; | |
| 889 | 889 | git_net_url lookup_url = GIT_NET_URL_INIT; | |
| 890 | 890 | int error; | |
| 891 | 891 | ||
| 892 | - if ((error = git_net_url_dup(&lookup_url, url)) < 0 || | ||
| 893 | - (error = git_repository_config__weakptr(&cfg, remote->repo)) < 0) | ||
| 892 | + if ((error = git_net_url_dup(&lookup_url, url)) < 0) | ||
| 894 | 893 | goto done; | |
| 895 | 894 | ||
| 895 | + if (remote->repo) { | ||
| 896 | + if ((error = git_repository_config(&cfg, remote->repo)) < 0) | ||
| 897 | + goto done; | ||
| 898 | + } else { | ||
| 899 | + if ((error = git_config_open_default(&cfg)) < 0) | ||
| 900 | + goto done; | ||
| 901 | + } | ||
| 902 | + | ||
| 896 | 903 | /* remote.<name>.proxy config setting */ | |
| 897 | 904 | if (remote->name && remote->name[0]) { | |
| 898 | 905 | git_buf_clear(&buf); | |
@@ -922,6 +929,7 @@ static int http_proxy_config(char **out, git_remote *remote, git_net_url *url) | |||
| 922 | 929 | error = lookup_config(out, cfg, "http.proxy"); | |
| 923 | 930 | ||
| 924 | 931 | done: | |
| 932 | + git_config_free(cfg); | ||
| 925 | 933 | git_buf_dispose(&buf); | |
| 926 | 934 | git_net_url_dispose(&lookup_url); | |
| 927 | 935 | return error; | |
@@ -971,7 +979,6 @@ int git_remote__http_proxy(char **out, git_remote *remote, git_net_url *url) | |||
| 971 | 979 | ||
| 972 | 980 | GIT_ASSERT_ARG(out); | |
| 973 | 981 | GIT_ASSERT_ARG(remote); | |
| 974 | - GIT_ASSERT_ARG(remote->repo); | ||
| 975 | 982 | ||
| 976 | 983 | *out = NULL; | |
| 977 | 984 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,7 @@ | |||
| 1 | 1 | #include "clar_libgit2.h" | |
| 2 | - #include "remote.h" | ||
| 2 | + #include "futils.h" | ||
| 3 | 3 | #include "net.h" | |
| 4 | + #include "remote.h" | ||
| 4 | 5 | ||
| 5 | 6 | static git_repository *repo; | |
| 6 | 7 | static git_net_url url = GIT_NET_URL_INIT; | |
@@ -105,6 +106,45 @@ void test_remote_httpproxy__config_empty_overrides(void) | |||
| 105 | 106 | assert_config_match("remote.lg2.proxy", ""); | |
| 106 | 107 | } | |
| 107 | 108 | ||
| 109 | + void assert_global_config_match(const char *config, const char *expected) | ||
| 110 | + { | ||
| 111 | + git_remote *remote; | ||
| 112 | + char *proxy; | ||
| 113 | + git_config* cfg; | ||
| 114 | + | ||
| 115 | + if (config) { | ||
| 116 | + cl_git_pass(git_config_open_default(&cfg)); | ||
| 117 | + git_config_set_string(cfg, config, expected); | ||
| 118 | + git_config_free(cfg); | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + cl_git_pass(git_remote_create_detached(&remote, "https://github.com/libgit2/libgit2")); | ||
| 122 | + cl_git_pass(git_remote__http_proxy(&proxy, remote, &url)); | ||
| 123 | + | ||
| 124 | + if (expected) | ||
| 125 | + cl_assert_equal_s(proxy, expected); | ||
| 126 | + else | ||
| 127 | + cl_assert_equal_p(proxy, expected); | ||
| 128 | + | ||
| 129 | + git_remote_free(remote); | ||
| 130 | + git__free(proxy); | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + void test_remote_httpproxy__config_overrides_detached_remote(void) | ||
| 134 | + { | ||
| 135 | + cl_fake_home(); | ||
| 136 | + | ||
| 137 | + assert_global_config_match(NULL, NULL); | ||
| 138 | + assert_global_config_match("http.proxy", "http://localhost:1/"); | ||
| 139 | + assert_global_config_match("http.https://github.com.proxy", "http://localhost:2/"); | ||
| 140 | + assert_global_config_match("http.https://github.com/.proxy", "http://localhost:3/"); | ||
| 141 | + assert_global_config_match("http.https://github.com/libgit2.proxy", "http://localhost:4/"); | ||
| 142 | + assert_global_config_match("http.https://github.com/libgit2/.proxy", "http://localhost:5/"); | ||
| 143 | + assert_global_config_match("http.https://github.com/libgit2/libgit2.proxy", "http://localhost:6/"); | ||
| 144 | + | ||
| 145 | + cl_git_pass(git_futils_rmdir_r("home", NULL, GIT_RMDIR_REMOVE_FILES)); | ||
| 146 | + } | ||
| 147 | + | ||
| 108 | 148 | void test_remote_httpproxy__env(void) | |
| 109 | 149 | { | |
| 110 | 150 | orig_http_proxy = cl_getenv("HTTP_PROXY"); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments