3 test_description
='test skipping fetch negotiator'
6 test_expect_success
'fetch.negotiationalgorithm config' '
7 test_when_finished "rm -rf repo" &&
9 cat >repo/.git/config <<-\EOF &&
13 cat >expect <<-\EOF &&
14 error: missing value for '\''fetch.negotiationalgorithm'\''
15 fatal: bad config variable '\''fetch.negotiationalgorithm'\'' in file '\''.git/config'\'' at line 2
17 test_expect_code 128 git -C repo fetch >out 2>actual &&
18 test_must_be_empty out &&
19 test_cmp expect actual
25 grep "fetch> have $(git -C client rev-parse $1)" trace
28 echo "No have $(git -C client rev-parse $1) ($1)"
38 grep "fetch> have $(git -C client rev-parse $1)" trace
47 # trace_fetch <client_dir> <server_dir> [args]
49 # Trace the packet output of fetch, but make sure we disable the variable
50 # in the child upload-pack, so we don't combine the results in the same file.
54 GIT_TRACE_PACKET
="$(pwd)/trace" \
55 git
-C "$client" fetch \
56 --upload-pack 'unset GIT_TRACE_PACKET; git-upload-pack' \
60 test_expect_success
'commits with no parents are sent regardless of skip distance' '
62 test_commit -C server to_fetch &&
65 for i in $(test_seq 7)
67 test_commit -C client c$i || return 1
70 # We send: "c7" (skip 1) "c5" (skip 2) "c2" (skip 4). After that, since
71 # "c1" has no parent, it is still sent as "have" even though it would
72 # normally be skipped.
73 test_config -C client fetch.negotiationalgorithm skipping &&
74 trace_fetch client "$(pwd)/server" &&
75 have_sent c7 c5 c2 c1 &&
76 have_not_sent c6 c4 c3
79 test_expect_success
'when two skips collide, favor the larger one' '
80 rm -rf server client trace &&
82 test_commit -C server to_fetch &&
85 for i in $(test_seq 11)
87 test_commit -C client c$i || return 1
89 git -C client checkout c5 &&
90 test_commit -C client c5side &&
92 # Before reaching c5, we send "c5side" (skip 1) and "c11" (skip 1) "c9"
93 # (skip 2) "c6" (skip 4). The larger skip (skip 4) takes precedence, so
94 # the next "have" sent will be "c1" (from "c6" skip 4) and not "c4"
95 # (from "c5side" skip 1).
96 test_config -C client fetch.negotiationalgorithm skipping &&
97 trace_fetch client "$(pwd)/server" &&
98 have_sent c5side c11 c9 c6 c1 &&
99 have_not_sent c10 c8 c7 c5 c4 c3 c2
102 test_expect_success
'use ref advertisement to filter out commits' '
103 rm -rf server client trace &&
105 test_commit -C server c1 &&
106 test_commit -C server c2 &&
107 test_commit -C server c3 &&
108 git -C server tag -d c1 c2 c3 &&
110 git clone server client &&
111 test_commit -C client c4 &&
112 test_commit -C client c5 &&
113 git -C client checkout c4^^ &&
114 test_commit -C client c2side &&
116 git -C server checkout --orphan anotherbranch &&
117 test_commit -C server to_fetch &&
119 # The server advertising "c3" (as "refs/heads/main") means that we do
120 # not need to send any ancestors of "c3", but we still need to send "c3"
122 test_config -C client fetch.negotiationalgorithm skipping &&
124 # The ref advertisement itself is filtered when protocol v2 is used, so
127 GIT_TEST_PROTOCOL_VERSION=0 &&
128 export GIT_TEST_PROTOCOL_VERSION &&
129 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 &&
171 for i in $(test_seq 8)
173 git -C client checkout --orphan b$i &&
174 test_commit -C client b$i.c0 || return 1
176 for j in $(test_seq 19)
178 for i in $(test_seq 8)
180 git -C client checkout b$i &&
181 test_commit -C client b$i.c$j || return 1
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 &&
193 # NEEDSWORK: The number of "have"s sent depends on whether the transport
194 # is stateful. If the overspecification of the result were reduced, this
195 # test could be used for both stateful and stateless transports.
197 # Force protocol v0, in which local transport is stateful (in
198 # protocol v2 it is stateless).
199 GIT_TEST_PROTOCOL_VERSION=0 &&
200 export GIT_TEST_PROTOCOL_VERSION &&
201 trace_fetch client "$(pwd)/server" to_fetch
203 grep " fetch" trace &&
205 # fetch-pack sends 2 requests each containing 16 "have" lines before
206 # processing the first response. In these 2 requests, 4 commits from
207 # each branch are sent. Just check the first branch.
208 have_sent b1.c19 b1.c17 b1.c14 b1.c9 &&
209 have_not_sent b1.c18 b1.c16 b1.c15 b1.c13 b1.c12 b1.c11 b1.c10 &&
211 # While fetch-pack is processing the first response, it should read that
212 # the server ACKs b1.c19 and b1.c17.
213 grep "fetch< ACK $(git -C client rev-parse b1.c19) common" trace &&
214 grep "fetch< ACK $(git -C client rev-parse b1.c17) common" trace &&
216 # fetch-pack should thus not send any more commits in the b1 branch, but
217 # should still send the others (in this test, just check b2).
218 for i in $(test_seq 0 8)
220 have_not_sent b1.c$i || return 1
222 have_sent b2.c1 b2.c0