Commit | Line | Data |
---|---|---|
8ee378a0 JH |
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 && | |
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` && | |
32 | git-cat-file $t $object || exit 1 | |
33 | done <obj-list | |
34 | } >expect' | |
8ee378a0 JH |
35 | |
36 | test_expect_success \ | |
37 | 'pack without delta' \ | |
38 | '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 test-1' | |
49 | ||
50 | unset GIT_OBJECT_DIRECTORY | |
51 | cd $TRASH/.git2 | |
52 | ||
53 | test_expect_success \ | |
54 | 'check unpack without delta' \ | |
55 | '(cd ../.git && find objects -type f -print) | | |
56 | while read path | |
57 | do | |
58 | cmp $path ../.git/$path || { | |
59 | echo $path differs. | |
60 | exit 1 | |
61 | } | |
62 | done' | |
63 | cd $TRASH | |
64 | ||
65 | test_expect_success \ | |
66 | 'pack with delta' \ | |
67 | 'pwd && | |
68 | git-pack-objects test-2 <obj-list' | |
69 | ||
70 | rm -fr .git2 | |
71 | mkdir .git2 | |
72 | ||
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' | |
79 | ||
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 | |
86 | do | |
87 | cmp $path ../.git/$path || { | |
88 | echo $path differs. | |
89 | exit 1 | |
90 | } | |
91 | done' | |
92 | cd $TRASH | |
93 | ||
1f688557 JH |
94 | rm -fr .git2 |
95 | mkdir .git2 | |
96 | ||
97 | test_expect_success \ | |
98 | 'use packed objects' \ | |
99 | 'GIT_OBJECT_DIRECTORY=.git2/objects && | |
100 | export GIT_OBJECT_DIRECTORY && | |
101 | git-init-db && | |
1f688557 JH |
102 | cp test-1.pack test-1.idx .git2/objects/pack && { |
103 | git-diff-tree --root -p $commit && | |
104 | while read object | |
105 | do | |
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' | |
111 | ||
112 | ||
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 | |
121 | do | |
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' | |
127 | ||
f9253394 JH |
128 | unset GIT_OBJECT_DIRECTORY |
129 | ||
130 | test_expect_success \ | |
131 | 'verify pack' \ | |
132 | 'git-verify-pack test-1.idx test-2.idx' | |
133 | ||
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 && | |
142 | ||
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 && | |
149 | ||
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 && | |
156 | ||
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 && | |
163 | ||
164 | :' | |
165 | ||
8ee378a0 | 166 | test_done |