Merge branch 'ab/test-must-be-empty-for-master'
[git.git] / t / t5552-skipping-fetch-negotiator.sh
blob3b60bd44e0a925931bc0ccb7c0b67df4809a6773
1 #!/bin/sh
3 test_description='test skipping fetch negotiator'
4 . ./test-lib.sh
6 have_sent () {
7 while test "$#" -ne 0
8 do
9 grep "fetch> have $(git -C client rev-parse $1)" trace
10 if test $? -ne 0
11 then
12 echo "No have $(git -C client rev-parse $1) ($1)"
13 return 1
15 shift
16 done
19 have_not_sent () {
20 while test "$#" -ne 0
22 grep "fetch> have $(git -C client rev-parse $1)" trace
23 if test $? -eq 0
24 then
25 return 1
27 shift
28 done
31 test_expect_success 'commits with no parents are sent regardless of skip distance' '
32 git init server &&
33 test_commit -C server to_fetch &&
35 git init client &&
36 for i in $(seq 7)
38 test_commit -C client c$i
39 done &&
41 # We send: "c7" (skip 1) "c5" (skip 2) "c2" (skip 4). After that, since
42 # "c1" has no parent, it is still sent as "have" even though it would
43 # normally be skipped.
44 test_config -C client fetch.negotiationalgorithm skipping &&
45 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch "$(pwd)/server" &&
46 have_sent c7 c5 c2 c1 &&
47 have_not_sent c6 c4 c3
50 test_expect_success 'unknown fetch.negotiationAlgorithm values error out' '
51 rm -rf server client trace &&
52 git init server &&
53 test_commit -C server to_fetch &&
55 git init client &&
56 test_commit -C client on_client &&
57 git -C client checkout on_client &&
59 test_config -C client fetch.negotiationAlgorithm invalid &&
60 test_must_fail git -C client fetch "$(pwd)/server" 2>err &&
61 test_i18ngrep "unknown fetch negotiation algorithm" err &&
63 # Explicit "default" value
64 test_config -C client fetch.negotiationAlgorithm default &&
65 git -C client -c fetch.negotiationAlgorithm=default fetch "$(pwd)/server" &&
67 # Implementation detail: If there is nothing to fetch, we will not error out
68 test_config -C client fetch.negotiationAlgorithm invalid &&
69 git -C client fetch "$(pwd)/server" 2>err &&
70 test_i18ngrep ! "unknown fetch negotiation algorithm" err
73 test_expect_success 'when two skips collide, favor the larger one' '
74 rm -rf server client trace &&
75 git init server &&
76 test_commit -C server to_fetch &&
78 git init client &&
79 for i in $(seq 11)
81 test_commit -C client c$i
82 done &&
83 git -C client checkout c5 &&
84 test_commit -C client c5side &&
86 # Before reaching c5, we send "c5side" (skip 1) and "c11" (skip 1) "c9"
87 # (skip 2) "c6" (skip 4). The larger skip (skip 4) takes precedence, so
88 # the next "have" sent will be "c1" (from "c6" skip 4) and not "c4"
89 # (from "c5side" skip 1).
90 test_config -C client fetch.negotiationalgorithm skipping &&
91 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch "$(pwd)/server" &&
92 have_sent c5side c11 c9 c6 c1 &&
93 have_not_sent c10 c8 c7 c5 c4 c3 c2
96 test_expect_success 'use ref advertisement to filter out commits' '
97 rm -rf server client trace &&
98 git init server &&
99 test_commit -C server c1 &&
100 test_commit -C server c2 &&
101 test_commit -C server c3 &&
102 git -C server tag -d c1 c2 c3 &&
104 git clone server client &&
105 test_commit -C client c4 &&
106 test_commit -C client c5 &&
107 git -C client checkout c4^^ &&
108 test_commit -C client c2side &&
110 git -C server checkout --orphan anotherbranch &&
111 test_commit -C server to_fetch &&
113 # The server advertising "c3" (as "refs/heads/master") means that we do
114 # not need to send any ancestors of "c3", but we still need to send "c3"
115 # itself.
116 test_config -C client fetch.negotiationalgorithm skipping &&
117 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch origin to_fetch &&
118 have_sent c5 c4^ c2side &&
119 have_not_sent c4 c4^^ c4^^^
122 test_expect_success 'handle clock skew' '
123 rm -rf server client trace &&
124 git init server &&
125 test_commit -C server to_fetch &&
127 git init client &&
129 # 2 regular commits
130 test_tick=2000000000 &&
131 test_commit -C client c1 &&
132 test_commit -C client c2 &&
134 # 4 old commits
135 test_tick=1000000000 &&
136 git -C client checkout c1 &&
137 test_commit -C client old1 &&
138 test_commit -C client old2 &&
139 test_commit -C client old3 &&
140 test_commit -C client old4 &&
142 # "c2" and "c1" are popped first, then "old4" to "old1". "old1" would
143 # normally be skipped, but is treated as a commit without a parent here
144 # and sent, because (due to clock skew) its only parent has already been
145 # popped off the priority queue.
146 test_config -C client fetch.negotiationalgorithm skipping &&
147 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch "$(pwd)/server" &&
148 have_sent c2 c1 old4 old2 old1 &&
149 have_not_sent old3
152 test_expect_success 'do not send "have" with ancestors of commits that server ACKed' '
153 rm -rf server client trace &&
154 git init server &&
155 test_commit -C server to_fetch &&
157 git init client &&
158 for i in $(seq 8)
160 git -C client checkout --orphan b$i &&
161 test_commit -C client b$i.c0
162 done &&
163 for j in $(seq 19)
165 for i in $(seq 8)
167 git -C client checkout b$i &&
168 test_commit -C client b$i.c$j
169 done
170 done &&
172 # Copy this branch over to the server and add a commit on it so that it
173 # is reachable but not advertised.
174 git -C server fetch --no-tags "$(pwd)/client" b1:refs/heads/b1 &&
175 git -C server checkout b1 &&
176 test_commit -C server commit-on-b1 &&
178 test_config -C client fetch.negotiationalgorithm skipping &&
179 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch "$(pwd)/server" to_fetch &&
180 grep " fetch" trace &&
182 # fetch-pack sends 2 requests each containing 16 "have" lines before
183 # processing the first response. In these 2 requests, 4 commits from
184 # each branch are sent. Just check the first branch.
185 have_sent b1.c19 b1.c17 b1.c14 b1.c9 &&
186 have_not_sent b1.c18 b1.c16 b1.c15 b1.c13 b1.c12 b1.c11 b1.c10 &&
188 # While fetch-pack is processing the first response, it should read that
189 # the server ACKs b1.c19 and b1.c17.
190 grep "fetch< ACK $(git -C client rev-parse b1.c19) common" trace &&
191 grep "fetch< ACK $(git -C client rev-parse b1.c17) common" trace &&
193 # fetch-pack should thus not send any more commits in the b1 branch, but
194 # should still send the others (in this test, just check b2).
195 for i in $(seq 0 8)
197 have_not_sent b1.c$i
198 done &&
199 have_sent b2.c1 b2.c0
202 test_done