Skip to content

Commit a4ddbc3

Browse files
peffgitster
authored andcommitted
http-push: enable "proactive auth"
Before commit 986bbc0, git was proactive about asking for http passwords. It assumed that if you had a username in your URL, you would also want a password, and asked for it before making any http requests. However, this could interfere with the use of .netrc (see 986bbc0 for details). And it was also unnecessary, since the http fetching code had learned to recognize an HTTP 401 and prompt the user then. Furthermore, the proactive prompt could interfere with the usage of .netrc (see 986bbc0 for details). Unfortunately, the http push-over-DAV code never learned to recognize HTTP 401, and so was broken by this change. This patch does a quick fix of re-enabling the "proactive auth" strategy only for http-push, leaving the dumb http fetch and smart-http as-is. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0521710 commit a4ddbc3

File tree

6 files changed

+13
-6
lines changed

6 files changed

+13
-6
lines changed

http-fetch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ int main(int argc, const char **argv)
6767

6868
git_config(git_default_config, NULL);
6969

70-
http_init(NULL, url);
70+
http_init(NULL, url, 0);
7171
walker = get_http_walker(url);
7272
walker->get_tree = get_tree;
7373
walker->get_history = get_history;

http-push.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1820,7 +1820,7 @@ int main(int argc, char **argv)
18201820

18211821
memset(remote_dir_exists, -1, 256);
18221822

1823-
http_init(NULL, repo->url);
1823+
http_init(NULL, repo->url, 1);
18241824

18251825
#ifdef USE_CURL_MULTI
18261826
is_running_queue = 0;

http.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ static int curl_ftp_no_epsv;
4343
static const char *curl_http_proxy;
4444
static const char *curl_cookie_file;
4545
static char *user_name, *user_pass, *description;
46+
static int http_proactive_auth;
4647
static const char *user_agent;
4748

4849
#if LIBCURL_VERSION_NUM >= 0x071700
@@ -279,6 +280,9 @@ static CURL *get_curl_handle(void)
279280
curl_easy_setopt(result, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
280281
#endif
281282

283+
if (http_proactive_auth)
284+
init_curl_http_auth(result);
285+
282286
if (ssl_cert != NULL)
283287
curl_easy_setopt(result, CURLOPT_SSLCERT, ssl_cert);
284288
if (has_cert_password())
@@ -367,7 +371,7 @@ static void set_from_env(const char **var, const char *envname)
367371
*var = val;
368372
}
369373

370-
void http_init(struct remote *remote, const char *url)
374+
void http_init(struct remote *remote, const char *url, int proactive_auth)
371375
{
372376
char *low_speed_limit;
373377
char *low_speed_time;
@@ -378,6 +382,8 @@ void http_init(struct remote *remote, const char *url)
378382

379383
curl_global_init(CURL_GLOBAL_ALL);
380384

385+
http_proactive_auth = proactive_auth;
386+
381387
if (remote && remote->http_proxy)
382388
curl_http_proxy = xstrdup(remote->http_proxy);
383389

http.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ extern void add_fill_function(void *data, int (*fill)(void *));
8686
extern void step_active_slots(void);
8787
#endif
8888

89-
extern void http_init(struct remote *remote, const char *url);
89+
extern void http_init(struct remote *remote, const char *url,
90+
int proactive_auth);
9091
extern void http_cleanup(void);
9192

9293
extern int data_received;

remote-curl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ int main(int argc, const char **argv)
859859

860860
url = strbuf_detach(&buf, NULL);
861861

862-
http_init(remote, url);
862+
http_init(remote, url, 0);
863863

864864
do {
865865
if (strbuf_getline(&buf, stdin, '\n') == EOF) {

t/t5540-http-push.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ test_expect_success 'PUT and MOVE sends object to URLs with SHA-1 hash suffix' '
160160
test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
161161
"$ROOT_PATH"/test_repo_clone master
162162

163-
test_expect_failure 'push to password-protected repository (user in URL)' '
163+
test_expect_success 'push to password-protected repository (user in URL)' '
164164
test_commit pw-user &&
165165
git push "$HTTPD_URL_USER/auth/dumb/test_repo.git" HEAD &&
166166
git rev-parse --verify HEAD >expect &&

0 commit comments

Comments
 (0)