3 test_description='test skipping fetch negotiator'
9 grep "fetch> have $(git -C client rev-parse $1)" trace
12 echo "No have $(git -C client rev-parse $1) ($1)"
22 grep "fetch> have $(git -C client rev-parse $1)" trace
31 # trace_fetch <client_dir> <server_dir> [args]
33 # Trace the packet output of fetch, but make sure we disable the variable
34 # in the child upload-pack, so we don't combine the results in the same file.
38 GIT_TRACE_PACKET="$(pwd)/trace" \
39 git -C "$client" fetch \
40 --upload-pack 'unset GIT_TRACE_PACKET; git-upload-pack' \
44 test_expect_success 'commits with no parents are sent regardless of skip distance' '
46 test_commit -C server to_fetch &&
51 test_commit -C client c$i
54 # We send: "c7" (skip 1) "c5" (skip 2) "c2" (skip 4). After that, since
55 # "c1" has no parent, it is still sent as "have" even though it would
56 # normally be skipped.
57 test_config -C client fetch.negotiationalgorithm skipping &&
58 trace_fetch client "$(pwd)/server" &&
59 have_sent c7 c5 c2 c1 &&
60 have_not_sent c6 c4 c3
63 test_expect_success 'unknown fetch.negotiationAlgorithm values error out' '
64 rm -rf server client trace &&
66 test_commit -C server to_fetch &&
69 test_commit -C client on_client &&
70 git -C client checkout on_client &&
72 test_config -C client fetch.negotiationAlgorithm invalid &&
73 test_must_fail git -C client fetch "$(pwd)/server" 2>err &&
74 test_i18ngrep "unknown fetch negotiation algorithm" err &&
76 # Explicit "default" value
77 test_config -C client fetch.negotiationAlgorithm default &&
78 git -C client -c fetch.negotiationAlgorithm=default fetch "$(pwd)/server" &&
80 # Implementation detail: If there is nothing to fetch, we will not error out
81 test_config -C client fetch.negotiationAlgorithm invalid &&
82 git -C client fetch "$(pwd)/server" 2>err &&
83 test_i18ngrep ! "unknown fetch negotiation algorithm" err
86 test_expect_success 'when two skips collide, favor the larger one' '
87 rm -rf server client trace &&
89 test_commit -C server to_fetch &&
94 test_commit -C client c$i
96 git -C client checkout c5 &&
97 test_commit -C client c5side &&
99 # Before reaching c5, we send "c5side" (skip 1) and "c11" (skip 1) "c9"
100 # (skip 2) "c6" (skip 4). The larger skip (skip 4) takes precedence, so
101 # the next "have" sent will be "c1" (from "c6" skip 4) and not "c4"
102 # (from "c5side" skip 1).
103 test_config -C client fetch.negotiationalgorithm skipping &&
104 trace_fetch client "$(pwd)/server" &&
105 have_sent c5side c11 c9 c6 c1 &&
106 have_not_sent c10 c8 c7 c5 c4 c3 c2
109 test_expect_success 'use ref advertisement to filter out commits' '
110 rm -rf server client trace &&
112 test_commit -C server c1 &&
113 test_commit -C server c2 &&
114 test_commit -C server c3 &&
115 git -C server tag -d c1 c2 c3 &&
117 git clone server client &&
118 test_commit -C client c4 &&
119 test_commit -C client c5 &&
120 git -C client checkout c4^^ &&
121 test_commit -C client c2side &&
123 git -C server checkout --orphan anotherbranch &&
124 test_commit -C server to_fetch &&
126 # The server advertising "c3" (as "refs/heads/master") means that we do
127 # not need to send any ancestors of "c3", but we still need to send "c3"
129 test_config -C client fetch.negotiationalgorithm skipping &&
130 trace_fetch client origin to_fetch &&
131 have_sent c5 c4^ c2side &&
132 have_not_sent c4 c4^^ c4^^^
135 test_expect_success 'handle clock skew' '
136 rm -rf server client trace &&
138 test_commit -C server to_fetch &&
143 test_tick=2000000000 &&
144 test_commit -C client c1 &&
145 test_commit -C client c2 &&
148 test_tick=1000000000 &&
149 git -C client checkout c1 &&
150 test_commit -C client old1 &&
151 test_commit -C client old2 &&
152 test_commit -C client old3 &&
153 test_commit -C client old4 &&
155 # "c2" and "c1" are popped first, then "old4" to "old1". "old1" would
156 # normally be skipped, but is treated as a commit without a parent here
157 # and sent, because (due to clock skew) its only parent has already been
158 # popped off the priority queue.
159 test_config -C client fetch.negotiationalgorithm skipping &&
160 trace_fetch client "$(pwd)/server" &&
161 have_sent c2 c1 old4 old2 old1 &&
165 test_expect_success 'do not send "have" with ancestors of commits that server ACKed' '
166 rm -rf server client trace &&
168 test_commit -C server to_fetch &&
173 git -C client checkout --orphan b$i &&
174 test_commit -C client b$i.c0
180 git -C client checkout b$i &&
181 test_commit -C client b$i.c$j
185 # Copy this branch over to the server and add a commit on it so that it
186 # is reachable but not advertised.
187 git -C server fetch --no-tags "$(pwd)/client" b1:refs/heads/b1 &&
188 git -C server checkout b1 &&
189 test_commit -C server commit-on-b1 &&
191 test_config -C client fetch.negotiationalgorithm skipping &&
192 trace_fetch client "$(pwd)/server" to_fetch &&
193 grep " fetch" trace &&
195 # fetch-pack sends 2 requests each containing 16 "have" lines before
196 # processing the first response. In these 2 requests, 4 commits from
197 # each branch are sent. Just check the first branch.
198 have_sent b1.c19 b1.c17 b1.c14 b1.c9 &&
199 have_not_sent b1.c18 b1.c16 b1.c15 b1.c13 b1.c12 b1.c11 b1.c10 &&
201 # While fetch-pack is processing the first response, it should read that
202 # the server ACKs b1.c19 and b1.c17.
203 grep "fetch< ACK $(git -C client rev-parse b1.c19) common" trace &&
204 grep "fetch< ACK $(git -C client rev-parse b1.c17) common" trace &&
206 # fetch-pack should thus not send any more commits in the b1 branch, but
207 # should still send the others (in this test, just check b2).
212 have_sent b2.c1 b2.c0