3 test_description
='test skipping fetch negotiator'
5 TEST_PASSES_SANITIZE_LEAK
=true
8 test_expect_success
'fetch.negotiationalgorithm config' '
9 test_when_finished "rm -rf repo" &&
11 cat >repo/.git/config <<-\EOF &&
15 cat >expect <<-\EOF &&
16 error: missing value for '\''fetch.negotiationalgorithm'\''
17 fatal: bad config variable '\''fetch.negotiationalgorithm'\'' in file '\''.git/config'\'' at line 2
19 test_expect_code 128 git -C repo fetch >out 2>actual &&
20 test_must_be_empty out &&
21 test_cmp expect actual
27 grep "fetch> have $(git -C client rev-parse $1)" trace
30 echo "No have $(git -C client rev-parse $1) ($1)"
40 grep "fetch> have $(git -C client rev-parse $1)" trace
49 # trace_fetch <client_dir> <server_dir> [args]
51 # Trace the packet output of fetch, but make sure we disable the variable
52 # in the child upload-pack, so we don't combine the results in the same file.
56 GIT_TRACE_PACKET
="$(pwd)/trace" \
57 git
-C "$client" fetch \
58 --upload-pack 'unset GIT_TRACE_PACKET; git-upload-pack' \
62 test_expect_success
'commits with no parents are sent regardless of skip distance' '
64 test_commit -C server to_fetch &&
67 for i in $(test_seq 7)
69 test_commit -C client c$i || return 1
72 # We send: "c7" (skip 1) "c5" (skip 2) "c2" (skip 4). After that, since
73 # "c1" has no parent, it is still sent as "have" even though it would
74 # normally be skipped.
75 test_config -C client fetch.negotiationalgorithm skipping &&
76 trace_fetch client "$(pwd)/server" &&
77 have_sent c7 c5 c2 c1 &&
78 have_not_sent c6 c4 c3
81 test_expect_success
'when two skips collide, favor the larger one' '
82 rm -rf server client trace &&
84 test_commit -C server to_fetch &&
87 for i in $(test_seq 11)
89 test_commit -C client c$i || return 1
91 git -C client checkout c5 &&
92 test_commit -C client c5side &&
94 # Before reaching c5, we send "c5side" (skip 1) and "c11" (skip 1) "c9"
95 # (skip 2) "c6" (skip 4). The larger skip (skip 4) takes precedence, so
96 # the next "have" sent will be "c1" (from "c6" skip 4) and not "c4"
97 # (from "c5side" skip 1).
98 test_config -C client fetch.negotiationalgorithm skipping &&
99 trace_fetch client "$(pwd)/server" &&
100 have_sent c5side c11 c9 c6 c1 &&
101 have_not_sent c10 c8 c7 c5 c4 c3 c2
104 test_expect_success
'use ref advertisement to filter out commits' '
105 rm -rf server client trace &&
107 test_commit -C server c1 &&
108 test_commit -C server c2 &&
109 test_commit -C server c3 &&
110 git -C server tag -d c1 c2 c3 &&
112 git clone server client &&
113 test_commit -C client c4 &&
114 test_commit -C client c5 &&
115 git -C client checkout c4^^ &&
116 test_commit -C client c2side &&
118 git -C server checkout --orphan anotherbranch &&
119 test_commit -C server to_fetch &&
121 # The server advertising "c3" (as "refs/heads/main") means that we do
122 # not need to send any ancestors of "c3", but we still need to send "c3"
124 test_config -C client fetch.negotiationalgorithm skipping &&
126 # The ref advertisement itself is filtered when protocol v2 is used, so
129 GIT_TEST_PROTOCOL_VERSION=0 &&
130 export GIT_TEST_PROTOCOL_VERSION &&
131 trace_fetch client origin to_fetch
133 have_sent c5 c4^ c2side &&
134 have_not_sent c4 c4^^ c4^^^
137 test_expect_success
'handle clock skew' '
138 rm -rf server client trace &&
140 test_commit -C server to_fetch &&
145 test_tick=2000000000 &&
146 test_commit -C client c1 &&
147 test_commit -C client c2 &&
150 test_tick=1000000000 &&
151 git -C client checkout c1 &&
152 test_commit -C client old1 &&
153 test_commit -C client old2 &&
154 test_commit -C client old3 &&
155 test_commit -C client old4 &&
157 # "c2" and "c1" are popped first, then "old4" to "old1". "old1" would
158 # normally be skipped, but is treated as a commit without a parent here
159 # and sent, because (due to clock skew) its only parent has already been
160 # popped off the priority queue.
161 test_config -C client fetch.negotiationalgorithm skipping &&
162 trace_fetch client "$(pwd)/server" &&
163 have_sent c2 c1 old4 old2 old1 &&
167 test_expect_success
'do not send "have" with ancestors of commits that server ACKed' '
168 rm -rf server client trace &&
170 test_commit -C server to_fetch &&
173 for i in $(test_seq 8)
175 git -C client checkout --orphan b$i &&
176 test_commit -C client b$i.c0 || return 1
178 for j in $(test_seq 19)
180 for i in $(test_seq 8)
182 git -C client checkout b$i &&
183 test_commit -C client b$i.c$j || return 1
187 # Copy this branch over to the server and add a commit on it so that it
188 # is reachable but not advertised.
189 git -C server fetch --no-tags "$(pwd)/client" b1:refs/heads/b1 &&
190 git -C server checkout b1 &&
191 test_commit -C server commit-on-b1 &&
193 test_config -C client fetch.negotiationalgorithm skipping &&
195 # NEEDSWORK: The number of "have"s sent depends on whether the transport
196 # is stateful. If the overspecification of the result were reduced, this
197 # test could be used for both stateful and stateless transports.
199 # Force protocol v0, in which local transport is stateful (in
200 # protocol v2 it is stateless).
201 GIT_TEST_PROTOCOL_VERSION=0 &&
202 export GIT_TEST_PROTOCOL_VERSION &&
203 trace_fetch client "$(pwd)/server" to_fetch
205 grep " fetch" trace &&
207 # fetch-pack sends 2 requests each containing 16 "have" lines before
208 # processing the first response. In these 2 requests, 4 commits from
209 # each branch are sent. Just check the first branch.
210 have_sent b1.c19 b1.c17 b1.c14 b1.c9 &&
211 have_not_sent b1.c18 b1.c16 b1.c15 b1.c13 b1.c12 b1.c11 b1.c10 &&
213 # While fetch-pack is processing the first response, it should read that
214 # the server ACKs b1.c19 and b1.c17.
215 grep "fetch< ACK $(git -C client rev-parse b1.c19) common" trace &&
216 grep "fetch< ACK $(git -C client rev-parse b1.c17) common" trace &&
218 # fetch-pack should thus not send any more commits in the b1 branch, but
219 # should still send the others (in this test, just check b2).
220 for i in $(test_seq 0 8)
222 have_not_sent b1.c$i || return 1
224 have_sent b2.c1 b2.c0