@@ -816,7 +816,21 @@ static int http_request(const char *url, void *result, int target, int options)
816816 ret = HTTP_OK ;
817817 else if (missing_target (& results ))
818818 ret = HTTP_MISSING_TARGET ;
819- else
819+ else if (results .http_code == 401 ) {
820+ if (user_name ) {
821+ ret = HTTP_NOAUTH ;
822+ } else {
823+ /*
824+ * git_getpass is needed here because its very likely stdin/stdout are
825+ * pipes to our parent process. So we instead need to use /dev/tty,
826+ * but that is non-portable. Using git_getpass() can at least be stubbed
827+ * on other platforms with a different implementation if/when necessary.
828+ */
829+ user_name = xstrdup (git_getpass ("Username: " ));
830+ init_curl_http_auth (slot -> curl );
831+ ret = HTTP_REAUTH ;
832+ }
833+ } else
820834 ret = HTTP_ERROR ;
821835 } else {
822836 error ("Unable to start HTTP request for %s" , url );
@@ -832,7 +846,11 @@ static int http_request(const char *url, void *result, int target, int options)
832846
833847int http_get_strbuf (const char * url , struct strbuf * result , int options )
834848{
835- return http_request (url , result , HTTP_REQUEST_STRBUF , options );
849+ int http_ret = http_request (url , result , HTTP_REQUEST_STRBUF , options );
850+ if (http_ret == HTTP_REAUTH ) {
851+ http_ret = http_request (url , result , HTTP_REQUEST_STRBUF , options );
852+ }
853+ return http_ret ;
836854}
837855
838856/*
0 commit comments