[PATCH] Missing test_done
[git.git] / t / t5300-pack-object.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2005 Junio C Hamano
4 #
5
6 test_description='git-pack-object
7
8 '
9 . ./test-lib.sh
10
11 TRASH=`pwd`
12
13 test_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-cache --add $i || exit
20      done &&
21      cat c >d && echo foo >>d && git-update-cache --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 || exit 1
33          done <obj-list
34      } >expect'
35
36 test_expect_success \
37     'pack without delta' \
38     'packname_1=$(git-pack-objects --window=0 test-1 <obj-list)'
39
40 rm -fr .git2
41 mkdir .git2
42
43 test_expect_success \
44     'unpack without delta' \
45     "GIT_OBJECT_DIRECTORY=.git2/objects &&
46      export GIT_OBJECT_DIRECTORY &&
47      git-init-db &&
48      git-unpack-objects -n <test-1-${packname_1}.pack &&
49      git-unpack-objects <test-1-${packname_1}.pack"
50
51 unset GIT_OBJECT_DIRECTORY
52 cd $TRASH/.git2
53
54 test_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              exit 1
62          }
63      done'
64 cd $TRASH
65
66 test_expect_success \
67     'pack with delta' \
68     'pwd &&
69      packname_2=$(git-pack-objects test-2 <obj-list)'
70
71 rm -fr .git2
72 mkdir .git2
73
74 test_expect_success \
75     'unpack with delta' \
76     'GIT_OBJECT_DIRECTORY=.git2/objects &&
77      export GIT_OBJECT_DIRECTORY &&
78      git-init-db &&
79      git-unpack-objects -n <test-2-${packname_2}.pack &&
80      git-unpack-objects <test-2-${packname_2}.pack'
81
82 unset GIT_OBJECT_DIRECTORY
83 cd $TRASH/.git2
84 test_expect_success \
85     'check unpack with 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              exit 1
92          }
93      done'
94 cd $TRASH
95
96 rm -fr .git2
97 mkdir .git2
98
99 test_expect_success \
100     'use packed objects' \
101     'GIT_OBJECT_DIRECTORY=.git2/objects &&
102      export GIT_OBJECT_DIRECTORY &&
103      git-init-db &&
104      cp test-1-${packname_1}.pack test-1-${packname_1}.idx .git2/objects/pack && {
105          git-diff-tree --root -p $commit &&
106          while read object
107          do
108             t=`git-cat-file -t $object` &&
109             git-cat-file $t $object || exit 1
110          done <obj-list
111     } >current &&
112     diff expect current'
113
114
115 test_expect_success \
116     'use packed deltified objects' \
117     'GIT_OBJECT_DIRECTORY=.git2/objects &&
118      export GIT_OBJECT_DIRECTORY &&
119      rm -f .git2/objects/pack/test-?.idx &&
120      cp test-2-${packname_2}.pack test-2-${packname_2}.idx .git2/objects/pack && {
121          git-diff-tree --root -p $commit &&
122          while read object
123          do
124             t=`git-cat-file -t $object` &&
125             git-cat-file $t $object || exit 1
126          done <obj-list
127     } >current &&
128     diff expect current'
129
130 unset GIT_OBJECT_DIRECTORY
131
132 test_expect_success \
133     'verify pack' \
134     'git-verify-pack test-1-${packname_1}.idx test-2-${packname_2}.idx'
135
136 test_expect_success \
137     'corrupt a pack and see if verify catches' \
138     'cp test-1-${packname_1}.idx test-3.idx &&
139      cp test-2-${packname_2}.pack test-3.pack &&
140      if git-verify-pack test-3.idx
141      then false
142      else :;
143      fi &&
144
145      cp test-1-${packname_1}.pack test-3.pack &&
146      dd if=/dev/zero of=test-3.pack count=1 bs=1 conv=notrunc seek=2 &&
147      if git-verify-pack test-3.idx
148      then false
149      else :;
150      fi &&
151
152      cp test-1-${packname_1}.pack test-3.pack &&
153      dd if=/dev/zero of=test-3.pack count=1 bs=1 conv=notrunc seek=7 &&
154      if git-verify-pack test-3.idx
155      then false
156      else :;
157      fi &&
158
159      cp test-1-${packname_1}.pack test-3.pack &&
160      dd if=/dev/zero of=test-3.pack count=1 bs=1 conv=notrunc seek=12 &&
161      if git-verify-pack test-3.idx
162      then false
163      else :;
164      fi &&
165
166      :'
167
168 test_done