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-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
36test_expect_success \
37 'pack without delta' \
38 '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-db &&
48 git-unpack-objects test-1'
49
50unset GIT_OBJECT_DIRECTORY
51cd $TRASH/.git2
52
53test_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'
63cd $TRASH
64
65test_expect_success \
66 'pack with delta' \
67 'pwd &&
68 git-pack-objects test-2 <obj-list'
69
70rm -fr .git2
71mkdir .git2
72
73test_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
80unset GIT_OBJECT_DIRECTORY
81cd $TRASH/.git2
82test_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'
92cd $TRASH
93
94rm -fr .git2
95mkdir .git2
96
97test_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
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
113test_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
128test_done