t / t5300-pack-object.shon commit Bisect: implement "git bisect run <cmd>..." to automatically bisect. (a17c410)
   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 | tr "\\0" $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 \
 127    'compare delta flavors' \
 128    'size_2=`stat -c "%s" test-2-${packname_2}.pack` &&
 129     size_3=`stat -c "%s" test-3-${packname_3}.pack` &&
 130     test $size_2 -gt $size_3'
 131
 132rm -fr .git2
 133mkdir .git2
 134
 135test_expect_success \
 136    'use packed objects' \
 137    'GIT_OBJECT_DIRECTORY=.git2/objects &&
 138     export GIT_OBJECT_DIRECTORY &&
 139     git-init &&
 140     cp test-1-${packname_1}.pack test-1-${packname_1}.idx .git2/objects/pack && {
 141         git-diff-tree --root -p $commit &&
 142         while read object
 143         do
 144            t=`git-cat-file -t $object` &&
 145            git-cat-file $t $object || return 1
 146         done <obj-list
 147    } >current &&
 148    diff expect current'
 149
 150test_expect_success \
 151    'use packed deltified (REF_DELTA) objects' \
 152    'GIT_OBJECT_DIRECTORY=.git2/objects &&
 153     export GIT_OBJECT_DIRECTORY &&
 154     rm .git2/objects/pack/test-* &&
 155     cp test-2-${packname_2}.pack test-2-${packname_2}.idx .git2/objects/pack && {
 156         git-diff-tree --root -p $commit &&
 157         while read object
 158         do
 159            t=`git-cat-file -t $object` &&
 160            git-cat-file $t $object || return 1
 161         done <obj-list
 162    } >current &&
 163    diff expect current'
 164
 165test_expect_success \
 166    'use packed deltified (OFS_DELTA) objects' \
 167    'GIT_OBJECT_DIRECTORY=.git2/objects &&
 168     export GIT_OBJECT_DIRECTORY &&
 169     rm .git2/objects/pack/test-* &&
 170     cp test-3-${packname_3}.pack test-3-${packname_3}.idx .git2/objects/pack && {
 171         git-diff-tree --root -p $commit &&
 172         while read object
 173         do
 174            t=`git-cat-file -t $object` &&
 175            git-cat-file $t $object || return 1
 176         done <obj-list
 177    } >current &&
 178    diff expect current'
 179
 180unset GIT_OBJECT_DIRECTORY
 181
 182test_expect_success \
 183    'verify pack' \
 184    'git-verify-pack    test-1-${packname_1}.idx \
 185                        test-2-${packname_2}.idx \
 186                        test-3-${packname_3}.idx'
 187
 188test_expect_success \
 189    'corrupt a pack and see if verify catches' \
 190    'cp test-1-${packname_1}.idx test-3.idx &&
 191     cp test-2-${packname_2}.pack test-3.pack &&
 192     if git-verify-pack test-3.idx
 193     then false
 194     else :;
 195     fi &&
 196
 197     : PACK_SIGNATURE &&
 198     cp test-1-${packname_1}.pack test-3.pack &&
 199     dd if=/dev/zero of=test-3.pack count=1 bs=1 conv=notrunc seek=2 &&
 200     if git-verify-pack test-3.idx
 201     then false
 202     else :;
 203     fi &&
 204
 205     : PACK_VERSION &&
 206     cp test-1-${packname_1}.pack test-3.pack &&
 207     dd if=/dev/zero of=test-3.pack count=1 bs=1 conv=notrunc seek=7 &&
 208     if git-verify-pack test-3.idx
 209     then false
 210     else :;
 211     fi &&
 212
 213     : TYPE/SIZE byte of the first packed object data &&
 214     cp test-1-${packname_1}.pack test-3.pack &&
 215     dd if=/dev/zero of=test-3.pack count=1 bs=1 conv=notrunc seek=12 &&
 216     if git-verify-pack test-3.idx
 217     then false
 218     else :;
 219     fi &&
 220
 221     : sum of the index file itself &&
 222     l=`wc -c <test-3.idx` &&
 223     l=`expr $l - 20` &&
 224     cp test-1-${packname_1}.pack test-3.pack &&
 225     dd if=/dev/zero of=test-3.idx count=20 bs=1 conv=notrunc seek=$l &&
 226     if git-verify-pack test-3.pack
 227     then false
 228     else :;
 229     fi &&
 230
 231     :'
 232
 233test_expect_success \
 234    'build pack index for an existing pack' \
 235    'cp test-1-${packname_1}.pack test-3.pack &&
 236     git-index-pack -o tmp.idx test-3.pack &&
 237     cmp tmp.idx test-1-${packname_1}.idx &&
 238
 239     git-index-pack test-3.pack &&
 240     cmp test-3.idx test-1-${packname_1}.idx &&
 241
 242     cp test-2-${packname_2}.pack test-3.pack &&
 243     git-index-pack -o tmp.idx test-2-${packname_2}.pack &&
 244     cmp tmp.idx test-2-${packname_2}.idx &&
 245
 246     git-index-pack test-3.pack &&
 247     cmp test-3.idx test-2-${packname_2}.idx &&
 248
 249     cp test-3-${packname_3}.pack test-3.pack &&
 250     git-index-pack -o tmp.idx test-3-${packname_3}.pack &&
 251     cmp tmp.idx test-3-${packname_3}.idx &&
 252
 253     git-index-pack test-3.pack &&
 254     cmp test-3.idx test-3-${packname_3}.idx &&
 255
 256     :'
 257
 258test_expect_success \
 259    'fake a SHA1 hash collision' \
 260    'test -f    .git/objects/c8/2de19312b6c3695c0c18f70709a6c535682a67 &&
 261     cp -f      .git/objects/9d/235ed07cd19811a6ceb342de82f190e49c9f68 \
 262                .git/objects/c8/2de19312b6c3695c0c18f70709a6c535682a67'
 263
 264test_expect_failure \
 265    'make sure index-pack detects the SHA1 collision' \
 266    'git-index-pack -o bad.idx test-3.pack'
 267
 268test_done