t / t5500-fetch-pack.shon commit Merge branch 'jc/maint-svn-info-test-fix' (f1f7677)
   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 "B 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 "B" $((64*3))
 114
 115pull_to_client 3rd "A" $((1*3))
 116
 117test_expect_success 'clone shallow' '
 118        git clone --depth 2 "file://$(pwd)/." shallow
 119'
 120
 121test_expect_success 'clone shallow object count' '
 122        (
 123                cd shallow &&
 124                git count-objects -v
 125        ) > count.shallow &&
 126        grep "^in-pack: 18" count.shallow
 127'
 128
 129test_expect_success 'clone shallow object count (part 2)' '
 130        sed -e "/^in-pack:/d" -e "/^packs:/d" -e "/^size-pack:/d" \
 131            -e "/: 0$/d" count.shallow > count_output &&
 132        ! test -s count_output
 133'
 134
 135test_expect_success 'fsck in shallow repo' '
 136        (
 137                cd shallow &&
 138                git fsck --full
 139        )
 140'
 141
 142test_expect_success 'simple fetch in shallow repo' '
 143        (
 144                cd shallow &&
 145                git fetch
 146        )
 147'
 148
 149test_expect_success 'no changes expected' '
 150        (
 151                cd shallow &&
 152                git count-objects -v
 153        ) > count.shallow.2 &&
 154        cmp count.shallow count.shallow.2
 155'
 156
 157test_expect_success 'fetch same depth in shallow repo' '
 158        (
 159                cd shallow &&
 160                git fetch --depth=2
 161        )
 162'
 163
 164test_expect_success 'no changes expected' '
 165        (
 166                cd shallow &&
 167                git count-objects -v
 168        ) > count.shallow.3 &&
 169        cmp count.shallow count.shallow.3
 170'
 171
 172test_expect_success 'add two more' '
 173        add B66 $B65 &&
 174        add B67 $B66
 175'
 176
 177test_expect_success 'pull in shallow repo' '
 178        (
 179                cd shallow &&
 180                git pull .. B
 181        )
 182'
 183
 184test_expect_success 'clone shallow object count' '
 185        (
 186                cd shallow &&
 187                git count-objects -v
 188        ) > count.shallow &&
 189        grep "^count: 6" count.shallow
 190'
 191
 192test_expect_success 'add two more (part 2)' '
 193        add B68 $B67 &&
 194        add B69 $B68
 195'
 196
 197test_expect_success 'deepening pull in shallow repo' '
 198        (
 199                cd shallow &&
 200                git pull --depth 4 .. B
 201        )
 202'
 203
 204test_expect_success 'clone shallow object count' '
 205        (
 206                cd shallow &&
 207                git count-objects -v
 208        ) > count.shallow &&
 209        grep "^count: 12" count.shallow
 210'
 211
 212test_expect_success 'deepening fetch in shallow repo' '
 213        (
 214                cd shallow &&
 215                git fetch --depth 4 .. A:A
 216        )
 217'
 218
 219test_expect_success 'clone shallow object count' '
 220        (
 221                cd shallow &&
 222                git count-objects -v
 223        ) > count.shallow &&
 224        grep "^count: 18" count.shallow
 225'
 226
 227test_expect_success 'pull in shallow repo with missing merge base' '
 228        (
 229                cd shallow &&
 230                test_must_fail git pull --depth 4 .. A
 231        )
 232'
 233
 234test_expect_success 'additional simple shallow deepenings' '
 235        (
 236                cd shallow &&
 237                git fetch --depth=8 &&
 238                git fetch --depth=10 &&
 239                git fetch --depth=11
 240        )
 241'
 242
 243test_expect_success 'clone shallow object count' '
 244        (
 245                cd shallow &&
 246                git count-objects -v
 247        ) > count.shallow &&
 248        grep "^count: 52" count.shallow
 249'
 250
 251test_done