[PATCH] Add git-verify-pack command.
[git/jrn.git] / t / t5300-pack-object.sh
blobd9931201204f72a3a5c532b112a95e002a266da3
1 #!/bin/sh
3 # Copyright (c) 2005 Junio C Hamano
6 test_description='git-pack-object
9 . ./test-lib.sh
11 TRASH=`pwd`
13 test_expect_success \
14 'setup' \
15 'rm -f .git/index*
16 for i in a b c
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
31 t=`git-cat-file -t $object` &&
32 git-cat-file $t $object || exit 1
33 done <obj-list
34 } >expect'
36 test_expect_success \
37 'pack without delta' \
38 'git-pack-objects --window=0 test-1 <obj-list'
40 rm -fr .git2
41 mkdir .git2
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 test-1'
50 unset GIT_OBJECT_DIRECTORY
51 cd $TRASH/.git2
53 test_expect_success \
54 'check unpack without delta' \
55 '(cd ../.git && find objects -type f -print) |
56 while read path
58 cmp $path ../.git/$path || {
59 echo $path differs.
60 exit 1
62 done'
63 cd $TRASH
65 test_expect_success \
66 'pack with delta' \
67 'pwd &&
68 git-pack-objects test-2 <obj-list'
70 rm -fr .git2
71 mkdir .git2
73 test_expect_success \
74 'unpack with delta' \
75 'GIT_OBJECT_DIRECTORY=.git2/objects &&
76 export GIT_OBJECT_DIRECTORY &&
77 git-init-db &&
78 git-unpack-objects test-2'
80 unset GIT_OBJECT_DIRECTORY
81 cd $TRASH/.git2
82 test_expect_success \
83 'check unpack with delta' \
84 '(cd ../.git && find objects -type f -print) |
85 while read path
87 cmp $path ../.git/$path || {
88 echo $path differs.
89 exit 1
91 done'
92 cd $TRASH
94 rm -fr .git2
95 mkdir .git2
97 test_expect_success \
98 'use packed objects' \
99 'GIT_OBJECT_DIRECTORY=.git2/objects &&
100 export GIT_OBJECT_DIRECTORY &&
101 git-init-db &&
102 cp test-1.pack test-1.idx .git2/objects/pack && {
103 git-diff-tree --root -p $commit &&
104 while read object
106 t=`git-cat-file -t $object` &&
107 git-cat-file $t $object || exit 1
108 done <obj-list
109 } >current &&
110 diff expect current'
113 test_expect_success \
114 'use packed deltified objects' \
115 'GIT_OBJECT_DIRECTORY=.git2/objects &&
116 export GIT_OBJECT_DIRECTORY &&
117 rm -f .git2/objects/pack/test-?.idx &&
118 cp test-2.pack test-2.idx .git2/objects/pack && {
119 git-diff-tree --root -p $commit &&
120 while read object
122 t=`git-cat-file -t $object` &&
123 git-cat-file $t $object || exit 1
124 done <obj-list
125 } >current &&
126 diff expect current'
128 unset GIT_OBJECT_DIRECTORY
130 test_expect_success \
131 'verify pack' \
132 'git-verify-pack test-1.idx test-2.idx'
134 test_expect_success \
135 'corrupt a pack and see if verify catches' \
136 'cp test-1.idx test-3.idx &&
137 cp test-2.pack test-3.pack &&
138 if git-verify-pack test-3.idx
139 then false
140 else :;
141 fi &&
143 cp test-1.pack test-3.pack &&
144 dd if=/dev/zero of=test-3.pack count=1 bs=1 conv=notrunc seek=2 &&
145 if git-verify-pack test-3.idx
146 then false
147 else :;
148 fi &&
150 cp test-1.pack test-3.pack &&
151 dd if=/dev/zero of=test-3.pack count=1 bs=1 conv=notrunc seek=7 &&
152 if git-verify-pack test-3.idx
153 then false
154 else :;
155 fi &&
157 cp test-1.pack test-3.pack &&
158 dd if=/dev/zero of=test-3.pack count=1 bs=1 conv=notrunc seek=12 &&
159 if git-verify-pack test-3.idx
160 then false
161 else :;
162 fi &&
166 test_done