Merge branch 'master' of github.com:linusboyle/git
[gitweb.git] / t / t5552-skipping-fetch-negotiator.sh
index 0a8e0e42ed3b0992ffa645464eeb33bdf727d6da..30857b84a8d5b5fdec59f775ab97293a7da4f2df 100755 (executable)
@@ -28,12 +28,25 @@ have_not_sent () {
        done
 }
 
+# trace_fetch <client_dir> <server_dir> [args]
+#
+# Trace the packet output of fetch, but make sure we disable the variable
+# in the child upload-pack, so we don't combine the results in the same file.
+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 $(seq 7)
+       for i in $(test_seq 7)
        do
                test_commit -C client c$i
        done &&
@@ -42,18 +55,41 @@ test_expect_success 'commits with no parents are sent regardless of skip distanc
        # "c1" has no parent, it is still sent as "have" even though it would
        # normally be skipped.
        test_config -C client fetch.negotiationalgorithm skipping &&
-       GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch "$(pwd)/server" &&
+       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 &&
+
+       # Explicit "default" value
+       test_config -C client fetch.negotiationAlgorithm default &&
+       git -C client -c fetch.negotiationAlgorithm=default fetch "$(pwd)/server" &&
+
+       # Implementation detail: If there is nothing to fetch, we will not error out
+       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 $(seq 11)
+       for i in $(test_seq 11)
        do
                test_commit -C client c$i
        done &&
@@ -65,7 +101,7 @@ test_expect_success 'when two skips collide, favor the larger one' '
        # the next "have" sent will be "c1" (from "c6" skip 4) and not "c4"
        # (from "c5side" skip 1).
        test_config -C client fetch.negotiationalgorithm skipping &&
-       GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch "$(pwd)/server" &&
+       trace_fetch client "$(pwd)/server" &&
        have_sent c5side c11 c9 c6 c1 &&
        have_not_sent c10 c8 c7 c5 c4 c3 c2
 '
@@ -91,7 +127,7 @@ test_expect_success 'use ref advertisement to filter out commits' '
        # not need to send any ancestors of "c3", but we still need to send "c3"
        # itself.
        test_config -C client fetch.negotiationalgorithm skipping &&
-       GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch origin to_fetch &&
+       trace_fetch client origin to_fetch &&
        have_sent c5 c4^ c2side &&
        have_not_sent c4 c4^^ c4^^^
 '
@@ -121,7 +157,7 @@ test_expect_success 'handle clock skew' '
        # and sent, because (due to clock skew) its only parent has already been
        # popped off the priority queue.
        test_config -C client fetch.negotiationalgorithm skipping &&
-       GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch "$(pwd)/server" &&
+       trace_fetch client "$(pwd)/server" &&
        have_sent c2 c1 old4 old2 old1 &&
        have_not_sent old3
 '
@@ -132,14 +168,14 @@ test_expect_success 'do not send "have" with ancestors of commits that server AC
        test_commit -C server to_fetch &&
 
        git init client &&
-       for i in $(seq 8)
+       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 $(seq 19)
+       for j in $(test_seq 19)
        do
-               for i in $(seq 8)
+               for i in $(test_seq 8)
                do
                        git -C client checkout b$i &&
                        test_commit -C client b$i.c$j
@@ -153,7 +189,7 @@ test_expect_success 'do not send "have" with ancestors of commits that server AC
        test_commit -C server commit-on-b1 &&
 
        test_config -C client fetch.negotiationalgorithm skipping &&
-       GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch "$(pwd)/server" to_fetch &&
+       trace_fetch client "$(pwd)/server" to_fetch &&
        grep "  fetch" trace &&
 
        # fetch-pack sends 2 requests each containing 16 "have" lines before
@@ -169,7 +205,7 @@ test_expect_success 'do not send "have" with ancestors of commits that server AC
 
        # fetch-pack should thus not send any more commits in the b1 branch, but
        # should still send the others (in this test, just check b2).
-       for i in $(seq 0 8)
+       for i in $(test_seq 0 8)
        do
                have_not_sent b1.c$i
        done &&