Skip to content

Commit 1aa8dde

Browse files
bmwillgitster
authored andcommitted
connect: 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 40fc51e commit 1aa8dde

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

connect.c

+8
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,14 @@ struct child_process *git_connect(int fd[2], const char *url,
12181218
enum protocol protocol;
12191219
enum protocol_version version = get_protocol_version_config();
12201220

1221+
/*
1222+
* NEEDSWORK: If we are trying to use protocol v2 and we are planning
1223+
* to perform a push, then fallback to v0 since the client doesn't know
1224+
* how to push yet using v2.
1225+
*/
1226+
if (version == protocol_v2 && !strcmp("git-receive-pack", prog))
1227+
version = protocol_v0;
1228+
12211229
/* Without this we cannot rely on waitpid() to tell
12221230
* what happened to our children.
12231231
*/

t/t5702-protocol-v2.sh

+24
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,30 @@ test_expect_success 'pull with git:// using protocol v2' '
9595
grep "fetch< version 2" log
9696
'
9797

98+
test_expect_success 'push with git:// and a config of v2 does not request v2' '
99+
test_when_finished "rm -f log" &&
100+
101+
# Till v2 for push is designed, make sure that if a client has
102+
# protocol.version configured to use v2, that the client instead falls
103+
# back and uses v0.
104+
105+
test_commit -C daemon_child three &&
106+
107+
# Push to another branch, as the target repository has the
108+
# master branch checked out and we cannot push into it.
109+
GIT_TRACE_PACKET="$(pwd)/log" git -C daemon_child -c protocol.version=2 \
110+
push origin HEAD:client_branch &&
111+
112+
git -C daemon_child log -1 --format=%s >actual &&
113+
git -C "$daemon_parent" log -1 --format=%s client_branch >expect &&
114+
test_cmp expect actual &&
115+
116+
# Client requested to use protocol v2
117+
! grep "push> .*\\\0\\\0version=2\\\0$" log &&
118+
# Server responded using protocol v2
119+
! grep "push< version 2" log
120+
'
121+
98122
stop_git_daemon
99123

100124
# Test protocol v2 with 'file://' transport

0 commit comments

Comments
 (0)