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