t / t5539-fetch-http-shallow.shon commit apply --recount: allow "no-op hunks" (22cb383)
   1#!/bin/sh
   2
   3test_description='fetch/clone from a shallow clone over http'
   4
   5. ./test-lib.sh
   6. "$TEST_DIRECTORY"/lib-httpd.sh
   7start_httpd
   8
   9commit() {
  10        echo "$1" >tracked &&
  11        git add tracked &&
  12        git commit -m "$1"
  13}
  14
  15test_expect_success 'setup shallow clone' '
  16        commit 1 &&
  17        commit 2 &&
  18        commit 3 &&
  19        commit 4 &&
  20        commit 5 &&
  21        commit 6 &&
  22        commit 7 &&
  23        git clone --no-local --depth=5 .git shallow &&
  24        git config --global transfer.fsckObjects true
  25'
  26
  27test_expect_success 'clone http repository' '
  28        git clone --bare --no-local shallow "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
  29        git clone $HTTPD_URL/smart/repo.git clone &&
  30        (
  31        cd clone &&
  32        git fsck &&
  33        git log --format=%s origin/master >actual &&
  34        cat <<EOF >expect &&
  357
  366
  375
  384
  393
  40EOF
  41        test_cmp expect actual
  42        )
  43'
  44
  45# This test is tricky. We need large enough "have"s that fetch-pack
  46# will put pkt-flush in between. Then we need a "have" the server
  47# does not have, it'll send "ACK %s ready"
  48test_expect_success 'no shallow lines after receiving ACK ready' '
  49        (
  50                cd shallow &&
  51                test_tick &&
  52                for i in $(test_seq 15)
  53                do
  54                        git checkout --orphan unrelated$i &&
  55                        test_commit unrelated$i &&
  56                        git push -q "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
  57                                refs/heads/unrelated$i:refs/heads/unrelated$i &&
  58                        git push -q ../clone/.git \
  59                                refs/heads/unrelated$i:refs/heads/unrelated$i ||
  60                        exit 1
  61                done &&
  62                git checkout master &&
  63                test_commit new &&
  64                git push  "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" master
  65        ) &&
  66        (
  67                cd clone &&
  68                git checkout --orphan newnew &&
  69                test_commit new-too &&
  70                GIT_TRACE_PACKET="$TRASH_DIRECTORY/trace" git fetch --depth=2 &&
  71                grep "fetch-pack< ACK .* ready" ../trace &&
  72                ! grep "fetch-pack> done" ../trace
  73        )
  74'
  75
  76test_expect_success 'clone shallow since ...' '
  77        test_create_repo shallow-since &&
  78        (
  79        cd shallow-since &&
  80        GIT_COMMITTER_DATE="100000000 +0700" git commit --allow-empty -m one &&
  81        GIT_COMMITTER_DATE="200000000 +0700" git commit --allow-empty -m two &&
  82        GIT_COMMITTER_DATE="300000000 +0700" git commit --allow-empty -m three &&
  83        mv .git "$HTTPD_DOCUMENT_ROOT_PATH/shallow-since.git" &&
  84        git clone --shallow-since "300000000 +0700" $HTTPD_URL/smart/shallow-since.git ../shallow11 &&
  85        git -C ../shallow11 log --pretty=tformat:%s HEAD >actual &&
  86        echo three >expected &&
  87        test_cmp expected actual
  88        )
  89'
  90
  91test_expect_success 'fetch shallow since ...' '
  92        git -C shallow11 fetch --shallow-since "200000000 +0700" origin &&
  93        git -C shallow11 log --pretty=tformat:%s origin/master >actual &&
  94        cat >expected <<-\EOF &&
  95        three
  96        two
  97        EOF
  98        test_cmp expected actual
  99'
 100
 101test_expect_success 'shallow clone exclude tag two' '
 102        test_create_repo shallow-exclude &&
 103        (
 104        cd shallow-exclude &&
 105        test_commit one &&
 106        test_commit two &&
 107        test_commit three &&
 108        mv .git "$HTTPD_DOCUMENT_ROOT_PATH/shallow-exclude.git" &&
 109        git clone --shallow-exclude two $HTTPD_URL/smart/shallow-exclude.git ../shallow12 &&
 110        git -C ../shallow12 log --pretty=tformat:%s HEAD >actual &&
 111        echo three >expected &&
 112        test_cmp expected actual
 113        )
 114'
 115
 116test_expect_success 'fetch exclude tag one' '
 117        git -C shallow12 fetch --shallow-exclude one origin &&
 118        git -C shallow12 log --pretty=tformat:%s origin/master >actual &&
 119        test_write_lines three two >expected &&
 120        test_cmp expected actual
 121'
 122
 123test_expect_success 'fetching deepen' '
 124        test_create_repo shallow-deepen &&
 125        (
 126        cd shallow-deepen &&
 127        test_commit one &&
 128        test_commit two &&
 129        test_commit three &&
 130        mv .git "$HTTPD_DOCUMENT_ROOT_PATH/shallow-deepen.git" &&
 131        git clone --depth 1 $HTTPD_URL/smart/shallow-deepen.git deepen &&
 132        mv "$HTTPD_DOCUMENT_ROOT_PATH/shallow-deepen.git" .git &&
 133        test_commit four &&
 134        git -C deepen log --pretty=tformat:%s master >actual &&
 135        echo three >expected &&
 136        test_cmp expected actual &&
 137        mv .git "$HTTPD_DOCUMENT_ROOT_PATH/shallow-deepen.git" &&
 138        git -C deepen fetch --deepen=1 &&
 139        git -C deepen log --pretty=tformat:%s origin/master >actual &&
 140        cat >expected <<-\EOF &&
 141        four
 142        three
 143        two
 144        EOF
 145        test_cmp expected actual
 146        )
 147'
 148
 149stop_httpd
 150test_done