t / t5500-fetch-pack.shon commit git p4 test: rename some "git-p4 command" strings (a64f732)
   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 detached HEAD' '
 286        git checkout HEAD^ &&
 287        git clone --depth 1 "file://$(pwd)/." shallow5 &&
 288        git checkout - &&
 289        GIT_DIR=shallow5/.git git rev-parse HEAD >actual &&
 290        git rev-parse HEAD^ >expected &&
 291        test_cmp expected actual
 292'
 293
 294test_expect_success 'shallow clone pulling tags' '
 295        git tag -a -m A TAGA1 A &&
 296        git tag -a -m B TAGB1 B &&
 297        git tag TAGA2 A &&
 298        git tag TAGB2 B &&
 299        git clone --depth 1 "file://$(pwd)/." shallow6 &&
 300
 301        cat >taglist.expected <<\EOF &&
 302TAGB1
 303TAGB2
 304EOF
 305        GIT_DIR=shallow6/.git git tag -l >taglist.actual &&
 306        test_cmp taglist.expected taglist.actual &&
 307
 308        echo "in-pack: 7" > count6.expected &&
 309        GIT_DIR=shallow6/.git git count-objects -v |
 310                grep "^in-pack" > count6.actual &&
 311        test_cmp count6.expected count6.actual
 312'
 313
 314test_expect_success 'shallow cloning single tag' '
 315        git clone --depth 1 --branch=TAGB1 "file://$(pwd)/." shallow7 &&
 316        cat >taglist.expected <<\EOF &&
 317TAGB1
 318TAGB2
 319EOF
 320        GIT_DIR=shallow7/.git git tag -l >taglist.actual &&
 321        test_cmp taglist.expected taglist.actual &&
 322
 323        echo "in-pack: 7" > count7.expected &&
 324        GIT_DIR=shallow7/.git git count-objects -v |
 325                grep "^in-pack" > count7.actual &&
 326        test_cmp count7.expected count7.actual
 327'
 328
 329test_expect_success 'setup tests for the --stdin parameter' '
 330        for head in C D E F
 331        do
 332                add $head
 333        done &&
 334        for head in A B C D E F
 335        do
 336                git tag $head $head
 337        done &&
 338        cat >input <<-\EOF
 339        refs/heads/C
 340        refs/heads/A
 341        refs/heads/D
 342        refs/tags/C
 343        refs/heads/B
 344        refs/tags/A
 345        refs/heads/E
 346        refs/tags/B
 347        refs/tags/E
 348        refs/tags/D
 349        EOF
 350        sort <input >expect &&
 351        (
 352                echo refs/heads/E &&
 353                echo refs/tags/E &&
 354                cat input
 355        ) >input.dup
 356'
 357
 358test_expect_success 'fetch refs from cmdline' '
 359        (
 360                cd client &&
 361                git fetch-pack --no-progress .. $(cat ../input)
 362        ) >output &&
 363        cut -d " " -f 2 <output | sort >actual &&
 364        test_cmp expect actual
 365'
 366
 367test_expect_success 'fetch refs from stdin' '
 368        (
 369                cd client &&
 370                git fetch-pack --stdin --no-progress .. <../input
 371        ) >output &&
 372        cut -d " " -f 2 <output | sort >actual &&
 373        test_cmp expect actual
 374'
 375
 376test_expect_success 'fetch mixed refs from cmdline and stdin' '
 377        (
 378                cd client &&
 379                tail -n +5 ../input |
 380                git fetch-pack --stdin --no-progress .. $(head -n 4 ../input)
 381        ) >output &&
 382        cut -d " " -f 2 <output | sort >actual &&
 383        test_cmp expect actual
 384'
 385
 386test_expect_success 'test duplicate refs from stdin' '
 387        (
 388        cd client &&
 389        test_must_fail git fetch-pack --stdin --no-progress .. <../input.dup
 390        ) >output &&
 391        cut -d " " -f 2 <output | sort >actual &&
 392        test_cmp expect actual
 393'
 394
 395test_done