Merge branch 'es/worktree-repair-copied' into cw/worktrees-relative
[git/gitster.git] / t / t5549-fetch-push-http.sh
blob6377fb6d99367820c9469bf73b98c4a5fb221569
1 #!/bin/sh
3 test_description='fetch/push functionality using the HTTP protocol'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
10 . "$TEST_DIRECTORY"/lib-httpd.sh
11 start_httpd
13 SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server"
14 URI="$HTTPD_URL/smart/server"
16 grep_wrote () {
17 object_count=$1
18 file_name=$2
19 grep 'write_pack_file/wrote.*"value":"'$1'"' $2
22 setup_client_and_server () {
23 git init client &&
24 test_when_finished 'rm -rf client' &&
25 test_commit -C client first_commit &&
26 test_commit -C client second_commit &&
28 git init "$SERVER" &&
29 test_when_finished 'rm -rf "$SERVER"' &&
30 test_config -C "$SERVER" http.receivepack true &&
31 test_commit -C "$SERVER" unrelated_commit &&
32 git -C client push "$URI" first_commit:refs/remotes/origin/first_commit &&
33 git -C "$SERVER" config receive.hideRefs refs/remotes/origin/first_commit
36 test_expect_success 'push without negotiation (for comparing object counts with the next test)' '
37 setup_client_and_server &&
39 GIT_TRACE2_EVENT="$(pwd)/event" git -C client -c protocol.version=2 \
40 push "$URI" refs/heads/main:refs/remotes/origin/main &&
41 test_when_finished "rm -f event" &&
42 grep_wrote 6 event # 2 commits, 2 trees, 2 blobs
45 test_expect_success 'push with negotiation' '
46 setup_client_and_server &&
48 GIT_TRACE2_EVENT="$(pwd)/event" git -C client -c protocol.version=2 -c push.negotiate=1 \
49 push "$URI" refs/heads/main:refs/remotes/origin/main &&
50 test_when_finished "rm -f event" &&
51 grep_wrote 3 event # 1 commit, 1 tree, 1 blob
54 test_expect_success 'push with negotiation proceeds anyway even if negotiation fails' '
55 setup_client_and_server &&
57 # Use protocol v0 to make negotiation fail (because protocol v0 does
58 # not support the "wait-for-done" capability, which is required for
59 # push negotiation)
60 GIT_TEST_PROTOCOL_VERSION=0 GIT_TRACE2_EVENT="$(pwd)/event" git -C client -c push.negotiate=1 \
61 push "$URI" refs/heads/main:refs/remotes/origin/main 2>err &&
62 test_when_finished "rm -f event" &&
63 grep_wrote 6 event && # 2 commits, 2 trees, 2 blobs
65 cat >warning-expect <<-EOF &&
66 warning: --negotiate-only requires protocol v2
67 warning: push negotiation failed; proceeding anyway with push
68 EOF
69 grep warning: err >warning-actual &&
70 test_cmp warning-expect warning-actual
73 test_done