Skip to content

Commit a4d78ce

Browse files
bmwillgitster
authored andcommitted
remote-curl: don't request v2 when pushing
In order to be able to ship protocol v2 with only supporting fetch, we need clients to not issue a request to use protocol v2 when pushing (since the client currently doesn't know how to push using protocol v2). This allows a client to have protocol v2 configured in `protocol.version` and take advantage of using v2 for fetch and falling back to using v0 when pushing while v2 for push is being designed. We could run into issues if we didn't fall back to protocol v2 when pushing right now. This is because currently a server will ignore a request to use v2 when contacting the 'receive-pack' endpoint and fall back to using v0, but when push v2 is rolled out to servers, the 'receive-pack' endpoint will start responding using v2. So we don't want to get into a state where a client is requesting to push with v2 before they actually know how to push using v2. Signed-off-by: Brandon Williams <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0f1dc53 commit a4d78ce

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

remote-curl.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ static struct discovery *discover_refs(const char *service, int for_push)
322322
struct discovery *last = last_discovery;
323323
int http_ret, maybe_smart = 0;
324324
struct http_get_options http_options;
325+
enum protocol_version version = get_protocol_version_config();
325326

326327
if (last && !strcmp(service, last->service))
327328
return last;
@@ -338,8 +339,16 @@ static struct discovery *discover_refs(const char *service, int for_push)
338339
strbuf_addf(&refs_url, "service=%s", service);
339340
}
340341

342+
/*
343+
* NEEDSWORK: If we are trying to use protocol v2 and we are planning
344+
* to perform a push, then fallback to v0 since the client doesn't know
345+
* how to push yet using v2.
346+
*/
347+
if (version == protocol_v2 && !strcmp("git-receive-pack", service))
348+
version = protocol_v0;
349+
341350
/* Add the extra Git-Protocol header */
342-
if (get_protocol_http_header(get_protocol_version_config(), &protocol_header))
351+
if (get_protocol_http_header(version, &protocol_header))
343352
string_list_append(&extra_headers, protocol_header.buf);
344353

345354
memset(&http_options, 0, sizeof(http_options));

t/t5702-protocol-v2.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,30 @@ test_expect_success 'fetch with http:// using protocol v2' '
244244
grep "git< version 2" log
245245
'
246246

247+
test_expect_success 'push with http:// and a config of v2 does not request v2' '
248+
test_when_finished "rm -f log" &&
249+
# Till v2 for push is designed, make sure that if a client has
250+
# protocol.version configured to use v2, that the client instead falls
251+
# back and uses v0.
252+
253+
test_commit -C http_child three &&
254+
255+
# Push to another branch, as the target repository has the
256+
# master branch checked out and we cannot push into it.
257+
GIT_TRACE_PACKET="$(pwd)/log" git -C http_child -c protocol.version=2 \
258+
push origin HEAD:client_branch &&
259+
260+
git -C http_child log -1 --format=%s >actual &&
261+
git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" log -1 --format=%s client_branch >expect &&
262+
test_cmp expect actual &&
263+
264+
# Client didnt request to use protocol v2
265+
! grep "Git-Protocol: version=2" log &&
266+
# Server didnt respond using protocol v2
267+
! grep "git< version 2" log
268+
'
269+
270+
247271
stop_httpd
248272

249273
test_done

0 commit comments

Comments
 (0)