]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5300-pack-object.sh
use 'init' instead of 'init-db' for shipped docs and tools
[thirdparty/git.git] / t / t5300-pack-object.sh
CommitLineData
8ee378a0
JH
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 &&
215a7ad1 19 git-update-index --add $i || return 1
8ee378a0 20 done &&
215a7ad1 21 cat c >d && echo foo >>d && git-update-index --add d &&
1f688557
JH
22 tree=`git-write-tree` &&
23 commit=`git-commit-tree $tree </dev/null` && {
8ee378a0 24 echo $tree &&
1f688557 25 echo $commit &&
8ee378a0 26 git-ls-tree $tree | sed -e "s/.* \\([0-9a-f]*\\) .*/\\1/"
1f688557
JH
27 } >obj-list && {
28 git-diff-tree --root -p $commit &&
29 while read object
30 do
31 t=`git-cat-file -t $object` &&
4d9d62fa 32 git-cat-file $t $object || return 1
1f688557
JH
33 done <obj-list
34 } >expect'
8ee378a0
JH
35
36test_expect_success \
37 'pack without delta' \
a61eea6a 38 'packname_1=$(git-pack-objects --window=0 test-1 <obj-list)'
8ee378a0
JH
39
40rm -fr .git2
41mkdir .git2
42
43test_expect_success \
44 'unpack without delta' \
a61eea6a 45 "GIT_OBJECT_DIRECTORY=.git2/objects &&
8ee378a0 46 export GIT_OBJECT_DIRECTORY &&
5c94f87e 47 git-init &&
a61eea6a
JS
48 git-unpack-objects -n <test-1-${packname_1}.pack &&
49 git-unpack-objects <test-1-${packname_1}.pack"
8ee378a0
JH
50
51unset GIT_OBJECT_DIRECTORY
f07a5241 52cd "$TRASH/.git2"
8ee378a0
JH
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.
4d9d62fa 61 return 1
8ee378a0
JH
62 }
63 done'
f07a5241 64cd "$TRASH"
8ee378a0
JH
65
66test_expect_success \
67 'pack with delta' \
68 'pwd &&
a61eea6a 69 packname_2=$(git-pack-objects test-2 <obj-list)'
8ee378a0
JH
70
71rm -fr .git2
72mkdir .git2
73
74test_expect_success \
75 'unpack with delta' \
76 'GIT_OBJECT_DIRECTORY=.git2/objects &&
77 export GIT_OBJECT_DIRECTORY &&
5c94f87e 78 git-init &&
a61eea6a
JS
79 git-unpack-objects -n <test-2-${packname_2}.pack &&
80 git-unpack-objects <test-2-${packname_2}.pack'
8ee378a0
JH
81
82unset GIT_OBJECT_DIRECTORY
f07a5241 83cd "$TRASH/.git2"
8ee378a0
JH
84test_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.
4d9d62fa 91 return 1
8ee378a0
JH
92 }
93 done'
f07a5241 94cd "$TRASH"
8ee378a0 95
1f688557
JH
96rm -fr .git2
97mkdir .git2
98
99test_expect_success \
100 'use packed objects' \
101 'GIT_OBJECT_DIRECTORY=.git2/objects &&
102 export GIT_OBJECT_DIRECTORY &&
5c94f87e 103 git-init &&
a61eea6a 104 cp test-1-${packname_1}.pack test-1-${packname_1}.idx .git2/objects/pack && {
1f688557
JH
105 git-diff-tree --root -p $commit &&
106 while read object
107 do
108 t=`git-cat-file -t $object` &&
4d9d62fa 109 git-cat-file $t $object || return 1
1f688557
JH
110 done <obj-list
111 } >current &&
112 diff expect current'
113
114
115test_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 &&
a61eea6a 120 cp test-2-${packname_2}.pack test-2-${packname_2}.idx .git2/objects/pack && {
1f688557
JH
121 git-diff-tree --root -p $commit &&
122 while read object
123 do
124 t=`git-cat-file -t $object` &&
4d9d62fa 125 git-cat-file $t $object || return 1
1f688557
JH
126 done <obj-list
127 } >current &&
128 diff expect current'
129
f9253394
JH
130unset GIT_OBJECT_DIRECTORY
131
132test_expect_success \
133 'verify pack' \
a61eea6a 134 'git-verify-pack test-1-${packname_1}.idx test-2-${packname_2}.idx'
f9253394
JH
135
136test_expect_success \
137 'corrupt a pack and see if verify catches' \
a61eea6a
JS
138 'cp test-1-${packname_1}.idx test-3.idx &&
139 cp test-2-${packname_2}.pack test-3.pack &&
f9253394
JH
140 if git-verify-pack test-3.idx
141 then false
142 else :;
143 fi &&
144
c97451ce 145 : PACK_SIGNATURE &&
a61eea6a 146 cp test-1-${packname_1}.pack test-3.pack &&
f9253394
JH
147 dd if=/dev/zero of=test-3.pack count=1 bs=1 conv=notrunc seek=2 &&
148 if git-verify-pack test-3.idx
149 then false
150 else :;
151 fi &&
152
c97451ce 153 : PACK_VERSION &&
a61eea6a 154 cp test-1-${packname_1}.pack test-3.pack &&
f9253394
JH
155 dd if=/dev/zero of=test-3.pack count=1 bs=1 conv=notrunc seek=7 &&
156 if git-verify-pack test-3.idx
157 then false
158 else :;
159 fi &&
160
c97451ce 161 : TYPE/SIZE byte of the first packed object data &&
a61eea6a 162 cp test-1-${packname_1}.pack test-3.pack &&
f9253394
JH
163 dd if=/dev/zero of=test-3.pack count=1 bs=1 conv=notrunc seek=12 &&
164 if git-verify-pack test-3.idx
165 then false
166 else :;
167 fi &&
168
c97451ce
JH
169 : sum of the index file itself &&
170 l=`wc -c <test-3.idx` &&
8eafa3da 171 l=`expr $l - 20` &&
c5ced645 172 cp test-1-${packname_1}.pack test-3.pack &&
c97451ce 173 dd if=/dev/zero of=test-3.idx count=20 bs=1 conv=notrunc seek=$l &&
c5ced645
JH
174 if git-verify-pack test-3.pack
175 then false
176 else :;
177 fi &&
178
f9253394
JH
179 :'
180
9cf6d335
SV
181test_expect_success \
182 'build pack index for an existing pack' \
183 'cp test-1-${packname_1}.pack test-3.pack &&
184 git-index-pack -o tmp.idx test-3.pack &&
185 cmp tmp.idx test-1-${packname_1}.idx &&
186
187 git-index-pack test-3.pack &&
188 cmp test-3.idx test-1-${packname_1}.idx &&
189
190 cp test-2-${packname_2}.pack test-3.pack &&
191 git-index-pack -o tmp.idx test-2-${packname_2}.pack &&
192 cmp tmp.idx test-2-${packname_2}.idx &&
193
194 git-index-pack test-3.pack &&
195 cmp test-3.idx test-2-${packname_2}.idx &&
196
197 :'
198
8ee378a0 199test_done