t5552-skipping-fetch-negotiator.sh [plain text]
#!/bin/sh
test_description='test skipping fetch negotiator'
. ./test-lib.sh
have_sent () {
while test "$#" -ne 0
do
grep "fetch> have $(git -C client rev-parse $1)" trace
if test $? -ne 0
then
echo "No have $(git -C client rev-parse $1) ($1)"
return 1
fi
shift
done
}
have_not_sent () {
while test "$#" -ne 0
do
grep "fetch> have $(git -C client rev-parse $1)" trace
if test $? -eq 0
then
return 1
fi
shift
done
}
trace_fetch () {
client=$1; shift
server=$1; shift
GIT_TRACE_PACKET="$(pwd)/trace" \
git -C "$client" fetch \
--upload-pack 'unset GIT_TRACE_PACKET; git-upload-pack' \
"$server" "$@"
}
test_expect_success 'commits with no parents are sent regardless of skip distance' '
git init server &&
test_commit -C server to_fetch &&
git init client &&
for i in $(test_seq 7)
do
test_commit -C client c$i
done &&
test_config -C client fetch.negotiationalgorithm skipping &&
trace_fetch client "$(pwd)/server" &&
have_sent c7 c5 c2 c1 &&
have_not_sent c6 c4 c3
'
test_expect_success 'unknown fetch.negotiationAlgorithm values error out' '
rm -rf server client trace &&
git init server &&
test_commit -C server to_fetch &&
git init client &&
test_commit -C client on_client &&
git -C client checkout on_client &&
test_config -C client fetch.negotiationAlgorithm invalid &&
test_must_fail git -C client fetch "$(pwd)/server" 2>err &&
test_i18ngrep "unknown fetch negotiation algorithm" err &&
test_config -C client fetch.negotiationAlgorithm default &&
git -C client -c fetch.negotiationAlgorithm=default fetch "$(pwd)/server" &&
test_config -C client fetch.negotiationAlgorithm invalid &&
git -C client fetch "$(pwd)/server" 2>err &&
test_i18ngrep ! "unknown fetch negotiation algorithm" err
'
test_expect_success 'when two skips collide, favor the larger one' '
rm -rf server client trace &&
git init server &&
test_commit -C server to_fetch &&
git init client &&
for i in $(test_seq 11)
do
test_commit -C client c$i
done &&
git -C client checkout c5 &&
test_commit -C client c5side &&
test_config -C client fetch.negotiationalgorithm skipping &&
trace_fetch client "$(pwd)/server" &&
have_sent c5side c11 c9 c6 c1 &&
have_not_sent c10 c8 c7 c5 c4 c3 c2
'
test_expect_success 'use ref advertisement to filter out commits' '
rm -rf server client trace &&
git init server &&
test_commit -C server c1 &&
test_commit -C server c2 &&
test_commit -C server c3 &&
git -C server tag -d c1 c2 c3 &&
git clone server client &&
test_commit -C client c4 &&
test_commit -C client c5 &&
git -C client checkout c4^^ &&
test_commit -C client c2side &&
git -C server checkout --orphan anotherbranch &&
test_commit -C server to_fetch &&
test_config -C client fetch.negotiationalgorithm skipping &&
trace_fetch client origin to_fetch &&
have_sent c5 c4^ c2side &&
have_not_sent c4 c4^^ c4^^^
'
test_expect_success 'handle clock skew' '
rm -rf server client trace &&
git init server &&
test_commit -C server to_fetch &&
git init client &&
test_tick=2000000000 &&
test_commit -C client c1 &&
test_commit -C client c2 &&
test_tick=1000000000 &&
git -C client checkout c1 &&
test_commit -C client old1 &&
test_commit -C client old2 &&
test_commit -C client old3 &&
test_commit -C client old4 &&
test_config -C client fetch.negotiationalgorithm skipping &&
trace_fetch client "$(pwd)/server" &&
have_sent c2 c1 old4 old2 old1 &&
have_not_sent old3
'
test_expect_success 'do not send "have" with ancestors of commits that server ACKed' '
rm -rf server client trace &&
git init server &&
test_commit -C server to_fetch &&
git init client &&
for i in $(test_seq 8)
do
git -C client checkout --orphan b$i &&
test_commit -C client b$i.c0
done &&
for j in $(test_seq 19)
do
for i in $(test_seq 8)
do
git -C client checkout b$i &&
test_commit -C client b$i.c$j
done
done &&
git -C server fetch --no-tags "$(pwd)/client" b1:refs/heads/b1 &&
git -C server checkout b1 &&
test_commit -C server commit-on-b1 &&
test_config -C client fetch.negotiationalgorithm skipping &&
trace_fetch client "$(pwd)/server" to_fetch &&
grep " fetch" trace &&
have_sent b1.c19 b1.c17 b1.c14 b1.c9 &&
have_not_sent b1.c18 b1.c16 b1.c15 b1.c13 b1.c12 b1.c11 b1.c10 &&
grep "fetch< ACK $(git -C client rev-parse b1.c19) common" trace &&
grep "fetch< ACK $(git -C client rev-parse b1.c17) common" trace &&
for i in $(test_seq 0 8)
do
have_not_sent b1.c$i
done &&
have_sent b2.c1 b2.c0
'
test_done