repack: repack promisor objects if -a or -A is set
[gitweb.git] / t / t5500-fetch-pack.sh
index 1b756687345207f42985048cbea8351755675ba8..fa03f56a2026b712519f932a8b4fd4a01bee80cc 100755 (executable)
@@ -30,7 +30,7 @@ add () {
        test_tick &&
        commit=$(echo "$text" | git commit-tree $tree $parents) &&
        eval "$name=$commit; export $name" &&
-       echo $commit > .git/refs/heads/$branch &&
+       git update-ref "refs/heads/$branch" "$commit" &&
        eval ${branch}TIP=$commit
 }
 
@@ -45,10 +45,10 @@ pull_to_client () {
 
                        case "$heads" in
                            *A*)
-                                   echo $ATIP > .git/refs/heads/A;;
+                                   git update-ref refs/heads/A "$ATIP";;
                        esac &&
                        case "$heads" in *B*)
-                           echo $BTIP > .git/refs/heads/B;;
+                           git update-ref refs/heads/B "$BTIP";;
                        esac &&
                        git symbolic-ref HEAD refs/heads/$(echo $heads \
                                | sed -e "s/^\(.\).*$/\1/") &&
@@ -92,8 +92,8 @@ test_expect_success 'setup' '
                cur=$(($cur+1))
        done &&
        add B1 $A1 &&
-       echo $ATIP > .git/refs/heads/A &&
-       echo $BTIP > .git/refs/heads/B &&
+       git update-ref refs/heads/A "$ATIP" &&
+       git update-ref refs/heads/B "$BTIP" &&
        git symbolic-ref HEAD refs/heads/B
 '
 
@@ -259,7 +259,7 @@ test_expect_success 'clone shallow object count' '
 test_expect_success 'pull in shallow repo with missing merge base' '
        (
                cd shallow &&
-               git fetch --depth 4 .. A
+               git fetch --depth 4 .. A &&
                test_must_fail git merge --allow-unrelated-histories FETCH_HEAD
        )
 '
@@ -482,25 +482,25 @@ test_expect_success 'set up tests of missing reference' '
 test_expect_success 'test lonely missing ref' '
        (
                cd client &&
-               test_must_fail git fetch-pack --no-progress .. refs/heads/xyzzy
-       ) >/dev/null 2>error-m &&
-       test_cmp expect-error error-m
+               test_must_fail git fetch-pack --no-progress .. refs/heads/xyzzy 2>../error-m
+       ) &&
+       test_i18ncmp expect-error error-m
 '
 
 test_expect_success 'test missing ref after existing' '
        (
                cd client &&
-               test_must_fail git fetch-pack --no-progress .. refs/heads/A refs/heads/xyzzy
-       ) >/dev/null 2>error-em &&
-       test_cmp expect-error error-em
+               test_must_fail git fetch-pack --no-progress .. refs/heads/A refs/heads/xyzzy 2>../error-em
+       ) &&
+       test_i18ncmp expect-error error-em
 '
 
 test_expect_success 'test missing ref before existing' '
        (
                cd client &&
-               test_must_fail git fetch-pack --no-progress .. refs/heads/xyzzy refs/heads/A
-       ) >/dev/null 2>error-me &&
-       test_cmp expect-error error-me
+               test_must_fail git fetch-pack --no-progress .. refs/heads/xyzzy refs/heads/A 2>../error-me
+       ) &&
+       test_i18ncmp expect-error error-me
 '
 
 test_expect_success 'test --all, --depth, and explicit head' '
@@ -595,6 +595,41 @@ test_expect_success 'fetch-pack can fetch a raw sha1' '
        git fetch-pack hidden $(git -C hidden rev-parse refs/hidden/one)
 '
 
