]>
Commit | Line | Data |
---|---|---|
b335d3f1 AR |
1 | #!/bin/sh |
2 | ||
3 | test_description='git cat-file' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
7 | echo_without_newline () { | |
8 | printf '%s' "$*" | |
9 | } | |
10 | ||
11 | strlen () { | |
12 | echo_without_newline "$1" | wc -c | sed -e 's/^ *//' | |
13 | } | |
14 | ||
15 | maybe_remove_timestamp () { | |
16 | if test -z "$2"; then | |
17 | echo_without_newline "$1" | |
18 | else | |
19 | echo_without_newline "$(printf '%s\n' "$1" | sed -e 's/ [0-9][0-9]* [-+][0-9][0-9][0-9][0-9]$//')" | |
20 | fi | |
21 | } | |
22 | ||
23 | run_tests () { | |
24 | type=$1 | |
25 | sha1=$2 | |
26 | size=$3 | |
27 | content=$4 | |
28 | pretty_content=$5 | |
29 | no_ts=$6 | |
30 | ||
a8128ed6 AR |
31 | batch_output="$sha1 $type $size |
32 | $content" | |
33 | ||
b335d3f1 AR |
34 | test_expect_success "$type exists" ' |
35 | git cat-file -e $sha1 | |
36 | ' | |
37 | ||
38 | test_expect_success "Type of $type is correct" ' | |
03c893cb JK |
39 | echo $type >expect && |
40 | git cat-file -t $sha1 >actual && | |
41 | test_cmp expect actual | |
b335d3f1 AR |
42 | ' |
43 | ||
44 | test_expect_success "Size of $type is correct" ' | |
03c893cb JK |
45 | echo $size >expect && |
46 | git cat-file -s $sha1 >actual && | |
47 | test_cmp expect actual | |
b335d3f1 AR |
48 | ' |
49 | ||
3e370f9f KN |
50 | test_expect_success "Type of $type is correct using --allow-unknown-type" ' |
51 | echo $type >expect && | |
52 | git cat-file -t --allow-unknown-type $sha1 >actual && | |
53 | test_cmp expect actual | |
54 | ' | |
55 | ||
56 | test_expect_success "Size of $type is correct using --allow-unknown-type" ' | |
57 | echo $size >expect && | |
58 | git cat-file -s --allow-unknown-type $sha1 >actual && | |
59 | test_cmp expect actual | |
60 | ' | |
61 | ||
b335d3f1 AR |
62 | test -z "$content" || |
63 | test_expect_success "Content of $type is correct" ' | |
03c893cb JK |
64 | maybe_remove_timestamp "$content" $no_ts >expect && |
65 | maybe_remove_timestamp "$(git cat-file $type $sha1)" $no_ts >actual && | |
66 | test_cmp expect actual | |
b335d3f1 AR |
67 | ' |
68 | ||
69 | test_expect_success "Pretty content of $type is correct" ' | |
03c893cb JK |
70 | maybe_remove_timestamp "$pretty_content" $no_ts >expect && |
71 | maybe_remove_timestamp "$(git cat-file -p $sha1)" $no_ts >actual && | |
72 | test_cmp expect actual | |
b335d3f1 | 73 | ' |
05d5667f | 74 | |
a8128ed6 AR |
75 | test -z "$content" || |
76 | test_expect_success "--batch output of $type is correct" ' | |
03c893cb JK |
77 | maybe_remove_timestamp "$batch_output" $no_ts >expect && |
78 | maybe_remove_timestamp "$(echo $sha1 | git cat-file --batch)" $no_ts >actual && | |
79 | test_cmp expect actual | |
a8128ed6 AR |
80 | ' |
81 | ||
05d5667f | 82 | test_expect_success "--batch-check output of $type is correct" ' |
03c893cb JK |
83 | echo "$sha1 $type $size" >expect && |
84 | echo_without_newline $sha1 | git cat-file --batch-check >actual && | |
85 | test_cmp expect actual | |
05d5667f | 86 | ' |
93d2a607 JK |
87 | |
88 | test_expect_success "custom --batch-check format" ' | |
89 | echo "$type $sha1" >expect && | |
90 | echo $sha1 | git cat-file --batch-check="%(objecttype) %(objectname)" >actual && | |
91 | test_cmp expect actual | |
92 | ' | |
97be0407 JK |
93 | |
94 | test_expect_success '--batch-check with %(rest)' ' | |
95 | echo "$type this is some extra content" >expect && | |
96 | echo "$sha1 this is some extra content" | | |
97 | git cat-file --batch-check="%(objecttype) %(rest)" >actual && | |
98 | test_cmp expect actual | |
99 | ' | |
6554dfa9 JK |
100 | |
101 | test -z "$content" || | |
102 | test_expect_success "--batch without type ($type)" ' | |
103 | { | |
104 | echo "$size" && | |
105 | maybe_remove_timestamp "$content" $no_ts | |
106 | } >expect && | |
107 | echo $sha1 | git cat-file --batch="%(objectsize)" >actual.full && | |
108 | maybe_remove_timestamp "$(cat actual.full)" $no_ts >actual && | |
109 | test_cmp expect actual | |
110 | ' | |
111 | ||
112 | test -z "$content" || | |
113 | test_expect_success "--batch without size ($type)" ' | |
114 | { | |
115 | echo "$type" && | |
116 | maybe_remove_timestamp "$content" $no_ts | |
117 | } >expect && | |
118 | echo $sha1 | git cat-file --batch="%(objecttype)" >actual.full && | |
119 | maybe_remove_timestamp "$(cat actual.full)" $no_ts >actual && | |
120 | test_cmp expect actual | |
121 | ' | |
b335d3f1 AR |
122 | } |
123 | ||
124 | hello_content="Hello World" | |
125 | hello_size=$(strlen "$hello_content") | |
126 | hello_sha1=$(echo_without_newline "$hello_content" | git hash-object --stdin) | |
127 | ||
128 | test_expect_success "setup" ' | |
129 | echo_without_newline "$hello_content" > hello && | |
130 | git update-index --add hello | |
131 | ' | |
132 | ||
133 | run_tests 'blob' $hello_sha1 $hello_size "$hello_content" "$hello_content" | |
134 | ||
97be0407 JK |
135 | test_expect_success '--batch-check without %(rest) considers whole line' ' |
136 | echo "$hello_sha1 blob $hello_size" >expect && | |
137 | git update-index --add --cacheinfo 100644 $hello_sha1 "white space" && | |
138 | test_when_finished "git update-index --remove \"white space\"" && | |
139 | echo ":white space" | git cat-file --batch-check >actual && | |
140 | test_cmp expect actual | |
141 | ' | |
142 | ||
e95f5313 | 143 | test_oid_init |
144 | ||
b335d3f1 | 145 | tree_sha1=$(git write-tree) |
e95f5313 | 146 | tree_size=$(($(test_oid rawsz) + 13)) |
b335d3f1 AR |
147 | tree_pretty_content="100644 blob $hello_sha1 hello" |
148 | ||
149 | run_tests 'tree' $tree_sha1 $tree_size "" "$tree_pretty_content" | |
150 | ||
41ccfdd9 | 151 | commit_message="Initial commit" |
b335d3f1 | 152 | commit_sha1=$(echo_without_newline "$commit_message" | git commit-tree $tree_sha1) |
e95f5313 | 153 | commit_size=$(($(test_oid hexsz) + 137)) |
b335d3f1 AR |
154 | commit_content="tree $tree_sha1 |
155 | author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 0000000000 +0000 | |
156 | committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 0000000000 +0000 | |
157 | ||
158 | $commit_message" | |
159 | ||
160 | run_tests 'commit' $commit_sha1 $commit_size "$commit_content" "$commit_content" 1 | |
161 | ||
162 | tag_header_without_timestamp="object $hello_sha1 | |
163 | type blob | |
164 | tag hellotag | |
165 | tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" | |
166 | tag_description="This is a tag" | |
167 | tag_content="$tag_header_without_timestamp 0000000000 +0000 | |
168 | ||
b335d3f1 AR |
169 | $tag_description" |
170 | ||
171 | tag_sha1=$(echo_without_newline "$tag_content" | git mktag) | |
172 | tag_size=$(strlen "$tag_content") | |
173 | ||
9cfa5126 | 174 | run_tests 'tag' $tag_sha1 $tag_size "$tag_content" "$tag_content" 1 |
b335d3f1 AR |
175 | |
176 | test_expect_success \ | |
177 | "Reach a blob from a tag pointing to it" \ | |
178 | "test '$hello_content' = \"\$(git cat-file blob $tag_sha1)\"" | |
179 | ||
a8128ed6 | 180 | for batch in batch batch-check |
05d5667f | 181 | do |
a8128ed6 AR |
182 | for opt in t s e p |
183 | do | |
184 | test_expect_success "Passing -$opt with --$batch fails" ' | |
185 | test_must_fail git cat-file --$batch -$opt $hello_sha1 | |
186 | ' | |
187 | ||
188 | test_expect_success "Passing --$batch with -$opt fails" ' | |
189 | test_must_fail git cat-file -$opt --$batch $hello_sha1 | |
190 | ' | |
191 | done | |
192 | ||
193 | test_expect_success "Passing <type> with --$batch fails" ' | |
194 | test_must_fail git cat-file --$batch blob $hello_sha1 | |
05d5667f AR |
195 | ' |
196 | ||
a8128ed6 AR |
197 | test_expect_success "Passing --$batch with <type> fails" ' |
198 | test_must_fail git cat-file blob --$batch $hello_sha1 | |
05d5667f | 199 | ' |
05d5667f | 200 | |
a8128ed6 AR |
201 | test_expect_success "Passing sha1 with --$batch fails" ' |
202 | test_must_fail git cat-file --$batch $hello_sha1 | |
203 | ' | |
204 | done | |
05d5667f | 205 | |
122d5346 DT |
206 | for opt in t s e p |
207 | do | |
208 | test_expect_success "Passing -$opt with --follow-symlinks fails" ' | |
209 | test_must_fail git cat-file --follow-symlinks -$opt $hello_sha1 | |
210 | ' | |
211 | done | |
212 | ||
3c076dbe LW |
213 | test_expect_success "--batch-check for a non-existent named object" ' |
214 | test "foobar42 missing | |
215 | foobar84 missing" = \ | |
216 | "$( ( echo foobar42; echo_without_newline foobar84; ) | git cat-file --batch-check)" | |
217 | ' | |
218 | ||
219 | test_expect_success "--batch-check for a non-existent hash" ' | |
220 | test "0000000000000000000000000000000000000042 missing | |
221 | 0000000000000000000000000000000000000084 missing" = \ | |
222 | "$( ( echo 0000000000000000000000000000000000000042; | |
bdbc17e8 MD |
223 | echo_without_newline 0000000000000000000000000000000000000084; ) | |
224 | git cat-file --batch-check)" | |
3c076dbe LW |
225 | ' |
226 | ||
227 | test_expect_success "--batch for an existent and a non-existent hash" ' | |
228 | test "$tag_sha1 tag $tag_size | |
229 | $tag_content | |
230 | 0000000000000000000000000000000000000000 missing" = \ | |
231 | "$( ( echo $tag_sha1; | |
bdbc17e8 MD |
232 | echo_without_newline 0000000000000000000000000000000000000000; ) | |
233 | git cat-file --batch)" | |
05d5667f AR |
234 | ' |
235 | ||
2e3a16b2 | 236 | test_expect_success "--batch-check for an empty line" ' |
05d5667f AR |
237 | test " missing" = "$(echo | git cat-file --batch-check)" |
238 | ' | |
239 | ||
4ef8d1dd | 240 | test_expect_success 'empty --batch-check notices missing object' ' |
8125a58b | 241 | echo "$ZERO_OID missing" >expect && |
242 | echo "$ZERO_OID" | git cat-file --batch-check="" >actual && | |
4ef8d1dd JH |
243 | test_cmp expect actual |
244 | ' | |
245 | ||
a8128ed6 AR |
246 | batch_input="$hello_sha1 |
247 | $commit_sha1 | |
248 | $tag_sha1 | |
249 | deadbeef | |
250 | ||
251 | " | |
252 | ||
253 | batch_output="$hello_sha1 blob $hello_size | |
254 | $hello_content | |
255 | $commit_sha1 commit $commit_size | |
256 | $commit_content | |
257 | $tag_sha1 tag $tag_size | |
258 | $tag_content | |
259 | deadbeef missing | |
260 | missing" | |
261 | ||
6c41e21d MB |
262 | test_expect_success '--batch with multiple sha1s gives correct format' ' |
263 | test "$(maybe_remove_timestamp "$batch_output" 1)" = "$(maybe_remove_timestamp "$(echo_without_newline "$batch_input" | git cat-file --batch)" 1)" | |
264 | ' | |
a8128ed6 | 265 | |
05d5667f AR |
266 | batch_check_input="$hello_sha1 |
267 | $tree_sha1 | |
268 | $commit_sha1 | |
269 | $tag_sha1 | |
270 | deadbeef | |
271 | ||
272 | " | |
273 | ||
274 | batch_check_output="$hello_sha1 blob $hello_size | |
275 | $tree_sha1 tree $tree_size | |
276 | $commit_sha1 commit $commit_size | |
277 | $tag_sha1 tag $tag_size | |
278 | deadbeef missing | |
279 | missing" | |
280 | ||
281 | test_expect_success "--batch-check with multiple sha1s gives correct format" ' | |
282 | test "$batch_check_output" = \ | |
283 | "$(echo_without_newline "$batch_check_input" | git cat-file --batch-check)" | |
284 | ' | |
285 | ||
65ea9c3c | 286 | test_expect_success 'setup blobs which are likely to delta' ' |
c680668d | 287 | test-tool genrandom foo 10240 >foo && |
65ea9c3c JK |
288 | { cat foo; echo plus; } >foo-plus && |
289 | git add foo foo-plus && | |
290 | git commit -m foo && | |
291 | cat >blobs <<-\EOF | |
292 | HEAD:foo | |
293 | HEAD:foo-plus | |
294 | EOF | |
295 | ' | |
296 | ||
297 | test_expect_success 'confirm that neither loose blob is a delta' ' | |
99094a7a | 298 | cat >expect <<-EOF && |
8125a58b | 299 | $ZERO_OID |
300 | $ZERO_OID | |
65ea9c3c JK |
301 | EOF |
302 | git cat-file --batch-check="%(deltabase)" <blobs >actual && | |
303 | test_cmp expect actual | |
304 | ' | |
305 | ||
306 | # To avoid relying too much on the current delta heuristics, | |
307 | # we will check only that one of the two objects is a delta | |
308 | # against the other, but not the order. We can do so by just | |
309 | # asking for the base of both, and checking whether either | |
310 | # sha1 appears in the output. | |
311 | test_expect_success '%(deltabase) reports packed delta bases' ' | |
312 | git repack -ad && | |
313 | git cat-file --batch-check="%(deltabase)" <blobs >actual && | |
314 | { | |
315 | grep "$(git rev-parse HEAD:foo)" actual || | |
316 | grep "$(git rev-parse HEAD:foo-plus)" actual | |
317 | } | |
318 | ' | |
319 | ||
3e370f9f KN |
320 | bogus_type="bogus" |
321 | bogus_content="bogus" | |
322 | bogus_size=$(strlen "$bogus_content") | |
323 | bogus_sha1=$(echo_without_newline "$bogus_content" | git hash-object -t $bogus_type --literally -w --stdin) | |
324 | ||
325 | test_expect_success "Type of broken object is correct" ' | |
326 | echo $bogus_type >expect && | |
327 | git cat-file -t --allow-unknown-type $bogus_sha1 >actual && | |
328 | test_cmp expect actual | |
329 | ' | |
330 | ||
331 | test_expect_success "Size of broken object is correct" ' | |
332 | echo $bogus_size >expect && | |
333 | git cat-file -s --allow-unknown-type $bogus_sha1 >actual && | |
334 | test_cmp expect actual | |
335 | ' | |
336 | bogus_type="abcdefghijklmnopqrstuvwxyz1234679" | |
337 | bogus_content="bogus" | |
338 | bogus_size=$(strlen "$bogus_content") | |
339 | bogus_sha1=$(echo_without_newline "$bogus_content" | git hash-object -t $bogus_type --literally -w --stdin) | |
340 | ||
341 | test_expect_success "Type of broken object is correct when type is large" ' | |
342 | echo $bogus_type >expect && | |
343 | git cat-file -t --allow-unknown-type $bogus_sha1 >actual && | |
344 | test_cmp expect actual | |
345 | ' | |
346 | ||
347 | test_expect_success "Size of large broken object is correct when type is large" ' | |
348 | echo $bogus_size >expect && | |
349 | git cat-file -s --allow-unknown-type $bogus_sha1 >actual && | |
350 | test_cmp expect actual | |
351 | ' | |
352 | ||
122d5346 DT |
353 | # Tests for git cat-file --follow-symlinks |
354 | test_expect_success 'prep for symlink tests' ' | |
355 | echo_without_newline "$hello_content" >morx && | |
356 | test_ln_s_add morx same-dir-link && | |
357 | test_ln_s_add dir link-to-dir && | |
358 | test_ln_s_add ../fleem out-of-repo-link && | |
359 | test_ln_s_add .. out-of-repo-link-dir && | |
360 | test_ln_s_add same-dir-link link-to-link && | |
361 | test_ln_s_add nope broken-same-dir-link && | |
362 | mkdir dir && | |
363 | test_ln_s_add ../morx dir/parent-dir-link && | |
364 | test_ln_s_add .. dir/link-dir && | |
365 | test_ln_s_add ../../escape dir/out-of-repo-link && | |
366 | test_ln_s_add ../.. dir/out-of-repo-link-dir && | |
367 | test_ln_s_add nope dir/broken-link-in-dir && | |
368 | mkdir dir/subdir && | |
369 | test_ln_s_add ../../morx dir/subdir/grandparent-dir-link && | |
370 | test_ln_s_add ../../../great-escape dir/subdir/out-of-repo-link && | |
371 | test_ln_s_add ../../.. dir/subdir/out-of-repo-link-dir && | |
372 | test_ln_s_add ../../../ dir/subdir/out-of-repo-link-dir-trailing && | |
373 | test_ln_s_add ../parent-dir-link dir/subdir/parent-dir-link-to-link && | |
374 | echo_without_newline "$hello_content" >dir/subdir/ind2 && | |
375 | echo_without_newline "$hello_content" >dir/ind1 && | |
376 | test_ln_s_add dir dirlink && | |
377 | test_ln_s_add dir/subdir subdirlink && | |
378 | test_ln_s_add subdir/ind2 dir/link-to-child && | |
379 | test_ln_s_add dir/link-to-child link-to-down-link && | |
380 | test_ln_s_add dir/.. up-down && | |
381 | test_ln_s_add dir/../ up-down-trailing && | |
382 | test_ln_s_add dir/../morx up-down-file && | |
383 | test_ln_s_add dir/../../morx up-up-down-file && | |
384 | test_ln_s_add subdirlink/../../morx up-two-down-file && | |
385 | test_ln_s_add loop1 loop2 && | |
386 | test_ln_s_add loop2 loop1 && | |
387 | git add morx dir/subdir/ind2 dir/ind1 && | |
388 | git commit -am "test" && | |
389 | echo $hello_sha1 blob $hello_size >found | |
390 | ' | |
391 | ||
392 | test_expect_success 'git cat-file --batch-check --follow-symlinks works for non-links' ' | |
393 | echo HEAD:morx | git cat-file --batch-check --follow-symlinks >actual && | |
394 | test_cmp found actual && | |
395 | echo HEAD:nope missing >expect && | |
396 | echo HEAD:nope | git cat-file --batch-check --follow-symlinks >actual && | |
397 | test_cmp expect actual | |
398 | ' | |
399 | ||
400 | test_expect_success 'git cat-file --batch-check --follow-symlinks works for in-repo, same-dir links' ' | |
401 | echo HEAD:same-dir-link | git cat-file --batch-check --follow-symlinks >actual && | |
402 | test_cmp found actual | |
403 | ' | |
404 | ||
405 | test_expect_success 'git cat-file --batch-check --follow-symlinks works for in-repo, links to dirs' ' | |
406 | echo HEAD:link-to-dir/ind1 | git cat-file --batch-check --follow-symlinks >actual && | |
407 | test_cmp found actual | |
408 | ' | |
409 | ||
410 | ||
411 | test_expect_success 'git cat-file --batch-check --follow-symlinks works for broken in-repo, same-dir links' ' | |
412 | echo dangling 25 >expect && | |
413 | echo HEAD:broken-same-dir-link >>expect && | |
414 | echo HEAD:broken-same-dir-link | git cat-file --batch-check --follow-symlinks >actual && | |
415 | test_cmp expect actual | |
416 | ' | |
417 | ||
418 | test_expect_success 'git cat-file --batch-check --follow-symlinks works for same-dir links-to-links' ' | |
419 | echo HEAD:link-to-link | git cat-file --batch-check --follow-symlinks >actual && | |
420 | test_cmp found actual | |
421 | ' | |
422 | ||
423 | test_expect_success 'git cat-file --batch-check --follow-symlinks works for parent-dir links' ' | |
424 | echo HEAD:dir/parent-dir-link | git cat-file --batch-check --follow-symlinks >actual && | |
425 | test_cmp found actual && | |
426 | echo notdir 29 >expect && | |
427 | echo HEAD:dir/parent-dir-link/nope >>expect && | |
428 | echo HEAD:dir/parent-dir-link/nope | git cat-file --batch-check --follow-symlinks >actual && | |
429 | test_cmp expect actual | |
430 | ' | |
431 | ||
432 | test_expect_success 'git cat-file --batch-check --follow-symlinks works for .. links' ' | |
433 | echo dangling 22 >expect && | |
434 | echo HEAD:dir/link-dir/nope >>expect && | |
435 | echo HEAD:dir/link-dir/nope | git cat-file --batch-check --follow-symlinks >actual && | |
436 | test_cmp expect actual && | |
437 | echo HEAD:dir/link-dir/morx | git cat-file --batch-check --follow-symlinks >actual && | |
438 | test_cmp found actual && | |
439 | echo dangling 27 >expect && | |
440 | echo HEAD:dir/broken-link-in-dir >>expect && | |
441 | echo HEAD:dir/broken-link-in-dir | git cat-file --batch-check --follow-symlinks >actual && | |
442 | test_cmp expect actual | |
443 | ' | |
444 | ||
445 | test_expect_success 'git cat-file --batch-check --follow-symlinks works for ../.. links' ' | |
446 | echo notdir 41 >expect && | |
447 | echo HEAD:dir/subdir/grandparent-dir-link/nope >>expect && | |
448 | echo HEAD:dir/subdir/grandparent-dir-link/nope | git cat-file --batch-check --follow-symlinks >actual && | |
449 | test_cmp expect actual && | |
450 | echo HEAD:dir/subdir/grandparent-dir-link | git cat-file --batch-check --follow-symlinks >actual && | |
451 | test_cmp found actual && | |
452 | echo HEAD:dir/subdir/parent-dir-link-to-link | git cat-file --batch-check --follow-symlinks >actual && | |
453 | test_cmp found actual | |
454 | ' | |
455 | ||
456 | test_expect_success 'git cat-file --batch-check --follow-symlinks works for dir/ links' ' | |
457 | echo dangling 17 >expect && | |
458 | echo HEAD:dirlink/morx >>expect && | |
459 | echo HEAD:dirlink/morx | git cat-file --batch-check --follow-symlinks >actual && | |
460 | test_cmp expect actual && | |
461 | echo $hello_sha1 blob $hello_size >expect && | |
462 | echo HEAD:dirlink/ind1 | git cat-file --batch-check --follow-symlinks >actual && | |
463 | test_cmp expect actual | |
464 | ' | |
465 | ||
466 | test_expect_success 'git cat-file --batch-check --follow-symlinks works for dir/subdir links' ' | |
467 | echo dangling 20 >expect && | |
468 | echo HEAD:subdirlink/morx >>expect && | |
469 | echo HEAD:subdirlink/morx | git cat-file --batch-check --follow-symlinks >actual && | |
470 | test_cmp expect actual && | |
471 | echo HEAD:subdirlink/ind2 | git cat-file --batch-check --follow-symlinks >actual && | |
472 | test_cmp found actual | |
473 | ' | |
474 | ||
475 | test_expect_success 'git cat-file --batch-check --follow-symlinks works for dir ->subdir links' ' | |
476 | echo notdir 27 >expect && | |
477 | echo HEAD:dir/link-to-child/morx >>expect && | |
478 | echo HEAD:dir/link-to-child/morx | git cat-file --batch-check --follow-symlinks >actual && | |
479 | test_cmp expect actual && | |
480 | echo HEAD:dir/link-to-child | git cat-file --batch-check --follow-symlinks >actual && | |
481 | test_cmp found actual && | |
482 | echo HEAD:link-to-down-link | git cat-file --batch-check --follow-symlinks >actual && | |
483 | test_cmp found actual | |
484 | ' | |
485 | ||
486 | test_expect_success 'git cat-file --batch-check --follow-symlinks works for out-of-repo symlinks' ' | |
487 | echo symlink 8 >expect && | |
488 | echo ../fleem >>expect && | |
489 | echo HEAD:out-of-repo-link | git cat-file --batch-check --follow-symlinks >actual && | |
490 | test_cmp expect actual && | |
491 | echo symlink 2 >expect && | |
492 | echo .. >>expect && | |
493 | echo HEAD:out-of-repo-link-dir | git cat-file --batch-check --follow-symlinks >actual && | |
494 | test_cmp expect actual | |
495 | ' | |
496 | ||
497 | test_expect_success 'git cat-file --batch-check --follow-symlinks works for out-of-repo symlinks in dirs' ' | |
498 | echo symlink 9 >expect && | |
499 | echo ../escape >>expect && | |
500 | echo HEAD:dir/out-of-repo-link | git cat-file --batch-check --follow-symlinks >actual && | |
501 | test_cmp expect actual && | |
502 | echo symlink 2 >expect && | |
503 | echo .. >>expect && | |
504 | echo HEAD:dir/out-of-repo-link-dir | git cat-file --batch-check --follow-symlinks >actual && | |
505 | test_cmp expect actual | |
506 | ' | |
507 | ||
508 | test_expect_success 'git cat-file --batch-check --follow-symlinks works for out-of-repo symlinks in subdirs' ' | |
509 | echo symlink 15 >expect && | |
510 | echo ../great-escape >>expect && | |
511 | echo HEAD:dir/subdir/out-of-repo-link | git cat-file --batch-check --follow-symlinks >actual && | |
512 | test_cmp expect actual && | |
513 | echo symlink 2 >expect && | |
514 | echo .. >>expect && | |
515 | echo HEAD:dir/subdir/out-of-repo-link-dir | git cat-file --batch-check --follow-symlinks >actual && | |
516 | test_cmp expect actual && | |
517 | echo symlink 3 >expect && | |
518 | echo ../ >>expect && | |
519 | echo HEAD:dir/subdir/out-of-repo-link-dir-trailing | git cat-file --batch-check --follow-symlinks >actual && | |
520 | test_cmp expect actual | |
521 | ' | |
522 | ||
523 | test_expect_success 'git cat-file --batch-check --follow-symlinks works for symlinks with internal ..' ' | |
524 | echo HEAD: | git cat-file --batch-check >expect && | |
525 | echo HEAD:up-down | git cat-file --batch-check --follow-symlinks >actual && | |
526 | test_cmp expect actual && | |
527 | echo HEAD:up-down-trailing | git cat-file --batch-check --follow-symlinks >actual && | |
528 | test_cmp expect actual && | |
529 | echo HEAD:up-down-file | git cat-file --batch-check --follow-symlinks >actual && | |
530 | test_cmp found actual && | |
531 | echo symlink 7 >expect && | |
532 | echo ../morx >>expect && | |
533 | echo HEAD:up-up-down-file | git cat-file --batch-check --follow-symlinks >actual && | |
534 | test_cmp expect actual && | |
535 | echo HEAD:up-two-down-file | git cat-file --batch-check --follow-symlinks >actual && | |
536 | test_cmp found actual | |
537 | ' | |
538 | ||
539 | test_expect_success 'git cat-file --batch-check --follow-symlink breaks loops' ' | |
540 | echo loop 10 >expect && | |
541 | echo HEAD:loop1 >>expect && | |
542 | echo HEAD:loop1 | git cat-file --batch-check --follow-symlinks >actual && | |
543 | test_cmp expect actual | |
544 | ' | |
545 | ||
546 | test_expect_success 'git cat-file --batch --follow-symlink returns correct sha and mode' ' | |
547 | echo HEAD:morx | git cat-file --batch >expect && | |
548 | echo HEAD:morx | git cat-file --batch --follow-symlinks >actual && | |
549 | test_cmp expect actual | |
550 | ' | |
67f0b6f3 | 551 | |
6a951937 | 552 | test_expect_success 'cat-file --batch-all-objects shows all objects' ' |
3115ee45 | 553 | # make new repos so we know the full set of objects; we will |
6a951937 | 554 | # also make sure that there are some packed and some loose |
aa2f5ef5 JK |
555 | # objects, some referenced and some not, some duplicates, and that |
556 | # there are some available only via alternates. | |
6a951937 JK |
557 | git init all-one && |
558 | ( | |
559 | cd all-one && | |
560 | echo content >file && | |
561 | git add file && | |
562 | git commit -qm base && | |
563 | git rev-parse HEAD HEAD^{tree} HEAD:file && | |
564 | git repack -ad && | |
565 | echo not-cloned | git hash-object -w --stdin | |
566 | ) >expect.unsorted && | |
567 | git clone -s all-one all-two && | |
568 | ( | |
569 | cd all-two && | |
570 | echo local-unref | git hash-object -w --stdin | |
571 | ) >>expect.unsorted && | |
aa2f5ef5 JK |
572 | git -C all-two rev-parse HEAD:file | |
573 | git -C all-two pack-objects .git/objects/pack/pack && | |
6a951937 JK |
574 | sort <expect.unsorted >expect && |
575 | git -C all-two cat-file --batch-all-objects \ | |
3115ee45 | 576 | --batch-check="%(objectname)" >actual && |
6a951937 JK |
577 | test_cmp expect actual |
578 | ' | |
579 | ||
0750bb5b JK |
580 | # The only user-visible difference is that the objects are no longer sorted, |
581 | # and the resulting sort order is undefined. So we can only check that it | |
582 | # produces the same objects as the ordered case, but that at least exercises | |
583 | # the code. | |
584 | test_expect_success 'cat-file --unordered works' ' | |
585 | git -C all-two cat-file --batch-all-objects --unordered \ | |
586 | --batch-check="%(objectname)" >actual.unsorted && | |
587 | sort <actual.unsorted >actual && | |
588 | test_cmp expect actual | |
589 | ' | |
590 | ||
b335d3f1 | 591 | test_done |