]> git.ipfire.org Git - thirdparty/git.git/commitdiff
connect: don't request v2 when pushing
authorBrandon Williams <bmwill@google.com>
Thu, 15 Mar 2018 17:31:31 +0000 (10:31 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 15 Mar 2018 19:01:09 +0000 (12:01 -0700)
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 <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
connect.c
t/t5702-protocol-v2.sh

index a57a060dc456771ac3f59997118f35933a324eb3..54971166ac4ba6646ea52051f8131dc16ea2e0ae 100644 (file)
--- a/connect.c
+++ b/connect.c
@@ -1218,6 +1218,14 @@ struct child_process *git_connect(int fd[2], const char *url,
        enum protocol protocol;
        enum protocol_version version = get_protocol_version_config();
 
+       /*
+        * NEEDSWORK: If we are trying to use protocol v2 and we are planning
+        * to perform a push, then fallback to v0 since the client doesn't know
+        * how to push yet using v2.
+        */
+       if (version == protocol_v2 && !strcmp("git-receive-pack", prog))
+               version = protocol_v0;
+
        /* Without this we cannot rely on waitpid() to tell
         * what happened to our children.
         */
index 4365ac2736b70d8c9a5b9e25f4dfd52b4fe42d19..e3a7c09d4ad872f7f9bf53aeed5f8ba4e3bc2d12 100755 (executable)
@@ -95,6 +95,30 @@ test_expect_success 'pull with git:// using protocol v2' '
        grep "fetch< version 2" log
 '
 
+test_expect_success 'push with git:// and a config of v2 does not request v2' '
+       test_when_finished "rm -f log" &&
+
+       # Till v2 for push is designed, make sure that if a client has
+       # protocol.version configured to use v2, that the client instead falls
+       # back and uses v0.
+
+       test_commit -C daemon_child three &&
+
+       # Push to another branch, as the target repository has the
+       # master branch checked out and we cannot push into it.
+       GIT_TRACE_PACKET="$(pwd)/log" git -C daemon_child -c protocol.version=2 \
+               push origin HEAD:client_branch &&
+
+       git -C daemon_child log -1 --format=%s >actual &&
+       git -C "$daemon_parent" log -1 --format=%s client_branch >expect &&
+       test_cmp expect actual &&
+
+       # Client requested to use protocol v2
+       ! grep "push> .*\\\0\\\0version=2\\\0$" log &&
+       # Server responded using protocol v2
+       ! grep "push< version 2" log
+'
+
 stop_git_daemon
 
 # Test protocol v2 with 'file://' transport