send-pack: fix push.negotiate with remote helper
Commit 477673d6f3 ("send-pack: support push negotiation", 2021-05-05) introduced the push.negotiate config variable and included a test. The test only covered pushing without a remote helper, so the fact that pushing with a remote helper doesn't work went unnoticed. This is ultimately caused by the "url" field not being set in the args struct. This field being unset probably went unnoticed because besides push negotiation, this field is only used to generate a "pushee" line in a push cert (and if not given, no such line is generated). Therefore, set this field. Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jonathan Tan committed
Jul 15, 2021 at 10:44 UTC
74fab8ff54e6e6a30efa254b8b5322764d119386
2 files changed
+72
builtin/send-pack.c
+1
@@ -230,6 +230,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
230
args.atomic = atomic;
231
args.stateless_rpc = stateless_rpc;
232
args.push_options = push_options.nr ? &push_options : NULL;
233
+ args.url = dest;
234
235
if (from_stdin) {
236
if (args.stateless_rpc) {
t/t5549-fetch-push-http.sh
new
+71
@@ -0,0 +1,71 @@
1
+#!/bin/sh
2
+
3
+test_description='fetch/push functionality using the HTTP protocol'
4
+
5
+GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6
+export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
+
8
+. ./test-lib.sh
9
+. "$TEST_DIRECTORY"/lib-httpd.sh
10
+start_httpd
11
+
12
+SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server"
13
+URI="$HTTPD_URL/smart/server"
14
+
15
+grep_wrote () {
16
+ object_count=$1
17
+ file_name=$2
18
+ grep 'write_pack_file/wrote.*"value":"'$1'"' $2
19
+}
20
+
21
+setup_client_and_server () {
22
+ git init client &&
23
+ test_when_finished 'rm -rf client' &&
24
+ test_commit -C client first_commit &&
25
+ test_commit -C client second_commit &&
26
+
27
+ git init "$SERVER" &&
28
+ test_when_finished 'rm -rf "$SERVER"' &&
29
+ test_config -C "$SERVER" http.receivepack true &&
30
+ git -C client push "$URI" first_commit:refs/remotes/origin/first_commit &&
31
+ git -C "$SERVER" config receive.hideRefs refs/remotes/origin/first_commit
32
+}
33
+
34
+test_expect_success 'push without negotiation (for comparing object counts with the next test)' '
35
+ setup_client_and_server &&
36
+
37
+ GIT_TRACE2_EVENT="$(pwd)/event" git -C client -c protocol.version=2 \
38
+ push "$URI" refs/heads/main:refs/remotes/origin/main &&
39
+ test_when_finished "rm -f event" &&
40
+ grep_wrote 6 event # 2 commits, 2 trees, 2 blobs
41
+'
42
+
43
+test_expect_success 'push with negotiation' '
44
+ setup_client_and_server &&
45
+
46
+ GIT_TRACE2_EVENT="$(pwd)/event" git -C client -c protocol.version=2 -c push.negotiate=1 \
47
+ push "$URI" refs/heads/main:refs/remotes/origin/main &&
48
+ test_when_finished "rm -f event" &&
49
+ grep_wrote 3 event # 1 commit, 1 tree, 1 blob
50
+'
51
+
52
+test_expect_success 'push with negotiation proceeds anyway even if negotiation fails' '
53
+ setup_client_and_server &&
54
+
55
+ # Use protocol v0 to make negotiation fail (because protocol v0 does
56
+ # not support the "wait-for-done" capability, which is required for
57
+ # push negotiation)
58
+ GIT_TEST_PROTOCOL_VERSION=0 GIT_TRACE2_EVENT="$(pwd)/event" git -C client -c push.negotiate=1 \
59
+ push "$URI" refs/heads/main:refs/remotes/origin/main 2>err &&
60
+ test_when_finished "rm -f event" &&
61
+ grep_wrote 6 event && # 2 commits, 2 trees, 2 blobs
62
+
63
+ cat >warning-expect <<-EOF &&
64
+ warning: --negotiate-only requires protocol v2
65
+ warning: push negotiation failed; proceeding anyway with push
66
+EOF
67
+ grep warning: err >warning-actual &&
68
+ test_cmp warning-expect warning-actual
69
+'
70
+
71
+test_done