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 test_expect_success
'commits with no parents are sent regardless of skip distance' '
33 test_commit -C server to_fetch &&
38 test_commit -C client c$i
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
'when two skips collide, favor the larger one' '
51 rm -rf server client trace &&
53 test_commit -C server to_fetch &&
58 test_commit -C client c$i
60 git -C client checkout c5 &&
61 test_commit -C client c5side &&
63 # Before reaching c5, we send "c5side" (skip 1) and "c11" (skip 1) "c9"
64 # (skip 2) "c6" (skip 4). The larger skip (skip 4) takes precedence, so
65 # the next "have" sent will be "c1" (from "c6" skip 4) and not "c4"
66 # (from "c5side" skip 1).
67 test_config -C client fetch.negotiationalgorithm skipping &&
68 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch "$(pwd)/server" &&
69 have_sent c5side c11 c9 c6 c1 &&
70 have_not_sent c10 c8 c7 c5 c4 c3 c2
73 test_expect_success
'use ref advertisement to filter out commits' '
74 rm -rf server client trace &&
76 test_commit -C server c1 &&
77 test_commit -C server c2 &&
78 test_commit -C server c3 &&
79 git -C server tag -d c1 c2 c3 &&
81 git clone server client &&
82 test_commit -C client c4 &&
83 test_commit -C client c5 &&
84 git -C client checkout c4^^ &&
85 test_commit -C client c2side &&
87 git -C server checkout --orphan anotherbranch &&
88 test_commit -C server to_fetch &&
90 # The server advertising "c3" (as "refs/heads/master") means that we do
91 # not need to send any ancestors of "c3", but we still need to send "c3"
93 test_config -C client fetch.negotiationalgorithm skipping &&
94 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch origin to_fetch &&
95 have_sent c5 c4^ c2side &&
96 have_not_sent c4 c4^^ c4^^^
99 test_expect_success
'handle clock skew' '
100 rm -rf server client trace &&
102 test_commit -C server to_fetch &&
107 test_tick=2000000000 &&
108 test_commit -C client c1 &&
109 test_commit -C client c2 &&
112 test_tick=1000000000 &&
113 git -C client checkout c1 &&
114 test_commit -C client old1 &&
115 test_commit -C client old2 &&
116 test_commit -C client old3 &&
117 test_commit -C client old4 &&
119 # "c2" and "c1" are popped first, then "old4" to "old1". "old1" would
120 # normally be skipped, but is treated as a commit without a parent here
121 # and sent, because (due to clock skew) its only parent has already been
122 # popped off the priority queue.
123 test_config -C client fetch.negotiationalgorithm skipping &&
124 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch "$(pwd)/server" &&
125 have_sent c2 c1 old4 old2 old1 &&
129 test_expect_success
'do not send "have" with ancestors of commits that server ACKed' '
130 rm -rf server client trace &&
132 test_commit -C server to_fetch &&
137 git -C client checkout --orphan b$i &&
138 test_commit -C client b$i.c0
144 git -C client checkout b$i &&
145 test_commit -C client b$i.c$j
149 # Copy this branch over to the server and add a commit on it so that it
150 # is reachable but not advertised.
151 git -C server fetch --no-tags "$(pwd)/client" b1:refs/heads/b1 &&
152 git -C server checkout b1 &&
153 test_commit -C server commit-on-b1 &&
155 test_config -C client fetch.negotiationalgorithm skipping &&
156 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch "$(pwd)/server" to_fetch &&
157 grep " fetch" trace &&
159 # fetch-pack sends 2 requests each containing 16 "have" lines before
160 # processing the first response. In these 2 requests, 4 commits from
161 # each branch are sent. Just check the first branch.
162 have_sent b1.c19 b1.c17 b1.c14 b1.c9 &&
163 have_not_sent b1.c18 b1.c16 b1.c15 b1.c13 b1.c12 b1.c11 b1.c10 &&
165 # While fetch-pack is processing the first response, it should read that
166 # the server ACKs b1.c19 and b1.c17.
167 grep "fetch< ACK $(git -C client rev-parse b1.c19) common" trace &&
168 grep "fetch< ACK $(git -C client rev-parse b1.c17) common" trace &&
170 # fetch-pack should thus not send any more commits in the b1 branch, but
171 # should still send the others (in this test, just check b2).
176 have_sent b2.c1 b2.c0