Merge branch 'en/abort-df-conflict-fixes'
[gitweb.git] / t / t5510-fetch.sh
index 858381a7881f430c5e779c2e385ebda4bed3a6dc..5e810f494e69625cc365955143a08567b8f783a9 100755 (executable)
@@ -63,7 +63,7 @@ test_expect_success "fetch test" '
        git commit -a -m "updated by origin" &&
        cd two &&
        git fetch &&
-       test -f .git/refs/heads/one &&
+       git rev-parse --verify refs/heads/one &&
        mine=$(git rev-parse refs/heads/one) &&
        his=$(cd ../one && git rev-parse refs/heads/master) &&
        test "z$mine" = "z$his"
@@ -73,8 +73,8 @@ test_expect_success "fetch test for-merge" '
        cd "$D" &&
        cd three &&
        git fetch &&
-       test -f .git/refs/heads/two &&
-       test -f .git/refs/heads/one &&
+       git rev-parse --verify refs/heads/two &&
+       git rev-parse --verify refs/heads/one &&
        master_in_two=$(cd ../two && git rev-parse master) &&
        one_in_two=$(cd ../two && git rev-parse one) &&
        {
@@ -863,9 +863,11 @@ test_expect_success 'fetching with auto-gc does not lock up' '
        test_commit test2 &&
        (
                cd auto-gc &&
+               git config fetch.unpackLimit 1 &&
                git config gc.autoPackLimit 1 &&
                git config gc.autoDetach false &&
                GIT_ASK_YESNO="$D/askyesno" git fetch >fetch.out 2>&1 &&
+               test_i18ngrep "Auto packing the repository" fetch.out &&
                ! grep "Should I try again" fetch.out
        )
 '
@@ -875,8 +877,8 @@ test_expect_success C_LOCALE_OUTPUT 'fetch aligned output' '
        test_commit looooooooooooong-tag &&
        (
                cd full-output &&
-               git -c fetch.output=full fetch origin 2>&1 | \
-                       grep -e "->" | cut -c 22- >../actual
+               git -c fetch.output=full fetch origin >actual 2>&1 &&
+               grep -e "->" actual | cut -c 22- >../actual
        ) &&
        cat >expect <<-\EOF &&
        master               -> origin/master
@@ -890,8 +892,8 @@ test_expect_success C_LOCALE_OUTPUT 'fetch compact output' '
        test_commit extraaa &&
        (
                cd compact &&
-               git -c fetch.output=compact fetch origin 2>&1 | \
-                       grep -e "->" | cut -c 22- >../actual
+               git -c fetch.output=compact fetch origin >actual 2>&1 &&
+               grep -e "->" actual | cut -c 22- >../actual
        ) &&
        cat >expect <<-\EOF &&
        master     -> origin/*
@@ -900,4 +902,82 @@ test_expect_success C_LOCALE_OUTPUT 'fetch compact output' '
        test_cmp expect actual
 '
 
+setup_negotiation_tip () {
+       SERVER="$1"
+       URL="$2"
+       USE_PROTOCOL_V2="$3"
+
+       rm -rf "$SERVER" client trace &&
+       git init "$SERVER" &&
+       test_commit -C "$SERVER" alpha_1 &&
+       test_commit -C "$SERVER" alpha_2 &&
+       git -C "$SERVER" checkout --orphan beta &&
+       test_commit -C "$SERVER" beta_1 &&
+       test_commit -C "$SERVER" beta_2 &&
+
+       git clone "$URL" client &&
+
+       if test "$USE_PROTOCOL_V2" -eq 1
+       then
+               git -C "$SERVER" config protocol.version 2 &&
+               git -C client config protocol.version 2
+       fi &&
+
+       test_commit -C "$SERVER" beta_s &&
+       git -C "$SERVER" checkout master &&
+       test_commit -C "$SERVER" alpha_s &&
+       git -C "$SERVER" tag -d alpha_1 alpha_2 beta_1 beta_2
+}
+
+check_negotiation_tip () {
+       # Ensure that {alpha,beta}_1 are sent as "have", but not {alpha_beta}_2
+       ALPHA_1=$(git -C client rev-parse alpha_1) &&
+       grep "fetch> have $ALPHA_1" trace &&
+       BETA_1=$(git -C client rev-parse beta_1) &&
+       grep "fetch> have $BETA_1" trace &&
+       ALPHA_2=$(git -C client rev-parse alpha_2) &&
+       ! grep "fetch> have $ALPHA_2" trace &&
+       BETA_2=$(git -C client rev-parse beta_2) &&
+       ! grep "fetch> have $BETA_2" trace
+}
+
+test_expect_success '--negotiation-tip limits "have" lines sent' '
+       setup_negotiation_tip server server 0 &&
+       GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
+               --negotiation-tip=alpha_1 --negotiation-tip=beta_1 \
+               origin alpha_s beta_s &&
+       check_negotiation_tip
+'
+
+test_expect_success '--negotiation-tip understands globs' '
+       setup_negotiation_tip server server 0 &&
+       GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
+               --negotiation-tip=*_1 \
+               origin alpha_s beta_s &&
+       check_negotiation_tip
+'
+
+test_expect_success '--negotiation-tip understands abbreviated SHA-1' '
+       setup_negotiation_tip server server 0 &&
+       GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
+               --negotiation-tip=$(git -C client rev-parse --short alpha_1) \
+               --negotiation-tip=$(git -C client rev-parse --short beta_1) \
+               origin alpha_s beta_s &&
+       check_negotiation_tip
+'
+
+. "$TEST_DIRECTORY"/lib-httpd.sh
+start_httpd
+
+test_expect_success '--negotiation-tip limits "have" lines sent with HTTP protocol v2' '
+       setup_negotiation_tip "$HTTPD_DOCUMENT_ROOT_PATH/server" \
+               "$HTTPD_URL/smart/server" 1 &&
+       GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
+               --negotiation-tip=alpha_1 --negotiation-tip=beta_1 \
+               origin alpha_s beta_s &&
+       check_negotiation_tip
+'
+
+stop_httpd
+
 test_done