t / t5300-pack-object.shon commit Change xdl_merge to generate output even for null merges (5719db9)
   1#!/bin/sh
   2#
   3# Copyright (c) 2005 Junio C Hamano
   4#
   5
   6test_description='git pack-object
   7
   8'
   9. ./test-lib.sh
  10
  11TRASH=`pwd`
  12
  13test_expect_success \
  14    'setup' \
  15    'rm -f .git/index*
  16     for i in a b c
  17     do
  18             dd if=/dev/zero bs=4k count=1 | perl -pe "y/\\000/$i/" >$i &&
  19             git update-index --add $i || return 1
  20     done &&
  21     cat c >d && echo foo >>d && git update-index --add d &&
  22     tree=`git write-tree` &&
  23     commit=`git commit-tree $tree </dev/null` && {
  24         echo $tree &&
  25         echo $commit &&
  26         git ls-tree $tree | sed -e "s/.* \\([0-9a-f]*\\)       .*/\\1/"
  27     } >obj-list && {
  28         git diff-tree --root -p $commit &&
  29         while read object
  30         do
  31            t=`git cat-file -t $object` &&
  32            git cat-file $t $object || return 1
  33         done <obj-list
  34     } >expect'
  35
  36test_expect_success \
  37    'pack without delta' \
  38    'packname_1=$(git pack-objects --window=0 test-1 <obj-list)'
  39
  40rm -fr .git2
  41mkdir .git2
  42
  43test_expect_success \
  44    'unpack without delta' \
  45    "GIT_OBJECT_DIRECTORY=.git2/objects &&
  46     export GIT_OBJECT_DIRECTORY &&
  47     git init &&
  48     git unpack-objects -n <test-1-${packname_1}.pack &&
  49     git unpack-objects <test-1-${packname_1}.pack"
  50
  51unset GIT_OBJECT_DIRECTORY
  52cd "$TRASH/.git2"
  53
  54test_expect_success \
  55    'check unpack without delta' \
  56    '(cd ../.git && find objects -type f -print) |
  57     while read path
  58     do
  59         cmp $path ../.git/$path || {
  60             echo $path differs.
  61             return 1
  62         }
  63     done'
  64cd "$TRASH"
  65
  66test_expect_success \
  67    'pack with REF_DELTA' \
  68    'pwd &&
  69     packname_2=$(git pack-objects test-2 <obj-list)'
  70
  71rm -fr .git2
  72mkdir .git2
  73
  74test_expect_success \
  75    'unpack with REF_DELTA' \
  76    'GIT_OBJECT_DIRECTORY=.git2/objects &&
  77     export GIT_OBJECT_DIRECTORY &&
  78     git init &&
  79     git unpack-objects -n <test-2-${packname_2}.pack &&
  80     git unpack-objects <test-2-${packname_2}.pack'
  81
  82unset GIT_OBJECT_DIRECTORY
  83cd "$TRASH/.git2"
  84test_expect_success \
  85    'check unpack with REF_DELTA' \
  86    '(cd ../.git && find objects -type f -print) |
  87     while read path
  88     do
  89         cmp $path ../.git/$path || {
  90             echo $path differs.
  91             return 1
  92         }
  93     done'
  94cd "$TRASH"
  95
  96test_expect_success \
  97    'pack with OFS_DELTA' \
  98    'pwd &&
  99     packname_3=$(git pack-objects --delta-base-offset test-3 <obj-list)'
 100
 101rm -fr .git2
 102mkdir .git2
 103
 104test_expect_success \
 105    'unpack with OFS_DELTA' \
 106    'GIT_OBJECT_DIRECTORY=.git2/objects &&
 107     export GIT_OBJECT_DIRECTORY &&
 108     git init &&
 109     git unpack-objects -n <test-3-${packname_3}.pack &&
 110     git unpack-objects <test-3-${packname_3}.pack'
 111
 112unset GIT_OBJECT_DIRECTORY
 113cd "$TRASH/.git2"
 114test_expect_success \
 115    'check unpack with OFS_DELTA' \
 116    '(cd ../.git && find objects -type f -print) |
 117     while read path
 118     do
 119         cmp $path ../.git/$path || {
 120             echo $path differs.
 121             return 1
 122         }
 123     done'
 124cd "$TRASH"
 125
 126test_expect_success 'compare delta flavors' '
 127        perl -e '\''
 128                defined($_ = -s $_) or die for @ARGV;
 129                exit 1 if $ARGV[0] <= $ARGV[1];
 130        '\'' test-2-$packname_2.pack test-3-$packname_3.pack
 131'
 132
 133rm -fr .git2
 134mkdir .git2
 135
 136test_expect_success \
 137    'use packed objects' \
 138    'GIT_OBJECT_DIRECTORY=.git2/objects &&
 139     export GIT_OBJECT_DIRECTORY &&
 140     git init &&
 141     cp test-1-${packname_1}.pack test-1-${packname_1}.idx .git2/objects/pack && {
 142         git diff-tree --root -p $commit &&
 143         while read object
 144         do
 145            t=`git cat-file -t $object` &&
 146            git cat-file $t $object || return 1
 147         done <obj-list
 148    } >current &&
 149    diff expect current'
 150
 151test_expect_success \
 152    'use packed deltified (REF_DELTA) objects' \
 153    'GIT_OBJECT_DIRECTORY=.git2/objects &&
 154     export GIT_OBJECT_DIRECTORY &&
 155     rm -f .git2/objects/pack/test-* &&
 156     cp test-2-${packname_2}.pack test-2-${packname_2}.idx .git2/objects/pack && {
 157         git diff-tree --root -p $commit &&
 158         while read object
 159         do
 160            t=`git cat-file -t $object` &&
 161            git cat-file $t $object || return 1
 162         done <obj-list
 163    } >current &&
 164    diff expect current'
 165
 166test_expect_success \
 167    'use packed deltified (OFS_DELTA) objects' \
 168    'GIT_OBJECT_DIRECTORY=.git2/objects &&
 169     export GIT_OBJECT_DIRECTORY &&
 170     rm -f .git2/objects/pack/test-* &&
 171     cp test-3-${packname_3}.pack test-3-${packname_3}.idx .git2/objects/pack && {
 172         git diff-tree --root -p $commit &&
 173         while read object
 174         do
 175            t=`git cat-file -t $object` &&
 176            git cat-file $t $object || return 1
 177         done <obj-list
 178    } >current &&
 179    diff expect current'
 180
 181unset GIT_OBJECT_DIRECTORY
 182
 183test_expect_success \
 184    'verify pack' \
 185    'git verify-pack    test-1-${packname_1}.idx \
 186                        test-2-${packname_2}.idx \
 187                        test-3-${packname_3}.idx'
 188
 189test_expect_success \
 190    'verify pack -v' \
 191    'git verify-pack -v test-1-${packname_1}.idx \
 192                        test-2-${packname_2}.idx \
 193                        test-3-${packname_3}.idx'
 194
 195test_expect_success \
 196    'verify-pack catches mismatched .idx and .pack files' \
 197    'cat test-1-${packname_1}.idx >test-3.idx &&
 198     cat test-2-${packname_2}.pack >test-3.pack &&
 199     if git verify-pack test-3.idx
 200     then false
 201     else :;
 202     fi'
 203
 204test_expect_success \
 205    'verify-pack catches a corrupted pack signature' \
 206    'cat test-1-${packname_1}.pack >test-3.pack &&
 207     dd if=/dev/zero of=test-3.pack count=1 bs=1 conv=notrunc seek=2 &&
 208     if git verify-pack test-3.idx
 209     then false
 210     else :;
 211     fi'
 212
 213test_expect_success \
 214    'verify-pack catches a corrupted pack version' \
 215    'cat test-1-${packname_1}.pack >test-3.pack &&
 216     dd if=/dev/zero of=test-3.pack count=1 bs=1 conv=notrunc seek=7 &&
 217     if git verify-pack test-3.idx
 218     then false
 219     else :;
 220     fi'
 221
 222test_expect_success \
 223    'verify-pack catches a corrupted type/size of the 1st packed object data' \
 224    'cat test-1-${packname_1}.pack >test-3.pack &&
 225     dd if=/dev/zero of=test-3.pack count=1 bs=1 conv=notrunc seek=12 &&
 226     if git verify-pack test-3.idx
 227     then false
 228     else :;
 229     fi'
 230
 231test_expect_success \
 232    'verify-pack catches a corrupted sum of the index file itself' \
 233    'l=`wc -c <test-3.idx` &&
 234     l=`expr $l - 20` &&
 235     cat test-1-${packname_1}.pack >test-3.pack &&
 236     dd if=/dev/zero of=test-3.idx count=20 bs=1 conv=notrunc seek=$l &&
 237     if git verify-pack test-3.pack
 238     then false
 239     else :;
 240     fi'
 241
 242test_expect_success \
 243    'build pack index for an existing pack' \
 244    'cat test-1-${packname_1}.pack >test-3.pack &&
 245     git index-pack -o tmp.idx test-3.pack &&
 246     cmp tmp.idx test-1-${packname_1}.idx &&
 247
 248     git index-pack test-3.pack &&
 249     cmp test-3.idx test-1-${packname_1}.idx &&
 250
 251     cat test-2-${packname_2}.pack >test-3.pack &&
 252     git index-pack -o tmp.idx test-2-${packname_2}.pack &&
 253     cmp tmp.idx test-2-${packname_2}.idx &&
 254
 255     git index-pack test-3.pack &&
 256     cmp test-3.idx test-2-${packname_2}.idx &&
 257
 258     cat test-3-${packname_3}.pack >test-3.pack &&
 259     git index-pack -o tmp.idx test-3-${packname_3}.pack &&
 260     cmp tmp.idx test-3-${packname_3}.idx &&
 261
 262     git index-pack test-3.pack &&
 263     cmp test-3.idx test-3-${packname_3}.idx &&
 264
 265     :'
 266
 267test_expect_success \
 268    'fake a SHA1 hash collision' \
 269    'test -f    .git/objects/c8/2de19312b6c3695c0c18f70709a6c535682a67 &&
 270     cp -f      .git/objects/9d/235ed07cd19811a6ceb342de82f190e49c9f68 \
 271                .git/objects/c8/2de19312b6c3695c0c18f70709a6c535682a67'
 272
 273test_expect_success \
 274    'make sure index-pack detects the SHA1 collision' \
 275    'test_must_fail git index-pack -o bad.idx test-3.pack'
 276
 277test_expect_success \
 278    'honor pack.packSizeLimit' \
 279    'git config pack.packSizeLimit 200 &&
 280     packname_4=$(git pack-objects test-4 <obj-list) &&
 281     test 3 = $(ls test-4-*.pack | wc -l)'
 282
 283test_expect_success 'unpacking with --strict' '
 284
 285        git config --unset pack.packsizelimit &&
 286        for j in a b c d e f g
 287        do
 288                for i in 0 1 2 3 4 5 6 7 8 9
 289                do
 290                        o=$(echo $j$i | git hash-object -w --stdin) &&
 291                        echo "100644 $o 0 $j$i"
 292                done
 293        done >LIST &&
 294        rm -f .git/index &&
 295        git update-index --index-info <LIST &&
 296        LIST=$(git write-tree) &&
 297        rm -f .git/index &&
 298        head -n 10 LIST | git update-index --index-info &&
 299        LI=$(git write-tree) &&
 300        rm -f .git/index &&
 301        tail -n 10 LIST | git update-index --index-info &&
 302        ST=$(git write-tree) &&
 303        PACK5=$( git rev-list --objects "$LIST" "$LI" "$ST" | \
 304                git pack-objects test-5 ) &&
 305        PACK6=$( (
 306                        echo "$LIST"
 307                        echo "$LI"
 308                        echo "$ST"
 309                 ) | git pack-objects test-6 ) &&
 310        test_create_repo test-5 &&
 311        (
 312                cd test-5 &&
 313                git unpack-objects --strict <../test-5-$PACK5.pack &&
 314                git ls-tree -r $LIST &&
 315                git ls-tree -r $LI &&
 316                git ls-tree -r $ST
 317        ) &&
 318        test_create_repo test-6 &&
 319        (
 320                # tree-only into empty repo -- many unreachables
 321                cd test-6 &&
 322                test_must_fail git unpack-objects --strict <../test-6-$PACK6.pack
 323        ) &&
 324        (
 325                # already populated -- no unreachables
 326                cd test-5 &&
 327                git unpack-objects --strict <../test-6-$PACK6.pack
 328        )
 329'
 330
 331test_expect_success 'index-pack with --strict' '
 332
 333        for j in a b c d e f g
 334        do
 335                for i in 0 1 2 3 4 5 6 7 8 9
 336                do
 337                        o=$(echo $j$i | git hash-object -w --stdin) &&
 338                        echo "100644 $o 0 $j$i"
 339                done
 340        done >LIST &&
 341        rm -f .git/index &&
 342        git update-index --index-info <LIST &&
 343        LIST=$(git write-tree) &&
 344        rm -f .git/index &&
 345        head -n 10 LIST | git update-index --index-info &&
 346        LI=$(git write-tree) &&
 347        rm -f .git/index &&
 348        tail -n 10 LIST | git update-index --index-info &&
 349        ST=$(git write-tree) &&
 350        PACK5=$( git rev-list --objects "$LIST" "$LI" "$ST" | \
 351                git pack-objects test-5 ) &&
 352        PACK6=$( (
 353                        echo "$LIST"
 354                        echo "$LI"
 355                        echo "$ST"
 356                 ) | git pack-objects test-6 ) &&
 357        test_create_repo test-7 &&
 358        (
 359                cd test-7 &&
 360                git index-pack --strict --stdin <../test-5-$PACK5.pack &&
 361                git ls-tree -r $LIST &&
 362                git ls-tree -r $LI &&
 363                git ls-tree -r $ST
 364        ) &&
 365        test_create_repo test-8 &&
 366        (
 367                # tree-only into empty repo -- many unreachables
 368                cd test-8 &&
 369                test_must_fail git index-pack --strict --stdin <../test-6-$PACK6.pack
 370        ) &&
 371        (
 372                # already populated -- no unreachables
 373                cd test-7 &&
 374                git index-pack --strict --stdin <../test-6-$PACK6.pack
 375        )
 376'
 377
 378test_expect_success 'tolerate absurdly small packsizelimit' '
 379        git config pack.packSizeLimit 2 &&
 380        packname_9=$(git pack-objects test-9 <obj-list) &&
 381        test $(wc -l <obj-list) = $(ls test-9-*.pack | wc -l)
 382'
 383
 384test_done