3 test_description
='git cat-file'
7 echo_without_newline
() {
12 echo_without_newline
"$1" |
wc -c |
sed -e 's/^ *//'
15 maybe_remove_timestamp
() {
17 echo_without_newline
"$1"
19 echo_without_newline
"$(printf '%s\n' "$1" | sed -e 's/ [0-9][0-9]* [-+][0-9][0-9][0-9][0-9]$//')"
31 batch_output
="$sha1 $type $size
34 test_expect_success
"$type exists" '
38 test_expect_success
"Type of $type is correct" '
40 git cat-file -t $sha1 >actual &&
41 test_cmp expect actual
44 test_expect_success
"Size of $type is correct" '
46 git cat-file -s $sha1 >actual &&
47 test_cmp expect actual
50 test_expect_success
"Type of $type is correct using --allow-unknown-type" '
52 git cat-file -t --allow-unknown-type $sha1 >actual &&
53 test_cmp expect actual
56 test_expect_success
"Size of $type is correct using --allow-unknown-type" '
58 git cat-file -s --allow-unknown-type $sha1 >actual &&
59 test_cmp expect actual
63 test_expect_success
"Content of $type is correct" '
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
69 test_expect_success
"Pretty content of $type is correct" '
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
76 test_expect_success
"--batch output of $type is correct" '
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
82 test_expect_success
"--batch-check output of $type is correct" '
83 echo "$sha1 $type $size" >expect &&
84 echo_without_newline $sha1 | git cat-file --batch-check >actual &&
85 test_cmp expect actual
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
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
101 test -z "$content" ||
102 test_expect_success
"--batch without type ($type)" '
105 maybe_remove_timestamp "$content" $no_ts
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
112 test -z "$content" ||
113 test_expect_success
"--batch without size ($type)" '
116 maybe_remove_timestamp "$content" $no_ts
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
124 hello_content
="Hello World"
125 hello_size
=$
(strlen
"$hello_content")
126 hello_sha1
=$
(echo_without_newline
"$hello_content" | git hash-object
--stdin)
128 test_expect_success
"setup" '
129 echo_without_newline "$hello_content" > hello &&
130 git update-index --add hello
133 run_tests
'blob' $hello_sha1 $hello_size "$hello_content" "$hello_content"
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
143 tree_sha1
=$
(git write-tree
)
144 tree_size
=$
(($
(test_oid rawsz
) + 13))
145 tree_pretty_content
="100644 blob $hello_sha1 hello"
147 run_tests
'tree' $tree_sha1 $tree_size "" "$tree_pretty_content"
149 commit_message
="Initial commit"
150 commit_sha1
=$
(echo_without_newline
"$commit_message" | git commit-tree
$tree_sha1)
151 commit_size
=$
(($
(test_oid hexsz
) + 137))
152 commit_content
="tree $tree_sha1
153 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 0000000000 +0000
154 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 0000000000 +0000
158 run_tests
'commit' $commit_sha1 $commit_size "$commit_content" "$commit_content" 1
160 tag_header_without_timestamp
="object $hello_sha1
163 tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
164 tag_description
="This is a tag"
165 tag_content
="$tag_header_without_timestamp 0000000000 +0000
169 tag_sha1
=$
(echo_without_newline
"$tag_content" | git hash-object
-t tag
--stdin -w)
170 tag_size
=$
(strlen
"$tag_content")
172 run_tests
'tag' $tag_sha1 $tag_size "$tag_content" "$tag_content" 1
174 test_expect_success \
175 "Reach a blob from a tag pointing to it" \
176 "test '$hello_content' = \"\$(git cat-file blob $tag_sha1)\""
178 for batch in batch batch-check
182 test_expect_success
"Passing -$opt with --$batch fails" '
183 test_must_fail git cat-file --$batch -$opt $hello_sha1
186 test_expect_success
"Passing --$batch with -$opt fails" '
187 test_must_fail git cat-file -$opt --$batch $hello_sha1
191 test_expect_success
"Passing <type> with --$batch fails" '
192 test_must_fail git cat-file --$batch blob $hello_sha1
195 test_expect_success
"Passing --$batch with <type> fails" '
196 test_must_fail git cat-file blob --$batch $hello_sha1
199 test_expect_success
"Passing sha1 with --$batch fails" '
200 test_must_fail git cat-file --$batch $hello_sha1
206 test_expect_success
"Passing -$opt with --follow-symlinks fails" '
207 test_must_fail git cat-file --follow-symlinks -$opt $hello_sha1
211 test_expect_success
"--batch-check for a non-existent named object" '
212 test "foobar42 missing
213 foobar84 missing" = \
214 "$( ( echo foobar42 && echo_without_newline foobar84 ) | git cat-file --batch-check)"
217 test_expect_success
"--batch-check for a non-existent hash" '
218 test "0000000000000000000000000000000000000042 missing
219 0000000000000000000000000000000000000084 missing" = \
220 "$( ( echo 0000000000000000000000000000000000000042 &&
221 echo_without_newline 0000000000000000000000000000000000000084 ) |
222 git cat-file --batch-check)"
225 test_expect_success
"--batch for an existent and a non-existent hash" '
226 test "$tag_sha1 tag $tag_size
228 0000000000000000000000000000000000000000 missing" = \
229 "$( ( echo $tag_sha1 &&
230 echo_without_newline 0000000000000000000000000000000000000000 ) |
231 git cat-file --batch)"
234 test_expect_success
"--batch-check for an empty line" '
235 test " missing" = "$(echo | git cat-file --batch-check)"
238 test_expect_success
'empty --batch-check notices missing object' '
239 echo "$ZERO_OID missing" >expect &&
240 echo "$ZERO_OID" | git cat-file --batch-check="" >actual &&
241 test_cmp expect actual
244 batch_input
="$hello_sha1
251 batch_output
="$hello_sha1 blob $hello_size
253 $commit_sha1 commit $commit_size
255 $tag_sha1 tag $tag_size
260 test_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)"
264 batch_check_input
="$hello_sha1
272 batch_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
279 test_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)"
284 test_expect_success
'setup blobs which are likely to delta' '
285 test-tool genrandom foo 10240 >foo &&
286 { cat foo && echo plus; } >foo-plus &&
287 git add foo foo-plus &&
295 test_expect_success
'confirm that neither loose blob is a delta' '
296 cat >expect <<-EOF &&
300 git cat-file --batch-check="%(deltabase)" <blobs >actual &&
301 test_cmp expect actual
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.
309 test_expect_success
'%(deltabase) reports packed delta bases' '
311 git cat-file --batch-check="%(deltabase)" <blobs >actual &&
313 grep "$(git rev-parse HEAD:foo)" actual ||
314 grep "$(git rev-parse HEAD:foo-plus)" actual
318 test_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) &&
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)
330 for arg1
in '' --allow-unknown-type
334 if test "$arg1" = "--allow-unknown-type" && test "$arg2" = "-p"
340 test_expect_success
"cat-file $arg1 $arg2 error on bogus short OID" '
341 cat >expect <<-\EOF &&
342 fatal: invalid object type
345 if test "$arg1" = "--allow-unknown-type"
347 git cat-file $arg1 $arg2 $bogus_short_sha1
349 test_must_fail git cat-file $arg1 $arg2 $bogus_short_sha1 >out 2>actual &&
350 test_must_be_empty out &&
351 test_cmp expect actual
355 test_expect_success
"cat-file $arg1 $arg2 error on bogus full OID" '
356 if test "$arg2" = "-p"
359 error: header for $bogus_long_sha1 too long, exceeds 32 bytes
360 fatal: Not a valid object name $bogus_long_sha1
364 error: header for $bogus_long_sha1 too long, exceeds 32 bytes
365 fatal: git cat-file: could not get object info
369 if test "$arg1" = "--allow-unknown-type"
371 git cat-file $arg1 $arg2 $bogus_short_sha1
373 test_must_fail git cat-file $arg1 $arg2 $bogus_long_sha1 >out 2>actual &&
374 test_must_be_empty out &&
375 test_cmp expect actual
379 test_expect_success
"cat-file $arg1 $arg2 error on missing short OID" '
380 cat >expect.err <<-EOF &&
381 fatal: Not a valid object name $(test_oid deadbeef_short)
383 test_must_fail git cat-file $arg1 $arg2 $(test_oid deadbeef_short) >out 2>err.actual &&
384 test_must_be_empty out
387 test_expect_success
"cat-file $arg1 $arg2 error on missing full OID" '
388 if test "$arg2" = "-p"
390 cat >expect.err <<-EOF
391 fatal: Not a valid object name $(test_oid deadbeef)
394 cat >expect.err <<-\EOF
395 fatal: git cat-file: could not get object info
398 test_must_fail git cat-file $arg1 $arg2 $(test_oid deadbeef) >out 2>err.actual &&
399 test_must_be_empty out &&
400 test_cmp expect.err err.actual
405 test_expect_success
'-e is OK with a broken object without --allow-unknown-type' '
406 git cat-file -e $bogus_short_sha1
409 test_expect_success
'-e can not be combined with --allow-unknown-type' '
410 test_expect_code 128 git cat-file -e --allow-unknown-type $bogus_short_sha1
413 test_expect_success
'-p cannot print a broken object even with --allow-unknown-type' '
414 test_must_fail git cat-file -p $bogus_short_sha1 &&
415 test_expect_code 128 git cat-file -p --allow-unknown-type $bogus_short_sha1
418 test_expect_success
'<type> <hash> does not work with objects of broken types' '
419 cat >err.expect <<-\EOF &&
420 fatal: invalid object type "bogus"
422 test_must_fail git cat-file $bogus_short_type $bogus_short_sha1 2>err.actual &&
423 test_cmp err.expect err.actual
426 test_expect_success
'broken types combined with --batch and --batch-check' '
427 echo $bogus_short_sha1 >bogus-oid &&
429 cat >err.expect <<-\EOF &&
430 fatal: invalid object type
433 test_must_fail git cat-file --batch <bogus-oid 2>err.actual &&
434 test_cmp err.expect err.actual &&
436 test_must_fail git cat-file --batch-check <bogus-oid 2>err.actual &&
437 test_cmp err.expect err.actual
440 test_expect_success
'the --batch and --batch-check options do not combine with --allow-unknown-type' '
441 test_expect_code 128 git cat-file --batch --allow-unknown-type <bogus-oid &&
442 test_expect_code 128 git cat-file --batch-check --allow-unknown-type <bogus-oid
445 test_expect_success
'the --allow-unknown-type option does not consider replacement refs' '
446 cat >expect <<-EOF &&
449 git cat-file -t --allow-unknown-type $bogus_short_sha1 >actual &&
450 test_cmp expect actual &&
452 # Create it manually, as "git replace" will die on bogus
454 head=$(git rev-parse --verify HEAD) &&
455 test_when_finished "test-tool ref-store main delete-refs 0 msg refs/replace/$bogus_short_sha1" &&
456 test-tool ref-store main update-ref msg "refs/replace/$bogus_short_sha1" $head $ZERO_OID REF_SKIP_OID_VERIFICATION &&
458 cat >expect <<-EOF &&
461 git cat-file -t --allow-unknown-type $bogus_short_sha1 >actual &&
462 test_cmp expect actual
465 test_expect_success
"Type of broken object is correct" '
466 echo $bogus_short_type >expect &&
467 git cat-file -t --allow-unknown-type $bogus_short_sha1 >actual &&
468 test_cmp expect actual
471 test_expect_success
"Size of broken object is correct" '
472 echo $bogus_short_size >expect &&
473 git cat-file -s --allow-unknown-type $bogus_short_sha1 >actual &&
474 test_cmp expect actual
477 test_expect_success
'clean up broken object' '
478 rm .git/objects/$(test_oid_to_path $bogus_short_sha1)
481 test_expect_success
"Type of broken object is correct when type is large" '
482 echo $bogus_long_type >expect &&
483 git cat-file -t --allow-unknown-type $bogus_long_sha1 >actual &&
484 test_cmp expect actual
487 test_expect_success
"Size of large broken object is correct when type is large" '
488 echo $bogus_long_size >expect &&
489 git cat-file -s --allow-unknown-type $bogus_long_sha1 >actual &&
490 test_cmp expect actual
493 test_expect_success
'clean up broken object' '
494 rm .git/objects/$(test_oid_to_path $bogus_long_sha1)
497 test_expect_success
'cat-file -t and -s on corrupt loose object' '
498 git init --bare corrupt-loose.git &&
500 cd corrupt-loose.git &&
502 # Setup and create the empty blob and its path
503 empty_path=$(git rev-parse --git-path objects/$(test_oid_to_path "$EMPTY_BLOB")) &&
504 git hash-object -w --stdin </dev/null &&
506 # Create another blob and its path
507 echo other >other.blob &&
508 other_blob=$(git hash-object -w --stdin <other.blob) &&
509 other_path=$(git rev-parse --git-path objects/$(test_oid_to_path "$other_blob")) &&
511 # Before the swap the size is 0
512 cat >out.expect <<-EOF &&
515 git cat-file -s "$EMPTY_BLOB" >out.actual 2>err.actual &&
516 test_must_be_empty err.actual &&
517 test_cmp out.expect out.actual &&
519 # Swap the two to corrupt the repository
520 mv -f "$other_path" "$empty_path" &&
521 test_must_fail git fsck 2>err.fsck &&
522 grep "hash-path mismatch" err.fsck &&
524 # confirm that cat-file is reading the new swapped-in
526 cat >out.expect <<-EOF &&
529 git cat-file -t "$EMPTY_BLOB" >out.actual 2>err.actual &&
530 test_must_be_empty err.actual &&
531 test_cmp out.expect out.actual &&
533 # ... since it has a different size now.
534 cat >out.expect <<-EOF &&
537 git cat-file -s "$EMPTY_BLOB" >out.actual 2>err.actual &&
538 test_must_be_empty err.actual &&
539 test_cmp out.expect out.actual &&
541 # So far "cat-file" has been happy to spew the found
542 # content out as-is. Try to make it zlib-invalid.
543 mv -f other.blob "$empty_path" &&
544 test_must_fail git fsck 2>err.fsck &&
545 grep "^error: inflate: data stream error (" err.fsck
549 # Tests for git cat-file --follow-symlinks
550 test_expect_success
'prep for symlink tests' '
551 echo_without_newline "$hello_content" >morx &&
552 test_ln_s_add morx same-dir-link &&
553 test_ln_s_add dir link-to-dir &&
554 test_ln_s_add ../fleem out-of-repo-link &&
555 test_ln_s_add .. out-of-repo-link-dir &&
556 test_ln_s_add same-dir-link link-to-link &&
557 test_ln_s_add nope broken-same-dir-link &&
559 test_ln_s_add ../morx dir/parent-dir-link &&
560 test_ln_s_add .. dir/link-dir &&
561 test_ln_s_add ../../escape dir/out-of-repo-link &&
562 test_ln_s_add ../.. dir/out-of-repo-link-dir &&
563 test_ln_s_add nope dir/broken-link-in-dir &&
565 test_ln_s_add ../../morx dir/subdir/grandparent-dir-link &&
566 test_ln_s_add ../../../great-escape dir/subdir/out-of-repo-link &&
567 test_ln_s_add ../../.. dir/subdir/out-of-repo-link-dir &&
568 test_ln_s_add ../../../ dir/subdir/out-of-repo-link-dir-trailing &&
569 test_ln_s_add ../parent-dir-link dir/subdir/parent-dir-link-to-link &&
570 echo_without_newline "$hello_content" >dir/subdir/ind2 &&
571 echo_without_newline "$hello_content" >dir/ind1 &&
572 test_ln_s_add dir dirlink &&
573 test_ln_s_add dir/subdir subdirlink &&
574 test_ln_s_add subdir/ind2 dir/link-to-child &&
575 test_ln_s_add dir/link-to-child link-to-down-link &&
576 test_ln_s_add dir/.. up-down &&
577 test_ln_s_add dir/../ up-down-trailing &&
578 test_ln_s_add dir/../morx up-down-file &&
579 test_ln_s_add dir/../../morx up-up-down-file &&
580 test_ln_s_add subdirlink/../../morx up-two-down-file &&
581 test_ln_s_add loop1 loop2 &&
582 test_ln_s_add loop2 loop1 &&
583 git add morx dir/subdir/ind2 dir/ind1 &&
584 git commit -am "test" &&
585 echo $hello_sha1 blob $hello_size >found
588 test_expect_success
'git cat-file --batch-check --follow-symlinks works for non-links' '
589 echo HEAD:morx | git cat-file --batch-check --follow-symlinks >actual &&
590 test_cmp found actual &&
591 echo HEAD:nope missing >expect &&
592 echo HEAD:nope | git cat-file --batch-check --follow-symlinks >actual &&
593 test_cmp expect actual
596 test_expect_success
'git cat-file --batch-check --follow-symlinks works for in-repo, same-dir links' '
597 echo HEAD:same-dir-link | git cat-file --batch-check --follow-symlinks >actual &&
598 test_cmp found actual
601 test_expect_success
'git cat-file --batch-check --follow-symlinks works for in-repo, links to dirs' '
602 echo HEAD:link-to-dir/ind1 | git cat-file --batch-check --follow-symlinks >actual &&
603 test_cmp found actual
607 test_expect_success
'git cat-file --batch-check --follow-symlinks works for broken in-repo, same-dir links' '
608 echo dangling 25 >expect &&
609 echo HEAD:broken-same-dir-link >>expect &&
610 echo HEAD:broken-same-dir-link | git cat-file --batch-check --follow-symlinks >actual &&
611 test_cmp expect actual
614 test_expect_success
'git cat-file --batch-check --follow-symlinks works for same-dir links-to-links' '
615 echo HEAD:link-to-link | git cat-file --batch-check --follow-symlinks >actual &&
616 test_cmp found actual
619 test_expect_success
'git cat-file --batch-check --follow-symlinks works for parent-dir links' '
620 echo HEAD:dir/parent-dir-link | git cat-file --batch-check --follow-symlinks >actual &&
621 test_cmp found actual &&
622 echo notdir 29 >expect &&
623 echo HEAD:dir/parent-dir-link/nope >>expect &&
624 echo HEAD:dir/parent-dir-link/nope | git cat-file --batch-check --follow-symlinks >actual &&
625 test_cmp expect actual
628 test_expect_success
'git cat-file --batch-check --follow-symlinks works for .. links' '
629 echo dangling 22 >expect &&
630 echo HEAD:dir/link-dir/nope >>expect &&
631 echo HEAD:dir/link-dir/nope | git cat-file --batch-check --follow-symlinks >actual &&
632 test_cmp expect actual &&
633 echo HEAD:dir/link-dir/morx | git cat-file --batch-check --follow-symlinks >actual &&
634 test_cmp found actual &&
635 echo dangling 27 >expect &&
636 echo HEAD:dir/broken-link-in-dir >>expect &&
637 echo HEAD:dir/broken-link-in-dir | git cat-file --batch-check --follow-symlinks >actual &&
638 test_cmp expect actual
641 test_expect_success
'git cat-file --batch-check --follow-symlinks works for ../.. links' '
642 echo notdir 41 >expect &&
643 echo HEAD:dir/subdir/grandparent-dir-link/nope >>expect &&
644 echo HEAD:dir/subdir/grandparent-dir-link/nope | git cat-file --batch-check --follow-symlinks >actual &&
645 test_cmp expect actual &&
646 echo HEAD:dir/subdir/grandparent-dir-link | git cat-file --batch-check --follow-symlinks >actual &&
647 test_cmp found actual &&
648 echo HEAD:dir/subdir/parent-dir-link-to-link | git cat-file --batch-check --follow-symlinks >actual &&
649 test_cmp found actual
652 test_expect_success
'git cat-file --batch-check --follow-symlinks works for dir/ links' '
653 echo dangling 17 >expect &&
654 echo HEAD:dirlink/morx >>expect &&
655 echo HEAD:dirlink/morx | git cat-file --batch-check --follow-symlinks >actual &&
656 test_cmp expect actual &&
657 echo $hello_sha1 blob $hello_size >expect &&
658 echo HEAD:dirlink/ind1 | git cat-file --batch-check --follow-symlinks >actual &&
659 test_cmp expect actual
662 test_expect_success
'git cat-file --batch-check --follow-symlinks works for dir/subdir links' '
663 echo dangling 20 >expect &&
664 echo HEAD:subdirlink/morx >>expect &&
665 echo HEAD:subdirlink/morx | git cat-file --batch-check --follow-symlinks >actual &&
666 test_cmp expect actual &&
667 echo HEAD:subdirlink/ind2 | git cat-file --batch-check --follow-symlinks >actual &&
668 test_cmp found actual
671 test_expect_success
'git cat-file --batch-check --follow-symlinks works for dir ->subdir links' '
672 echo notdir 27 >expect &&
673 echo HEAD:dir/link-to-child/morx >>expect &&
674 echo HEAD:dir/link-to-child/morx | git cat-file --batch-check --follow-symlinks >actual &&
675 test_cmp expect actual &&
676 echo HEAD:dir/link-to-child | git cat-file --batch-check --follow-symlinks >actual &&
677 test_cmp found actual &&
678 echo HEAD:link-to-down-link | git cat-file --batch-check --follow-symlinks >actual &&
679 test_cmp found actual
682 test_expect_success
'git cat-file --batch-check --follow-symlinks works for out-of-repo symlinks' '
683 echo symlink 8 >expect &&
684 echo ../fleem >>expect &&
685 echo HEAD:out-of-repo-link | git cat-file --batch-check --follow-symlinks >actual &&
686 test_cmp expect actual &&
687 echo symlink 2 >expect &&
689 echo HEAD:out-of-repo-link-dir | git cat-file --batch-check --follow-symlinks >actual &&
690 test_cmp expect actual
693 test_expect_success
'git cat-file --batch-check --follow-symlinks works for out-of-repo symlinks in dirs' '
694 echo symlink 9 >expect &&
695 echo ../escape >>expect &&
696 echo HEAD:dir/out-of-repo-link | git cat-file --batch-check --follow-symlinks >actual &&
697 test_cmp expect actual &&
698 echo symlink 2 >expect &&
700 echo HEAD:dir/out-of-repo-link-dir | git cat-file --batch-check --follow-symlinks >actual &&
701 test_cmp expect actual
704 test_expect_success
'git cat-file --batch-check --follow-symlinks works for out-of-repo symlinks in subdirs' '
705 echo symlink 15 >expect &&
706 echo ../great-escape >>expect &&
707 echo HEAD:dir/subdir/out-of-repo-link | git cat-file --batch-check --follow-symlinks >actual &&
708 test_cmp expect actual &&
709 echo symlink 2 >expect &&
711 echo HEAD:dir/subdir/out-of-repo-link-dir | git cat-file --batch-check --follow-symlinks >actual &&
712 test_cmp expect actual &&
713 echo symlink 3 >expect &&
715 echo HEAD:dir/subdir/out-of-repo-link-dir-trailing | git cat-file --batch-check --follow-symlinks >actual &&
716 test_cmp expect actual
719 test_expect_success
'git cat-file --batch-check --follow-symlinks works for symlinks with internal ..' '
720 echo HEAD: | git cat-file --batch-check >expect &&
721 echo HEAD:up-down | git cat-file --batch-check --follow-symlinks >actual &&
722 test_cmp expect actual &&
723 echo HEAD:up-down-trailing | git cat-file --batch-check --follow-symlinks >actual &&
724 test_cmp expect actual &&
725 echo HEAD:up-down-file | git cat-file --batch-check --follow-symlinks >actual &&
726 test_cmp found actual &&
727 echo symlink 7 >expect &&
728 echo ../morx >>expect &&
729 echo HEAD:up-up-down-file | git cat-file --batch-check --follow-symlinks >actual &&
730 test_cmp expect actual &&
731 echo HEAD:up-two-down-file | git cat-file --batch-check --follow-symlinks >actual &&
732 test_cmp found actual
735 test_expect_success
'git cat-file --batch-check --follow-symlink breaks loops' '
736 echo loop 10 >expect &&
737 echo HEAD:loop1 >>expect &&
738 echo HEAD:loop1 | git cat-file --batch-check --follow-symlinks >actual &&
739 test_cmp expect actual
742 test_expect_success
'git cat-file --batch --follow-symlink returns correct sha and mode' '
743 echo HEAD:morx | git cat-file --batch >expect &&
744 echo HEAD:morx | git cat-file --batch --follow-symlinks >actual &&
745 test_cmp expect actual
748 test_expect_success
'cat-file --batch-all-objects shows all objects' '
749 # make new repos so we know the full set of objects; we will
750 # also make sure that there are some packed and some loose
751 # objects, some referenced and some not, some duplicates, and that
752 # there are some available only via alternates.
756 echo content >file &&
758 git commit -qm base &&
759 git rev-parse HEAD HEAD^{tree} HEAD:file &&
761 echo not-cloned | git hash-object -w --stdin
762 ) >expect.unsorted &&
763 git clone -s all-one all-two &&
766 echo local-unref | git hash-object -w --stdin
767 ) >>expect.unsorted &&
768 git -C all-two rev-parse HEAD:file |
769 git -C all-two pack-objects .git/objects/pack/pack &&
770 sort <expect.unsorted >expect &&
771 git -C all-two cat-file --batch-all-objects \
772 --batch-check="%(objectname)" >actual &&
773 test_cmp expect actual
776 # The only user-visible difference is that the objects are no longer sorted,
777 # and the resulting sort order is undefined. So we can only check that it
778 # produces the same objects as the ordered case, but that at least exercises
780 test_expect_success
'cat-file --unordered works' '
781 git -C all-two cat-file --batch-all-objects --unordered \
782 --batch-check="%(objectname)" >actual.unsorted &&
783 sort <actual.unsorted >actual &&
784 test_cmp expect actual
787 test_expect_success
'set up object list for --batch-all-objects tests' '
788 git -C all-two cat-file --batch-all-objects --batch-check="%(objectname)" >objects
791 test_expect_success
'cat-file --batch="%(objectname)" with --batch-all-objects will work' '
792 git -C all-two cat-file --batch="%(objectname)" <objects >expect &&
793 git -C all-two cat-file --batch-all-objects --batch="%(objectname)" >actual &&
797 test_expect_success
'cat-file --batch="%(rest)" with --batch-all-objects will work' '
798 git -C all-two cat-file --batch="%(rest)" <objects >expect &&
799 git -C all-two cat-file --batch-all-objects --batch="%(rest)" >actual &&
803 test_expect_success
'cat-file --batch="batman" with --batch-all-objects will work' '
804 git -C all-two cat-file --batch="batman" <objects >expect &&
805 git -C all-two cat-file --batch-all-objects --batch="batman" >actual &&
809 test_expect_success
'set up replacement object' '
810 orig=$(git rev-parse HEAD) &&
811 git cat-file commit $orig >orig &&
816 fake=$(git hash-object -t commit -w fake) &&
817 orig_size=$(git cat-file -s $orig) &&
818 fake_size=$(git cat-file -s $fake) &&
819 git replace $orig $fake
822 test_expect_success
'cat-file --batch respects replace objects' '
823 git cat-file --batch >actual <<-EOF &&
827 echo "$orig commit $fake_size" &&
831 test_cmp expect actual
834 test_expect_success
'cat-file --batch-check respects replace objects' '
835 git cat-file --batch-check >actual <<-EOF &&
838 echo "$orig commit $fake_size" >expect &&
839 test_cmp expect actual
842 # Pull the entry for object with oid "$1" out of the output of
843 # "cat-file --batch", including its object content (which requires
844 # parsing and reading a set amount of bytes, hence perl).
845 extract_batch_output
() {
847 BEGIN { $oid = shift }
848 if (/^$oid \S+ (\d+)$/) {
850 read STDIN, my $buf, $1;
857 test_expect_success
'cat-file --batch-all-objects --batch ignores replace' '
858 git cat-file --batch-all-objects --batch >actual.raw &&
859 extract_batch_output $orig <actual.raw >actual &&
861 echo "$orig commit $orig_size" &&
865 test_cmp expect actual
868 test_expect_success
'cat-file --batch-all-objects --batch-check ignores replace' '
869 git cat-file --batch-all-objects --batch-check >actual.raw &&
870 grep ^$orig actual.raw >actual &&
871 echo "$orig commit $orig_size" >expect &&
872 test_cmp expect actual