]>
Commit | Line | Data |
---|---|---|
74fab8ff JT |
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 && | |
54a03bc7 | 30 | test_commit -C "$SERVER" unrelated_commit && |
74fab8ff JT |
31 | git -C client push "$URI" first_commit:refs/remotes/origin/first_commit && |
32 | git -C "$SERVER" config receive.hideRefs refs/remotes/origin/first_commit | |
33 | } | |
34 | ||
35 | test_expect_success 'push without negotiation (for comparing object counts with the next test)' ' | |
36 | setup_client_and_server && | |
37 | ||
38 | GIT_TRACE2_EVENT="$(pwd)/event" git -C client -c protocol.version=2 \ | |
39 | push "$URI" refs/heads/main:refs/remotes/origin/main && | |
40 | test_when_finished "rm -f event" && | |
41 | grep_wrote 6 event # 2 commits, 2 trees, 2 blobs | |
42 | ' | |
43 | ||
44 | test_expect_success 'push with negotiation' ' | |
45 | setup_client_and_server && | |
46 | ||
47 | GIT_TRACE2_EVENT="$(pwd)/event" git -C client -c protocol.version=2 -c push.negotiate=1 \ | |
48 | push "$URI" refs/heads/main:refs/remotes/origin/main && | |
49 | test_when_finished "rm -f event" && | |
50 | grep_wrote 3 event # 1 commit, 1 tree, 1 blob | |
51 | ' | |
52 | ||
53 | test_expect_success 'push with negotiation proceeds anyway even if negotiation fails' ' | |
54 | setup_client_and_server && | |
55 | ||
56 | # Use protocol v0 to make negotiation fail (because protocol v0 does | |
57 | # not support the "wait-for-done" capability, which is required for | |
58 | # push negotiation) | |
59 | GIT_TEST_PROTOCOL_VERSION=0 GIT_TRACE2_EVENT="$(pwd)/event" git -C client -c push.negotiate=1 \ | |
60 | push "$URI" refs/heads/main:refs/remotes/origin/main 2>err && | |
61 | test_when_finished "rm -f event" && | |
62 | grep_wrote 6 event && # 2 commits, 2 trees, 2 blobs | |
63 | ||
64 | cat >warning-expect <<-EOF && | |
65 | warning: --negotiate-only requires protocol v2 | |
66 | warning: push negotiation failed; proceeding anyway with push | |
67 | EOF | |
68 | grep warning: err >warning-actual && | |
69 | test_cmp warning-expect warning-actual | |
70 | ' | |
71 | ||
72 | test_done |