Skip to content

Commit e586e7d

Browse files
steadmongitster
authored andcommitted
remote-curl: die on server-side errors
When a smart HTTP server sends an error message via pkt-line, remote-curl will fail to detect the error (which usually results in incorrectly falling back to dumb-HTTP mode). This patch adds a check in check_smart_http() for server-side error messages, as well as a test case for this issue. Signed-off-by: Josh Steadmon <steadmon@google.com> Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 240fb9b commit e586e7d

5 files changed

Lines changed: 16 additions & 0 deletions

File tree

remote-curl.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,9 @@ static void check_smart_http(struct discovery *d, const char *service,
382382
*/
383383
d->proto_git = 1;
384384

385+
} else if (skip_prefix(line, "ERR ", &p)) {
386+
die(_("remote error: %s"), p);
387+
385388
} else {
386389
die("invalid server response; got '%s'", line);
387390
}

t/lib-httpd.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ prepare_httpd() {
131131
mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH"
132132
cp "$TEST_PATH"/passwd "$HTTPD_ROOT_PATH"
133133
install_script broken-smart-http.sh
134+
install_script error-smart-http.sh
134135
install_script error.sh
135136
install_script apply-one-time-sed.sh
136137

t/lib-httpd/apache.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ Alias /auth/dumb/ www/auth/dumb/
117117
</LocationMatch>
118118
ScriptAliasMatch /smart_*[^/]*/(.*) ${GIT_EXEC_PATH}/git-http-backend/$1
119119
ScriptAlias /broken_smart/ broken-smart-http.sh/
120+
ScriptAlias /error_smart/ error-smart-http.sh/
120121
ScriptAlias /error/ error.sh/
121122
ScriptAliasMatch /one_time_sed/(.*) apply-one-time-sed.sh/$1
122123
<Directory ${GIT_EXEC_PATH}>
@@ -125,6 +126,9 @@ ScriptAliasMatch /one_time_sed/(.*) apply-one-time-sed.sh/$1
125126
<Files broken-smart-http.sh>
126127
Options ExecCGI
127128
</Files>
129+
<Files error-smart-http.sh>
130+
Options ExecCGI
131+
</Files>
128132
<Files error.sh>
129133
Options ExecCGI
130134
</Files>

t/lib-httpd/error-smart-http.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
echo "Content-Type: application/x-git-upload-pack-advertisement"
2+
echo
3+
printf "%s" "0019ERR server-side error"

t/t5551-http-fetch-smart.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,5 +429,10 @@ test_expect_success 'GIT_TRACE_CURL_NO_DATA prevents data from being traced' '
429429
! grep "=> Send data" err
430430
'
431431

432+
test_expect_success 'server-side error detected' '
433+
test_must_fail git clone $HTTPD_URL/error_smart/repo.git 2>actual &&
434+
grep "server-side error" actual
435+
'
436+
432437
stop_httpd
433438
test_done

0 commit comments

Comments
 (0)