t / t5500-fetch-pack.shon commit Merge branch 'nd/maint-refname-in-hierarchy-check' (02a20d1)
   1#!/bin/sh
   2#
   3# Copyright (c) 2005 Johannes Schindelin
   4#
   5
   6test_description='Testing multi_ack pack fetching'
   7
   8. ./test-lib.sh
   9
  10# Test fetch-pack/upload-pack pair.
  11
  12# Some convenience functions
  13
  14add () {
  15        name=$1 &&
  16        text="$@" &&
  17        branch=`echo $name | sed -e 's/^\(.\).*$/\1/'` &&
  18        parents="" &&
  19
  20        shift &&
  21        while test $1; do
  22                parents="$parents -p $1" &&
  23                shift
  24        done &&
  25
  26        echo "$text" > test.txt &&
  27        git update-index --add test.txt &&
  28        tree=$(git write-tree) &&
  29        # make sure timestamps are in correct order
  30        test_tick &&
  31        commit=$(echo "$text" | git commit-tree $tree $parents) &&
  32        eval "$name=$commit; export $name" &&
  33        echo $commit > .git/refs/heads/$branch &&
  34        eval ${branch}TIP=$commit
  35}
  36
  37pull_to_client () {
  38        number=$1 &&
  39        heads=$2 &&
  40        count=$3 &&
  41        test_expect_success "$number pull" '
  42                (
  43                        cd client &&
  44                        git fetch-pack -k -v .. $heads &&
  45
  46                        case "$heads" in
  47                            *A*)
  48                                    echo $ATIP > .git/refs/heads/A;;
  49                        esac &&
  50                        case "$heads" in *B*)
  51                            echo $BTIP > .git/refs/heads/B;;
  52                        esac &&
  53                        git symbolic-ref HEAD refs/heads/`echo $heads \
  54                                | sed -e "s/^\(.\).*$/\1/"` &&
  55
  56                        git fsck --full &&
  57
  58                        mv .git/objects/pack/pack-* . &&
  59                        p=`ls -1 pack-*.pack` &&
  60                        git unpack-objects <$p &&
  61                        git fsck --full &&
  62
  63                        idx=`echo pack-*.idx` &&
  64                        pack_count=`git show-index <$idx | wc -l` &&
  65                        test $pack_count = $count &&
  66                        rm -f pack-*
  67                )
  68        '
  69}
  70
  71# Here begins the actual testing
  72
  73# A1 - ... - A20 - A21
  74#    \
  75#      B1  -   B2 - .. - B70
  76
  77# client pulls A20, B1. Then tracks only B. Then pulls A.
  78
  79test_expect_success 'setup' '
  80        mkdir client &&
  81        (
  82                cd client &&
  83                git init &&
  84                git config transfer.unpacklimit 0
  85        ) &&
  86        add A1 &&
  87        prev=1 &&
  88        cur=2 &&
  89        while [ $cur -le 10 ]; do
  90                add A$cur $(eval echo \$A$prev) &&
  91                prev=$cur &&
  92                cur=$(($cur+1))
  93        done &&
  94        add B1 $A1 &&
  95        echo $ATIP > .git/refs/heads/A &&
  96        echo $BTIP > .git/refs/heads/B &&
  97        git symbolic-ref HEAD refs/heads/B
  98'
  99
 100pull_to_client 1st "refs/heads/B refs/heads/A" $((11*3))
 101
 102test_expect_success 'post 1st pull setup' '
 103        add A11 $A10 &&
 104        prev=1 &&
 105        cur=2 &&
 106        while [ $cur -le 65 ]; do
 107                add B$cur $(eval echo \$B$prev) &&
 108                prev=$cur &&
 109                cur=$(($cur+1))
 110        done
 111'
 112
 113pull_to_client 2nd "refs/heads/B" $((64*3))
 114
 115pull_to_client 3rd "refs/heads/A" $((1*3))
 116
 117test_expect_success 'single branch clone' '
 118        git clone --single-branch "file://$(pwd)/." singlebranch
 119'
 120
 121test_expect_success 'single branch object count' '
 122        GIT_DIR=singlebranch/.git git count-objects -v |
 123                grep "^in-pack:" > count.singlebranch &&
 124        echo "in-pack: 198" >expected &&
 125        test_cmp expected count.singlebranch
 126'
 127
 128test_expect_success 'clone shallow' '
 129        git clone --no-single-branch --depth 2 "file://$(pwd)/." shallow
 130'
 131
 132test_expect_success 'clone shallow object count' '
 133        (
 134                cd shallow &&
 135                git count-objects -v
 136        ) > count.shallow &&
 137        grep "^in-pack: 18" count.shallow
 138'
 139
 140test_expect_success 'clone shallow object count (part 2)' '
 141        sed -e "/^in-pack:/d" -e "/^packs:/d" -e "/^size-pack:/d" \
 142            -e "/: 0$/d" count.shallow > count_output &&
 143        ! test -s count_output
 144'
 145
 146test_expect_success 'fsck in shallow repo' '
 147        (
 148                cd shallow &&
 149                git fsck --full
 150        )
 151'
 152
 153test_expect_success 'simple fetch in shallow repo' '
 154        (
 155                cd shallow &&
 156                git fetch
 157        )
 158'
 159
 160test_expect_success 'no changes expected' '
 161        (
 162                cd shallow &&
 163                git count-objects -v
 164        ) > count.shallow.2 &&
 165        cmp count.shallow count.shallow.2
 166'
 167
 168test_expect_success 'fetch same depth in shallow repo' '
 169        (
 170                cd shallow &&
 171                git fetch --depth=2
 172        )
 173'
 174
 175test_expect_success 'no changes expected' '
 176        (
 177                cd shallow &&
 178                git count-objects -v
 179        ) > count.shallow.3 &&
 180        cmp count.shallow count.shallow.3
 181'
 182
 183test_expect_success 'add two more' '
 184        add B66 $B65 &&
 185        add B67 $B66
 186'
 187
 188test_expect_success 'pull in shallow repo' '
 189        (
 190                cd shallow &&
 191                git pull .. B
 192        )
 193'
 194
 195test_expect_success 'clone shallow object count' '
 196        (
 197                cd shallow &&
 198                git count-objects -v
 199        ) > count.shallow &&
 200        grep "^count: 6" count.shallow
 201'
 202
 203test_expect_success 'add two more (part 2)' '
 204        add B68 $B67 &&
 205        add B69 $B68
 206'
 207
 208test_expect_success 'deepening pull in shallow repo' '
 209        (
 210                cd shallow &&
 211                git pull --depth 4 .. B
 212        )
 213'
 214
 215test_expect_success 'clone shallow object count' '
 216        (
 217                cd shallow &&
 218                git count-objects -v
 219        ) > count.shallow &&
 220        grep "^count: 12" count.shallow
 221'
 222
 223test_expect_success 'deepening fetch in shallow repo' '
 224        (
 225                cd shallow &&
 226                git fetch --depth 4 .. A:A
 227        )
 228'
 229
 230test_expect_success 'clone shallow object count' '
 231        (
 232                cd shallow &&
 233                git count-objects -v
 234        ) > count.shallow &&
 235        grep "^count: 18" count.shallow
 236'
 237
 238test_expect_success 'pull in shallow repo with missing merge base' '
 239        (
 240                cd shallow &&
 241                test_must_fail git pull --depth 4 .. A
 242        )
 243'
 244
 245test_expect_success 'additional simple shallow deepenings' '
 246        (
 247                cd shallow &&
 248                git fetch --depth=8 &&
 249                git fetch --depth=10 &&
 250                git fetch --depth=11
 251        )
 252'
 253
 254test_expect_success 'clone shallow object count' '
 255        (
 256                cd shallow &&
 257                git count-objects -v
 258        ) > count.shallow &&
 259        grep "^count: 52" count.shallow
 260'
 261
 262test_expect_success 'clone shallow without --no-single-branch' '
 263        git clone --depth 1 "file://$(pwd)/." shallow2
 264'
 265
 266test_expect_success 'clone shallow object count' '
 267        (
 268                cd shallow2 &&
 269                git count-objects -v
 270        ) > count.shallow2 &&
 271        grep "^in-pack: 6" count.shallow2
 272'
 273
 274test_expect_success 'clone shallow with --branch' '
 275        git clone --depth 1 --branch A "file://$(pwd)/." shallow3
 276'
 277
 278test_expect_success 'clone shallow object count' '
 279        echo "in-pack: 12" > count3.expected &&
 280        GIT_DIR=shallow3/.git git count-objects -v |
 281                grep "^in-pack" > count3.actual &&
 282        test_cmp count3.expected count3.actual
 283'
 284
 285test_expect_success 'clone shallow with nonexistent --branch' '
 286        git clone --depth 1 --branch Z "file://$(pwd)/." shallow4 &&
 287        GIT_DIR=shallow4/.git git rev-parse HEAD >actual &&
 288        git rev-parse HEAD >expected &&
 289        test_cmp expected actual
 290'
 291
 292test_expect_success 'clone shallow with detached HEAD' '
 293        git checkout HEAD^ &&
 294        git clone --depth 1 "file://$(pwd)/." shallow5 &&
 295        git checkout - &&
 296        GIT_DIR=shallow5/.git git rev-parse HEAD >actual &&
 297        git rev-parse HEAD^ >expected &&
 298        test_cmp expected actual
 299'
 300
 301test_expect_success 'shallow clone pulling tags' '
 302        git tag -a -m A TAGA1 A &&
 303        git tag -a -m B TAGB1 B &&
 304        git tag TAGA2 A &&
 305        git tag TAGB2 B &&
 306        git clone --depth 1 "file://$(pwd)/." shallow6 &&
 307
 308        cat >taglist.expected <<\EOF &&
 309TAGB1
 310TAGB2
 311EOF
 312        GIT_DIR=shallow6/.git git tag -l >taglist.actual &&
 313        test_cmp taglist.expected taglist.actual &&
 314
 315        echo "in-pack: 7" > count6.expected &&
 316        GIT_DIR=shallow6/.git git count-objects -v |
 317                grep "^in-pack" > count6.actual &&
 318        test_cmp count6.expected count6.actual
 319'
 320
 321test_done