t/README: add missing value for GIT_TEST_DEFAULT_REF_FORMAT
[git/gitster.git] / t / t1050-large.sh
blobed638f664479bd1abfca19b985aeaaff66452f18
1 #!/bin/sh
2 # Copyright (c) 2011, Google Inc.
4 test_description='adding and checking out large blobs'
6 TEST_PASSES_SANITIZE_LEAK=true
7 . ./test-lib.sh
9 test_expect_success 'core.bigFileThreshold must be non-negative' '
10 test_must_fail git -c core.bigFileThreshold=-1 rev-parse >out 2>err &&
11 grep "bad numeric config value" err &&
12 test_must_be_empty out
15 test_expect_success setup '
16 # clone does not allow us to pass core.bigfilethreshold to
17 # new repos, so set core.bigfilethreshold globally
18 git config --global core.bigfilethreshold 200k &&
19 printf "%2000000s" X >large1 &&
20 cp large1 large2 &&
21 cp large1 large3 &&
22 printf "%2500000s" Y >huge &&
23 GIT_ALLOC_LIMIT=1500k &&
24 export GIT_ALLOC_LIMIT
27 test_expect_success 'enter "large" codepath, with small core.bigFileThreshold' '
28 test_when_finished "rm -rf repo" &&
30 git init --bare repo &&
31 echo large | git -C repo hash-object -w --stdin &&
32 git -C repo -c core.bigfilethreshold=4 fsck
35 # add a large file with different settings
36 while read expect config
38 test_expect_success "add with $config" '
39 test_when_finished "rm -f .git/objects/pack/pack-*.* .git/index" &&
40 git $config add large1 &&
41 sz=$(test_file_size .git/objects/pack/pack-*.pack) &&
42 case "$expect" in
43 small) test "$sz" -le 100000 ;;
44 large) test "$sz" -ge 100000 ;;
45 esac
47 done <<\EOF
48 large -c core.compression=0
49 small -c core.compression=9
50 large -c core.compression=0 -c pack.compression=0
51 large -c core.compression=9 -c pack.compression=0
52 small -c core.compression=0 -c pack.compression=9
53 small -c core.compression=9 -c pack.compression=9
54 large -c pack.compression=0
55 small -c pack.compression=9
56 EOF
58 test_expect_success 'add a large file or two' '
59 git add large1 huge large2 &&
60 # make sure we got a single packfile and no loose objects
61 count=0 idx= &&
62 for p in .git/objects/pack/pack-*.pack
64 count=$(( $count + 1 )) &&
65 test_path_is_file "$p" &&
66 idx=${p%.pack}.idx &&
67 test_path_is_file "$idx" || return 1
68 done &&
69 test $count = 1 &&
70 cnt=$(git show-index <"$idx" | wc -l) &&
71 test $cnt = 2 &&
72 for l in .git/objects/$OIDPATH_REGEX
74 test_path_is_missing "$l" || return 1
75 done &&
77 # attempt to add another copy of the same
78 git add large3 &&
79 bad= count=0 &&
80 for p in .git/objects/pack/pack-*.pack
82 count=$(( $count + 1 )) &&
83 test_path_is_file "$p" &&
84 idx=${p%.pack}.idx &&
85 test_path_is_file "$idx" || return 1
86 done &&
87 test $count = 1
90 test_expect_success 'checkout a large file' '
91 large1=$(git rev-parse :large1) &&
92 git update-index --add --cacheinfo 100644 $large1 another &&
93 git checkout another &&
94 test_cmp large1 another
97 test_expect_success 'packsize limit' '
98 test_create_repo mid &&
100 cd mid &&
101 git config core.bigfilethreshold 64k &&
102 git config pack.packsizelimit 256k &&
104 # mid1 and mid2 will fit within 256k limit but
105 # appending mid3 will bust the limit and will
106 # result in a separate packfile.
107 test-tool genrandom "a" $(( 66 * 1024 )) >mid1 &&
108 test-tool genrandom "b" $(( 80 * 1024 )) >mid2 &&
109 test-tool genrandom "c" $(( 128 * 1024 )) >mid3 &&
110 git add mid1 mid2 mid3 &&
112 count=0 &&
113 for pi in .git/objects/pack/pack-*.idx
115 test_path_is_file "$pi" && count=$(( $count + 1 )) || return 1
116 done &&
117 test $count = 2 &&
120 git hash-object --stdin <mid1 &&
121 git hash-object --stdin <mid2 &&
122 git hash-object --stdin <mid3
124 sort >expect &&
126 for pi in .git/objects/pack/pack-*.idx
128 git show-index <"$pi" || return 1
129 done |
130 sed -e "s/^[0-9]* \([0-9a-f]*\) .*/\1/" |
131 sort >actual &&
133 test_cmp expect actual
137 test_expect_success 'diff --raw' '
138 git commit -q -m initial &&
139 echo modified >>large1 &&
140 git add large1 &&
141 git commit -q -m modified &&
142 git diff --raw HEAD^
145 test_expect_success 'diff --stat' '
146 git diff --stat HEAD^ HEAD
149 test_expect_success 'diff' '
150 git diff HEAD^ HEAD >actual &&
151 grep "Binary files.*differ" actual
154 test_expect_success 'diff --cached' '
155 git diff --cached HEAD^ >actual &&
156 grep "Binary files.*differ" actual
159 test_expect_success 'hash-object' '
160 git hash-object large1
163 test_expect_success 'cat-file a large file' '
164 git cat-file blob :large1 >/dev/null
167 test_expect_success 'cat-file a large file from a tag' '
168 git tag -m largefile largefiletag :large1 &&
169 git cat-file blob largefiletag >/dev/null
172 test_expect_success 'git-show a large file' '
173 git show :large1 >/dev/null
177 test_expect_success 'index-pack' '
178 git clone file://"$(pwd)"/.git foo &&
179 GIT_DIR=non-existent git index-pack --object-format=$(test_oid algo) \
180 --strict --verify foo/.git/objects/pack/*.pack
183 test_expect_success 'repack' '
184 git repack -ad
187 test_expect_success 'pack-objects with large loose object' '
188 SHA1=$(git hash-object huge) &&
189 test_create_repo loose &&
190 echo $SHA1 | git pack-objects --stdout |
191 GIT_ALLOC_LIMIT=0 GIT_DIR=loose/.git git unpack-objects &&
192 echo $SHA1 | GIT_DIR=loose/.git git pack-objects pack &&
193 test_create_repo packed &&
194 mv pack-* packed/.git/objects/pack &&
195 GIT_DIR=packed/.git git cat-file blob $SHA1 >actual &&
196 test_cmp huge actual
199 test_expect_success 'tar archiving' '
200 git archive --format=tar HEAD >/dev/null
203 test_expect_success 'zip archiving, store only' '
204 git archive --format=zip -0 HEAD >/dev/null
207 test_expect_success 'zip archiving, deflate' '
208 git archive --format=zip HEAD >/dev/null
211 test_expect_success 'fsck large blobs' '
212 git fsck 2>err &&
213 test_must_be_empty err
216 test_done