Merge branch 'os/fetch-check-not-current-branch'
[git/debian.git] / t / t1050-large.sh
blob4f3aa17c994240173fdb4de70da62611700e11fd
1 #!/bin/sh
2 # Copyright (c) 2011, Google Inc.
4 test_description='adding and checking out large blobs'
6 . ./test-lib.sh
8 test_expect_success setup '
9 # clone does not allow us to pass core.bigfilethreshold to
10 # new repos, so set core.bigfilethreshold globally
11 git config --global core.bigfilethreshold 200k &&
12 printf "%2000000s" X >large1 &&
13 cp large1 large2 &&
14 cp large1 large3 &&
15 printf "%2500000s" Y >huge &&
16 GIT_ALLOC_LIMIT=1500k &&
17 export GIT_ALLOC_LIMIT
20 test_expect_success 'enter "large" codepath, with small core.bigFileThreshold' '
21 test_when_finished "rm -rf repo" &&
23 git init --bare repo &&
24 echo large | git -C repo hash-object -w --stdin &&
25 git -C repo -c core.bigfilethreshold=4 fsck
28 # add a large file with different settings
29 while read expect config
31 test_expect_success "add with $config" '
32 test_when_finished "rm -f .git/objects/pack/pack-*.* .git/index" &&
33 git $config add large1 &&
34 sz=$(test_file_size .git/objects/pack/pack-*.pack) &&
35 case "$expect" in
36 small) test "$sz" -le 100000 ;;
37 large) test "$sz" -ge 100000 ;;
38 esac
40 done <<\EOF
41 large -c core.compression=0
42 small -c core.compression=9
43 large -c core.compression=0 -c pack.compression=0
44 large -c core.compression=9 -c pack.compression=0
45 small -c core.compression=0 -c pack.compression=9
46 small -c core.compression=9 -c pack.compression=9
47 large -c pack.compression=0
48 small -c pack.compression=9
49 EOF
51 test_expect_success 'add a large file or two' '
52 git add large1 huge large2 &&
53 # make sure we got a single packfile and no loose objects
54 count=0 idx= &&
55 for p in .git/objects/pack/pack-*.pack
57 count=$(( $count + 1 )) &&
58 test_path_is_file "$p" &&
59 idx=${p%.pack}.idx &&
60 test_path_is_file "$idx" || return 1
61 done &&
62 test $count = 1 &&
63 cnt=$(git show-index <"$idx" | wc -l) &&
64 test $cnt = 2 &&
65 for l in .git/objects/$OIDPATH_REGEX
67 test_path_is_missing "$l" || return 1
68 done &&
70 # attempt to add another copy of the same
71 git add large3 &&
72 bad= count=0 &&
73 for p in .git/objects/pack/pack-*.pack
75 count=$(( $count + 1 )) &&
76 test_path_is_file "$p" &&
77 idx=${p%.pack}.idx &&
78 test_path_is_file "$idx" || return 1
79 done &&
80 test $count = 1
83 test_expect_success 'checkout a large file' '
84 large1=$(git rev-parse :large1) &&
85 git update-index --add --cacheinfo 100644 $large1 another &&
86 git checkout another &&
87 test_cmp large1 another
90 test_expect_success 'packsize limit' '
91 test_create_repo mid &&
93 cd mid &&
94 git config core.bigfilethreshold 64k &&
95 git config pack.packsizelimit 256k &&
97 # mid1 and mid2 will fit within 256k limit but
98 # appending mid3 will bust the limit and will
99 # result in a separate packfile.
100 test-tool genrandom "a" $(( 66 * 1024 )) >mid1 &&
101 test-tool genrandom "b" $(( 80 * 1024 )) >mid2 &&
102 test-tool genrandom "c" $(( 128 * 1024 )) >mid3 &&
103 git add mid1 mid2 mid3 &&
105 count=0 &&
106 for pi in .git/objects/pack/pack-*.idx
108 test_path_is_file "$pi" && count=$(( $count + 1 )) || return 1
109 done &&
110 test $count = 2 &&
113 git hash-object --stdin <mid1 &&
114 git hash-object --stdin <mid2 &&
115 git hash-object --stdin <mid3
117 sort >expect &&
119 for pi in .git/objects/pack/pack-*.idx
121 git show-index <"$pi" || return 1
122 done |
123 sed -e "s/^[0-9]* \([0-9a-f]*\) .*/\1/" |
124 sort >actual &&
126 test_cmp expect actual
130 test_expect_success 'diff --raw' '
131 git commit -q -m initial &&
132 echo modified >>large1 &&
133 git add large1 &&
134 git commit -q -m modified &&
135 git diff --raw HEAD^
138 test_expect_success 'diff --stat' '
139 git diff --stat HEAD^ HEAD
142 test_expect_success 'diff' '
143 git diff HEAD^ HEAD >actual &&
144 grep "Binary files.*differ" actual
147 test_expect_success 'diff --cached' '
148 git diff --cached HEAD^ >actual &&
149 grep "Binary files.*differ" actual
152 test_expect_success 'hash-object' '
153 git hash-object large1
156 test_expect_success 'cat-file a large file' '
157 git cat-file blob :large1 >/dev/null
160 test_expect_success 'cat-file a large file from a tag' '
161 git tag -m largefile largefiletag :large1 &&
162 git cat-file blob largefiletag >/dev/null
165 test_expect_success 'git-show a large file' '
166 git show :large1 >/dev/null
170 test_expect_success 'index-pack' '
171 git clone file://"$(pwd)"/.git foo &&
172 GIT_DIR=non-existent git index-pack --object-format=$(test_oid algo) \
173 --strict --verify foo/.git/objects/pack/*.pack
176 test_expect_success 'repack' '
177 git repack -ad
180 test_expect_success 'pack-objects with large loose object' '
181 SHA1=$(git hash-object huge) &&
182 test_create_repo loose &&
183 echo $SHA1 | git pack-objects --stdout |
184 GIT_ALLOC_LIMIT=0 GIT_DIR=loose/.git git unpack-objects &&
185 echo $SHA1 | GIT_DIR=loose/.git git pack-objects pack &&
186 test_create_repo packed &&
187 mv pack-* packed/.git/objects/pack &&
188 GIT_DIR=packed/.git git cat-file blob $SHA1 >actual &&
189 test_cmp huge actual
192 test_expect_success 'tar archiving' '
193 git archive --format=tar HEAD >/dev/null
196 test_expect_success 'zip archiving, store only' '
197 git archive --format=zip -0 HEAD >/dev/null
200 test_expect_success 'zip archiving, deflate' '
201 git archive --format=zip HEAD >/dev/null
204 test_expect_success 'fsck large blobs' '
205 git fsck 2>err &&
206 test_must_be_empty err
209 test_done