+test_expect_success 'fetch-pack can fetch a raw sha1 that is advertised as a ref' '
+       rm -rf server client &&
+       git init server &&
+       test_commit -C server 1 &&
+
+       git init client &&
+       git -C client fetch-pack ../server \
+               $(git -C server rev-parse refs/heads/master)
+'
+
+test_expect_success 'fetch-pack can fetch a raw sha1 overlapping a named ref' '
+       rm -rf server client &&
+       git init server &&
+       test_commit -C server 1 &&
+       test_commit -C server 2 &&
+
+       git init client &&
+       git -C client fetch-pack ../server \
+               $(git -C server rev-parse refs/tags/1) refs/tags/1
+'
+
+test_expect_success 'fetch-pack cannot fetch a raw sha1 that is not advertised as a ref' '
+       rm -rf server &&
+
+       git init server &&
+       test_commit -C server 5 &&
+       git -C server tag -d 5 &&
+       test_commit -C server 6 &&
+
+       git init client &&
+       test_must_fail git -C client fetch-pack ../server \
+               $(git -C server rev-parse refs/heads/master^) 2>err &&
+       test_i18ngrep "Server does not allow request for unadvertised object" err
+'
+
 check_prot_path () {
        cat >expected <<-EOF &&
        Diag: url=$1
@@ -724,6 +759,17 @@ test_expect_success 'fetch shallow since ...' '
        test_cmp expected actual
 '
 
+test_expect_success 'clone shallow since selects no commits' '
+       test_create_repo shallow-since-the-future &&
+       (
+       cd shallow-since-the-future &&
+       GIT_COMMITTER_DATE="100000000 +0700" git commit --allow-empty -m one &&
+       GIT_COMMITTER_DATE="200000000 +0700" git commit --allow-empty -m two &&
+       GIT_COMMITTER_DATE="300000000 +0700" git commit --allow-empty -m three &&
+       test_must_fail git clone --shallow-since "900000000 +0700" "file://$(pwd)/." ../shallow111
+       )
+'
+
 test_expect_success 'shallow clone exclude tag two' '
        test_create_repo shallow-exclude &&
        (
@@ -768,4 +814,100 @@ test_expect_success 'fetching deepen' '
        )
 '
 
+test_expect_success 'use ref advertisement to prune "have" lines sent' '
+       rm -rf server client &&
+       git init server &&
+       test_commit -C server both_have_1 &&
+       git -C server tag -d both_have_1 &&
+       test_commit -C server both_have_2 &&
+
+       git clone server client &&
+       test_commit -C server server_has &&
+       test_commit -C client client_has &&
+
+       # In both protocol v0 and v2, ensure that the parent of both_have_2 is
+       # not sent as a "have" line. The client should know that the server has
+       # both_have_2, so it only needs to inform the server that it has
+       # both_have_2, and the server can infer the rest.
+
+       rm -f trace &&
+       cp -r client clientv0 &&
+       GIT_TRACE_PACKET="$(pwd)/trace" git -C clientv0 \
+               fetch origin server_has both_have_2 &&
+       grep "have $(git -C client rev-parse client_has)" trace &&
+       grep "have $(git -C client rev-parse both_have_2)" trace &&
+       ! grep "have $(git -C client rev-parse both_have_2^)" trace &&
+
+       rm -f trace &&
+       cp -r client clientv2 &&
+       GIT_TRACE_PACKET="$(pwd)/trace" git -C clientv2 -c protocol.version=2 \
+               fetch origin server_has both_have_2 &&
+       grep "have $(git -C client rev-parse client_has)" trace &&
+       grep "have $(git -C client rev-parse both_have_2)" trace &&
+       ! grep "have $(git -C client rev-parse both_have_2^)" trace
+'
+
+test_expect_success 'filtering by size' '
+       rm -rf server client &&
+       test_create_repo server &&
+       test_commit -C server one &&
+       test_config -C server uploadpack.allowfilter 1 &&
+
+       test_create_repo client &&
+       git -C client fetch-pack --filter=blob:limit=0 ../server HEAD &&
+
+       # Ensure that object is not inadvertently fetched
+       test_must_fail git -C client cat-file -e $(git hash-object server/one.t)
+'
+
+test_expect_success 'filtering by size has no effect if support for it is not advertised' '
+       rm -rf server client &&
+       test_create_repo server &&
+       test_commit -C server one &&
+
+       test_create_repo client &&
+       git -C client fetch-pack --filter=blob:limit=0 ../server HEAD 2> err &&
+
+       # Ensure that object is fetched
+       git -C client cat-file -e $(git hash-object server/one.t) &&
+
+       test_i18ngrep "filtering not recognized by server" err
+'
+
+fetch_filter_blob_limit_zero () {
+       SERVER="$1"
+       URL="$2"
+
+       rm -rf "$SERVER" client &&
+       test_create_repo "$SERVER" &&
+       test_commit -C "$SERVER" one &&
+       test_config -C "$SERVER" uploadpack.allowfilter 1 &&
+
+       git clone "$URL" client &&
+       test_config -C client extensions.partialclone origin &&
+
+       test_commit -C "$SERVER" two &&
+
+       git -C client fetch --filter=blob:limit=0 origin HEAD:somewhere &&
+
+       # Ensure that commit is fetched, but blob is not
+       test_config -C client extensions.partialclone "arbitrary string" &&
+       git -C client cat-file -e $(git -C "$SERVER" rev-parse two) &&
+       test_must_fail git -C client cat-file -e $(git hash-object "$SERVER/two.t")
+}
+
+test_expect_success 'fetch with --filter=blob:limit=0' '
+       fetch_filter_blob_limit_zero server server
+'
+
+. "$TEST_DIRECTORY"/lib-httpd.sh
+start_httpd
+
+test_expect_success 'fetch with --filter=blob:limit=0 and HTTP' '
+       fetch_filter_blob_limit_zero "$HTTPD_DOCUMENT_ROOT_PATH/server" "$HTTPD_URL/smart/server"
+'
+
+stop_httpd
+
+
 test_done