3 test_description
='git cat-file'
7 test_cmdmode_usage
() {
8 test_expect_code
129 "$@" 2>err
&&
9 grep "^error:.*is incompatible with" err
17 '--textconv --filters' \
18 '--batch-all-objects -e'
20 test_expect_success
"usage: cmdmode $switches" '
21 test_cmdmode_usage git cat-file $switches
25 test_incompatible_usage
() {
26 test_expect_code
129 "$@" 2>err
&&
27 grep -E "^(fatal|error):.*(requires|incompatible with|needs)" err
30 for opt
in --batch --batch-check
32 test_expect_success
"usage: incompatible options: --path with $opt" '
33 test_incompatible_usage git cat-file --path=foo $opt
37 test_missing_usage
() {
38 test_expect_code
129 "$@" 2>err
&&
39 grep -E "^fatal:.*required" err
42 short_modes
="-e -p -t -s"
43 cw_modes
="--textconv --filters"
47 test_expect_success
"usage: $opt requires another option" '
48 test_missing_usage git cat-file $opt
52 for opt
in $short_modes
54 test_expect_success
"usage: $opt requires another option" '
55 test_missing_usage git cat-file $opt
61 "--path=foo HEAD:some-path.txt"
63 test_expect_success
"usage: incompatible options: $opt and $opt2" '
64 test_incompatible_usage git cat-file $opt $opt2
69 test_too_many_arguments
() {
70 test_expect_code
129 "$@" 2>err
&&
71 grep -E "^fatal: too many arguments$" err
74 for opt
in $short_modes $cw_modes
77 test_expect_success
"usage: too many arguments: $opt $args" '
78 test_too_many_arguments git cat-file $opt $args
81 for opt2
in --buffer --follow-symlinks
83 test_expect_success
"usage: incompatible arguments: $opt with batch option $opt2" '
84 test_incompatible_usage git cat-file $opt $opt2
93 test_expect_success
"usage: bad option combination: $opt without batch mode" '
94 test_incompatible_usage git cat-file $opt &&
95 test_incompatible_usage git cat-file $opt commit HEAD
99 echo_without_newline
() {
104 echo_without_newline
"$1" |
wc -c |
sed -e 's/^ *//'
107 maybe_remove_timestamp
() {
108 if test -z "$2"; then
109 echo_without_newline
"$1"
111 echo_without_newline
"$(printf '%s\n' "$1" | sed -e 's/ [0-9][0-9]* [-+][0-9][0-9][0-9][0-9]$//')"
123 batch_output
="$sha1 $type $size
126 test_expect_success
"$type exists" '
127 git cat-file -e $sha1
130 test_expect_success
"Type of $type is correct" '
131 echo $type >expect &&
132 git cat-file -t $sha1 >actual &&
133 test_cmp expect actual
136 test_expect_success
"Size of $type is correct" '
137 echo $size >expect &&
138 git cat-file -s $sha1 >actual &&
139 test_cmp expect actual
142 test_expect_success
"Type of $type is correct using --allow-unknown-type" '
143 echo $type >expect &&
144 git cat-file -t --allow-unknown-type $sha1 >actual &&
145 test_cmp expect actual
148 test_expect_success
"Size of $type is correct using --allow-unknown-type" '
149 echo $size >expect &&
150 git cat-file -s --allow-unknown-type $sha1 >actual &&
151 test_cmp expect actual
154 test -z "$content" ||
155 test_expect_success
"Content of $type is correct" '
156 maybe_remove_timestamp "$content" $no_ts >expect &&
157 maybe_remove_timestamp "$(git cat-file $type $sha1)" $no_ts >actual &&
158 test_cmp expect actual
161 test_expect_success
"Pretty content of $type is correct" '
162 maybe_remove_timestamp "$pretty_content" $no_ts >expect &&
163 maybe_remove_timestamp "$(git cat-file -p $sha1)" $no_ts >actual &&
164 test_cmp expect actual
167 test -z "$content" ||
168 test_expect_success
"--batch output of $type is correct" '
169 maybe_remove_timestamp "$batch_output" $no_ts >expect &&
170 maybe_remove_timestamp "$(echo $sha1 | git cat-file --batch)" $no_ts >actual &&
171 test_cmp expect actual
174 test_expect_success
"--batch-check output of $type is correct" '
175 echo "$sha1 $type $size" >expect &&
176 echo_without_newline $sha1 | git cat-file --batch-check >actual &&
177 test_cmp expect actual
180 test_expect_success
"custom --batch-check format" '
181 echo "$type $sha1" >expect &&
182 echo $sha1 | git cat-file --batch-check="%(objecttype) %(objectname)" >actual &&
183 test_cmp expect actual
186 test_expect_success
'--batch-check with %(rest)' '
187 echo "$type this is some extra content" >expect &&
188 echo "$sha1 this is some extra content" |
189 git cat-file --batch-check="%(objecttype) %(rest)" >actual &&
190 test_cmp expect actual
193 test -z "$content" ||
194 test_expect_success
"--batch without type ($type)" '
197 maybe_remove_timestamp "$content" $no_ts
199 echo $sha1 | git cat-file --batch="%(objectsize)" >actual.full &&
200 maybe_remove_timestamp "$(cat actual.full)" $no_ts >actual &&
201 test_cmp expect actual
204 test -z "$content" ||
205 test_expect_success
"--batch without size ($type)" '
208 maybe_remove_timestamp "$content" $no_ts
210 echo $sha1 | git cat-file --batch="%(objecttype)" >actual.full &&
211 maybe_remove_timestamp "$(cat actual.full)" $no_ts >actual &&
212 test_cmp expect actual
216 hello_content
="Hello World"
217 hello_size
=$
(strlen
"$hello_content")
218 hello_sha1
=$
(echo_without_newline
"$hello_content" | git hash-object
--stdin)
220 test_expect_success
"setup" '
221 echo_without_newline "$hello_content" > hello &&
222 git update-index --add hello
225 run_tests
'blob' $hello_sha1 $hello_size "$hello_content" "$hello_content"
227 test_expect_success
'--batch-check without %(rest) considers whole line' '
228 echo "$hello_sha1 blob $hello_size" >expect &&
229 git update-index --add --cacheinfo 100644 $hello_sha1 "white space" &&
230 test_when_finished "git update-index --remove \"white space\"" &&
231 echo ":white space" | git cat-file --batch-check >actual &&
232 test_cmp expect actual
235 tree_sha1
=$
(git write-tree
)
236 tree_size
=$
(($
(test_oid rawsz
) + 13))
237 tree_pretty_content
="100644 blob $hello_sha1 hello"
239 run_tests
'tree' $tree_sha1 $tree_size "" "$tree_pretty_content"
241 commit_message
="Initial commit"
242 commit_sha1
=$
(echo_without_newline
"$commit_message" | git commit-tree
$tree_sha1)
243 commit_size
=$
(($
(test_oid hexsz
) + 137))
244 commit_content
="tree $tree_sha1
245 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 0000000000 +0000
246 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 0000000000 +0000
250 run_tests
'commit' $commit_sha1 $commit_size "$commit_content" "$commit_content" 1
252 tag_header_without_timestamp
="object $hello_sha1
255 tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
256 tag_description
="This is a tag"
257 tag_content
="$tag_header_without_timestamp 0000000000 +0000
261 tag_sha1
=$
(echo_without_newline
"$tag_content" | git hash-object
-t tag
--stdin -w)
262 tag_size
=$
(strlen
"$tag_content")
264 run_tests
'tag' $tag_sha1 $tag_size "$tag_content" "$tag_content" 1
266 test_expect_success \
267 "Reach a blob from a tag pointing to it" \
268 "test '$hello_content' = \"\$(git cat-file blob $tag_sha1)\""
270 for batch in batch batch-check
274 test_expect_success
"Passing -$opt with --$batch fails" '
275 test_must_fail git cat-file --$batch -$opt $hello_sha1
278 test_expect_success
"Passing --$batch with -$opt fails" '
279 test_must_fail git cat-file -$opt --$batch $hello_sha1
283 test_expect_success
"Passing <type> with --$batch fails" '
284 test_must_fail git cat-file --$batch blob $hello_sha1
287 test_expect_success
"Passing --$batch with <type> fails" '
288 test_must_fail git cat-file blob --$batch $hello_sha1
291 test_expect_success
"Passing sha1 with --$batch fails" '
292 test_must_fail git cat-file --$batch $hello_sha1
298 test_expect_success
"Passing -$opt with --follow-symlinks fails" '
299 test_must_fail git cat-file --follow-symlinks -$opt $hello_sha1
303 test_expect_success
"--batch-check for a non-existent named object" '
304 test "foobar42 missing
305 foobar84 missing" = \
306 "$( ( echo foobar42 && echo_without_newline foobar84 ) | git cat-file --batch-check)"
309 test_expect_success
"--batch-check for a non-existent hash" '
310 test "0000000000000000000000000000000000000042 missing
311 0000000000000000000000000000000000000084 missing" = \
312 "$( ( echo 0000000000000000000000000000000000000042 &&
313 echo_without_newline 0000000000000000000000000000000000000084 ) |
314 git cat-file --batch-check)"
317 test_expect_success
"--batch for an existent and a non-existent hash" '
318 test "$tag_sha1 tag $tag_size
320 0000000000000000000000000000000000000000 missing" = \
321 "$( ( echo $tag_sha1 &&
322 echo_without_newline 0000000000000000000000000000000000000000 ) |
323 git cat-file --batch)"
326 test_expect_success
"--batch-check for an empty line" '
327 test " missing" = "$(echo | git cat-file --batch-check)"
330 test_expect_success
'empty --batch-check notices missing object' '
331 echo "$ZERO_OID missing" >expect &&
332 echo "$ZERO_OID" | git cat-file --batch-check="" >actual &&
333 test_cmp expect actual
336 batch_input
="$hello_sha1
343 batch_output
="$hello_sha1 blob $hello_size
345 $commit_sha1 commit $commit_size
347 $tag_sha1 tag $tag_size
352 test_expect_success
'--batch with multiple sha1s gives correct format' '
353 test "$(maybe_remove_timestamp "$batch_output" 1)" = "$(maybe_remove_timestamp "$(echo_without_newline "$batch_input" | git cat-file --batch)" 1)"
356 batch_check_input
="$hello_sha1
364 batch_check_output
="$hello_sha1 blob $hello_size
365 $tree_sha1 tree $tree_size
366 $commit_sha1 commit $commit_size
367 $tag_sha1 tag $tag_size
371 test_expect_success
"--batch-check with multiple sha1s gives correct format" '
372 test "$batch_check_output" = \
373 "$(echo_without_newline "$batch_check_input" | git cat-file --batch-check)"
376 test_expect_success
'setup blobs which are likely to delta' '
377 test-tool genrandom foo 10240 >foo &&
378 { cat foo && echo plus; } >foo-plus &&
379 git add foo foo-plus &&
387 test_expect_success
'confirm that neither loose blob is a delta' '
388 cat >expect <<-EOF &&
392 git cat-file --batch-check="%(deltabase)" <blobs >actual &&
393 test_cmp expect actual
396 # To avoid relying too much on the current delta heuristics,
397 # we will check only that one of the two objects is a delta
398 # against the other, but not the order. We can do so by just
399 # asking for the base of both, and checking whether either
400 # sha1 appears in the output.
401 test_expect_success
'%(deltabase) reports packed delta bases' '
403 git cat-file --batch-check="%(deltabase)" <blobs >actual &&
405 grep "$(git rev-parse HEAD:foo)" actual ||
406 grep "$(git rev-parse HEAD:foo-plus)" actual
410 test_expect_success
'setup bogus data' '
411 bogus_short_type="bogus" &&
412 bogus_short_content="bogus" &&
413 bogus_short_size=$(strlen "$bogus_short_content") &&
414 bogus_short_sha1=$(echo_without_newline "$bogus_short_content" | git hash-object -t $bogus_short_type --literally -w --stdin) &&
416 bogus_long_type="abcdefghijklmnopqrstuvwxyz1234679" &&
417 bogus_long_content="bogus" &&
418 bogus_long_size=$(strlen "$bogus_long_content") &&
419 bogus_long_sha1=$(echo_without_newline "$bogus_long_content" | git hash-object -t $bogus_long_type --literally -w --stdin)
422 for arg1
in '' --allow-unknown-type
426 if test "$arg1" = "--allow-unknown-type" && test "$arg2" = "-p"
432 test_expect_success
"cat-file $arg1 $arg2 error on bogus short OID" '
433 cat >expect <<-\EOF &&
434 fatal: invalid object type
437 if test "$arg1" = "--allow-unknown-type"
439 git cat-file $arg1 $arg2 $bogus_short_sha1
441 test_must_fail git cat-file $arg1 $arg2 $bogus_short_sha1 >out 2>actual &&
442 test_must_be_empty out &&
443 test_cmp expect actual
447 test_expect_success
"cat-file $arg1 $arg2 error on bogus full OID" '
448 if test "$arg2" = "-p"
451 error: header for $bogus_long_sha1 too long, exceeds 32 bytes
452 fatal: Not a valid object name $bogus_long_sha1
456 error: header for $bogus_long_sha1 too long, exceeds 32 bytes
457 fatal: git cat-file: could not get object info
461 if test "$arg1" = "--allow-unknown-type"
463 git cat-file $arg1 $arg2 $bogus_short_sha1
465 test_must_fail git cat-file $arg1 $arg2 $bogus_long_sha1 >out 2>actual &&
466 test_must_be_empty out &&
467 test_cmp expect actual
471 test_expect_success
"cat-file $arg1 $arg2 error on missing short OID" '
472 cat >expect.err <<-EOF &&
473 fatal: Not a valid object name $(test_oid deadbeef_short)
475 test_must_fail git cat-file $arg1 $arg2 $(test_oid deadbeef_short) >out 2>err.actual &&
476 test_must_be_empty out
479 test_expect_success
"cat-file $arg1 $arg2 error on missing full OID" '
480 if test "$arg2" = "-p"
482 cat >expect.err <<-EOF
483 fatal: Not a valid object name $(test_oid deadbeef)
486 cat >expect.err <<-\EOF
487 fatal: git cat-file: could not get object info
490 test_must_fail git cat-file $arg1 $arg2 $(test_oid deadbeef) >out 2>err.actual &&
491 test_must_be_empty out &&
492 test_cmp expect.err err.actual
497 test_expect_success
'-e is OK with a broken object without --allow-unknown-type' '
498 git cat-file -e $bogus_short_sha1
501 test_expect_success
'-e can not be combined with --allow-unknown-type' '
502 test_expect_code 128 git cat-file -e --allow-unknown-type $bogus_short_sha1
505 test_expect_success
'-p cannot print a broken object even with --allow-unknown-type' '
506 test_must_fail git cat-file -p $bogus_short_sha1 &&
507 test_expect_code 128 git cat-file -p --allow-unknown-type $bogus_short_sha1
510 test_expect_success
'<type> <hash> does not work with objects of broken types' '
511 cat >err.expect <<-\EOF &&
512 fatal: invalid object type "bogus"
514 test_must_fail git cat-file $bogus_short_type $bogus_short_sha1 2>err.actual &&
515 test_cmp err.expect err.actual
518 test_expect_success
'broken types combined with --batch and --batch-check' '
519 echo $bogus_short_sha1 >bogus-oid &&
521 cat >err.expect <<-\EOF &&
522 fatal: invalid object type
525 test_must_fail git cat-file --batch <bogus-oid 2>err.actual &&
526 test_cmp err.expect err.actual &&
528 test_must_fail git cat-file --batch-check <bogus-oid 2>err.actual &&
529 test_cmp err.expect err.actual
532 test_expect_success
'the --batch and --batch-check options do not combine with --allow-unknown-type' '
533 test_expect_code 128 git cat-file --batch --allow-unknown-type <bogus-oid &&
534 test_expect_code 128 git cat-file --batch-check --allow-unknown-type <bogus-oid
537 test_expect_success
'the --allow-unknown-type option does not consider replacement refs' '
538 cat >expect <<-EOF &&
541 git cat-file -t --allow-unknown-type $bogus_short_sha1 >actual &&
542 test_cmp expect actual &&
544 # Create it manually, as "git replace" will die on bogus
546 head=$(git rev-parse --verify HEAD) &&
547 test_when_finished "test-tool ref-store main delete-refs 0 msg refs/replace/$bogus_short_sha1" &&
548 test-tool ref-store main update-ref msg "refs/replace/$bogus_short_sha1" $head $ZERO_OID REF_SKIP_OID_VERIFICATION &&
550 cat >expect <<-EOF &&
553 git cat-file -t --allow-unknown-type $bogus_short_sha1 >actual &&
554 test_cmp expect actual
557 test_expect_success
"Type of broken object is correct" '
558 echo $bogus_short_type >expect &&
559 git cat-file -t --allow-unknown-type $bogus_short_sha1 >actual &&
560 test_cmp expect actual
563 test_expect_success
"Size of broken object is correct" '
564 echo $bogus_short_size >expect &&
565 git cat-file -s --allow-unknown-type $bogus_short_sha1 >actual &&
566 test_cmp expect actual
569 test_expect_success
'clean up broken object' '
570 rm .git/objects/$(test_oid_to_path $bogus_short_sha1)
573 test_expect_success
"Type of broken object is correct when type is large" '
574 echo $bogus_long_type >expect &&
575 git cat-file -t --allow-unknown-type $bogus_long_sha1 >actual &&
576 test_cmp expect actual
579 test_expect_success
"Size of large broken object is correct when type is large" '
580 echo $bogus_long_size >expect &&
581 git cat-file -s --allow-unknown-type $bogus_long_sha1 >actual &&
582 test_cmp expect actual
585 test_expect_success
'clean up broken object' '
586 rm .git/objects/$(test_oid_to_path $bogus_long_sha1)
589 test_expect_success
'cat-file -t and -s on corrupt loose object' '
590 git init --bare corrupt-loose.git &&
592 cd corrupt-loose.git &&
594 # Setup and create the empty blob and its path
595 empty_path=$(git rev-parse --git-path objects/$(test_oid_to_path "$EMPTY_BLOB")) &&
596 git hash-object -w --stdin </dev/null &&
598 # Create another blob and its path
599 echo other >other.blob &&
600 other_blob=$(git hash-object -w --stdin <other.blob) &&
601 other_path=$(git rev-parse --git-path objects/$(test_oid_to_path "$other_blob")) &&
603 # Before the swap the size is 0
604 cat >out.expect <<-EOF &&
607 git cat-file -s "$EMPTY_BLOB" >out.actual 2>err.actual &&
608 test_must_be_empty err.actual &&
609 test_cmp out.expect out.actual &&
611 # Swap the two to corrupt the repository
612 mv -f "$other_path" "$empty_path" &&
613 test_must_fail git fsck 2>err.fsck &&
614 grep "hash-path mismatch" err.fsck &&
616 # confirm that cat-file is reading the new swapped-in
618 cat >out.expect <<-EOF &&
621 git cat-file -t "$EMPTY_BLOB" >out.actual 2>err.actual &&
622 test_must_be_empty err.actual &&
623 test_cmp out.expect out.actual &&
625 # ... since it has a different size now.
626 cat >out.expect <<-EOF &&
629 git cat-file -s "$EMPTY_BLOB" >out.actual 2>err.actual &&
630 test_must_be_empty err.actual &&
631 test_cmp out.expect out.actual &&
633 # So far "cat-file" has been happy to spew the found
634 # content out as-is. Try to make it zlib-invalid.
635 mv -f other.blob "$empty_path" &&
636 test_must_fail git fsck 2>err.fsck &&
637 grep "^error: inflate: data stream error (" err.fsck
641 # Tests for git cat-file --follow-symlinks
642 test_expect_success
'prep for symlink tests' '
643 echo_without_newline "$hello_content" >morx &&
644 test_ln_s_add morx same-dir-link &&
645 test_ln_s_add dir link-to-dir &&
646 test_ln_s_add ../fleem out-of-repo-link &&
647 test_ln_s_add .. out-of-repo-link-dir &&
648 test_ln_s_add same-dir-link link-to-link &&
649 test_ln_s_add nope broken-same-dir-link &&
651 test_ln_s_add ../morx dir/parent-dir-link &&
652 test_ln_s_add .. dir/link-dir &&
653 test_ln_s_add ../../escape dir/out-of-repo-link &&
654 test_ln_s_add ../.. dir/out-of-repo-link-dir &&
655 test_ln_s_add nope dir/broken-link-in-dir &&
657 test_ln_s_add ../../morx dir/subdir/grandparent-dir-link &&
658 test_ln_s_add ../../../great-escape dir/subdir/out-of-repo-link &&
659 test_ln_s_add ../../.. dir/subdir/out-of-repo-link-dir &&
660 test_ln_s_add ../../../ dir/subdir/out-of-repo-link-dir-trailing &&
661 test_ln_s_add ../parent-dir-link dir/subdir/parent-dir-link-to-link &&
662 echo_without_newline "$hello_content" >dir/subdir/ind2 &&
663 echo_without_newline "$hello_content" >dir/ind1 &&
664 test_ln_s_add dir dirlink &&
665 test_ln_s_add dir/subdir subdirlink &&
666 test_ln_s_add subdir/ind2 dir/link-to-child &&
667 test_ln_s_add dir/link-to-child link-to-down-link &&
668 test_ln_s_add dir/.. up-down &&
669 test_ln_s_add dir/../ up-down-trailing &&
670 test_ln_s_add dir/../morx up-down-file &&
671 test_ln_s_add dir/../../morx up-up-down-file &&
672 test_ln_s_add subdirlink/../../morx up-two-down-file &&
673 test_ln_s_add loop1 loop2 &&
674 test_ln_s_add loop2 loop1 &&
675 git add morx dir/subdir/ind2 dir/ind1 &&
676 git commit -am "test" &&
677 echo $hello_sha1 blob $hello_size >found
680 test_expect_success
'git cat-file --batch-check --follow-symlinks works for non-links' '
681 echo HEAD:morx | git cat-file --batch-check --follow-symlinks >actual &&
682 test_cmp found actual &&
683 echo HEAD:nope missing >expect &&
684 echo HEAD:nope | git cat-file --batch-check --follow-symlinks >actual &&
685 test_cmp expect actual
688 test_expect_success
'git cat-file --batch-check --follow-symlinks works for in-repo, same-dir links' '
689 echo HEAD:same-dir-link | git cat-file --batch-check --follow-symlinks >actual &&
690 test_cmp found actual
693 test_expect_success
'git cat-file --batch-check --follow-symlinks works for in-repo, links to dirs' '
694 echo HEAD:link-to-dir/ind1 | git cat-file --batch-check --follow-symlinks >actual &&
695 test_cmp found actual
699 test_expect_success
'git cat-file --batch-check --follow-symlinks works for broken in-repo, same-dir links' '
700 echo dangling 25 >expect &&
701 echo HEAD:broken-same-dir-link >>expect &&
702 echo HEAD:broken-same-dir-link | git cat-file --batch-check --follow-symlinks >actual &&
703 test_cmp expect actual
706 test_expect_success
'git cat-file --batch-check --follow-symlinks works for same-dir links-to-links' '
707 echo HEAD:link-to-link | git cat-file --batch-check --follow-symlinks >actual &&
708 test_cmp found actual
711 test_expect_success
'git cat-file --batch-check --follow-symlinks works for parent-dir links' '
712 echo HEAD:dir/parent-dir-link | git cat-file --batch-check --follow-symlinks >actual &&
713 test_cmp found actual &&
714 echo notdir 29 >expect &&
715 echo HEAD:dir/parent-dir-link/nope >>expect &&
716 echo HEAD:dir/parent-dir-link/nope | git cat-file --batch-check --follow-symlinks >actual &&
717 test_cmp expect actual
720 test_expect_success
'git cat-file --batch-check --follow-symlinks works for .. links' '
721 echo dangling 22 >expect &&
722 echo HEAD:dir/link-dir/nope >>expect &&
723 echo HEAD:dir/link-dir/nope | git cat-file --batch-check --follow-symlinks >actual &&
724 test_cmp expect actual &&
725 echo HEAD:dir/link-dir/morx | git cat-file --batch-check --follow-symlinks >actual &&
726 test_cmp found actual &&
727 echo dangling 27 >expect &&
728 echo HEAD:dir/broken-link-in-dir >>expect &&
729 echo HEAD:dir/broken-link-in-dir | git cat-file --batch-check --follow-symlinks >actual &&
730 test_cmp expect actual
733 test_expect_success
'git cat-file --batch-check --follow-symlinks works for ../.. links' '
734 echo notdir 41 >expect &&
735 echo HEAD:dir/subdir/grandparent-dir-link/nope >>expect &&
736 echo HEAD:dir/subdir/grandparent-dir-link/nope | git cat-file --batch-check --follow-symlinks >actual &&
737 test_cmp expect actual &&
738 echo HEAD:dir/subdir/grandparent-dir-link | git cat-file --batch-check --follow-symlinks >actual &&
739 test_cmp found actual &&
740 echo HEAD:dir/subdir/parent-dir-link-to-link | git cat-file --batch-check --follow-symlinks >actual &&
741 test_cmp found actual
744 test_expect_success
'git cat-file --batch-check --follow-symlinks works for dir/ links' '
745 echo dangling 17 >expect &&
746 echo HEAD:dirlink/morx >>expect &&
747 echo HEAD:dirlink/morx | git cat-file --batch-check --follow-symlinks >actual &&
748 test_cmp expect actual &&
749 echo $hello_sha1 blob $hello_size >expect &&
750 echo HEAD:dirlink/ind1 | git cat-file --batch-check --follow-symlinks >actual &&
751 test_cmp expect actual
754 test_expect_success
'git cat-file --batch-check --follow-symlinks works for dir/subdir links' '
755 echo dangling 20 >expect &&
756 echo HEAD:subdirlink/morx >>expect &&
757 echo HEAD:subdirlink/morx | git cat-file --batch-check --follow-symlinks >actual &&
758 test_cmp expect actual &&
759 echo HEAD:subdirlink/ind2 | git cat-file --batch-check --follow-symlinks >actual &&
760 test_cmp found actual
763 test_expect_success
'git cat-file --batch-check --follow-symlinks works for dir ->subdir links' '
764 echo notdir 27 >expect &&
765 echo HEAD:dir/link-to-child/morx >>expect &&
766 echo HEAD:dir/link-to-child/morx | git cat-file --batch-check --follow-symlinks >actual &&
767 test_cmp expect actual &&
768 echo HEAD:dir/link-to-child | git cat-file --batch-check --follow-symlinks >actual &&
769 test_cmp found actual &&
770 echo HEAD:link-to-down-link | git cat-file --batch-check --follow-symlinks >actual &&
771 test_cmp found actual
774 test_expect_success
'git cat-file --batch-check --follow-symlinks works for out-of-repo symlinks' '
775 echo symlink 8 >expect &&
776 echo ../fleem >>expect &&
777 echo HEAD:out-of-repo-link | git cat-file --batch-check --follow-symlinks >actual &&
778 test_cmp expect actual &&
779 echo symlink 2 >expect &&
781 echo HEAD:out-of-repo-link-dir | git cat-file --batch-check --follow-symlinks >actual &&
782 test_cmp expect actual
785 test_expect_success
'git cat-file --batch-check --follow-symlinks works for out-of-repo symlinks in dirs' '
786 echo symlink 9 >expect &&
787 echo ../escape >>expect &&
788 echo HEAD:dir/out-of-repo-link | git cat-file --batch-check --follow-symlinks >actual &&
789 test_cmp expect actual &&
790 echo symlink 2 >expect &&
792 echo HEAD:dir/out-of-repo-link-dir | git cat-file --batch-check --follow-symlinks >actual &&
793 test_cmp expect actual
796 test_expect_success
'git cat-file --batch-check --follow-symlinks works for out-of-repo symlinks in subdirs' '
797 echo symlink 15 >expect &&
798 echo ../great-escape >>expect &&
799 echo HEAD:dir/subdir/out-of-repo-link | git cat-file --batch-check --follow-symlinks >actual &&
800 test_cmp expect actual &&
801 echo symlink 2 >expect &&
803 echo HEAD:dir/subdir/out-of-repo-link-dir | git cat-file --batch-check --follow-symlinks >actual &&
804 test_cmp expect actual &&
805 echo symlink 3 >expect &&
807 echo HEAD:dir/subdir/out-of-repo-link-dir-trailing | git cat-file --batch-check --follow-symlinks >actual &&
808 test_cmp expect actual
811 test_expect_success
'git cat-file --batch-check --follow-symlinks works for symlinks with internal ..' '
812 echo HEAD: | git cat-file --batch-check >expect &&
813 echo HEAD:up-down | git cat-file --batch-check --follow-symlinks >actual &&
814 test_cmp expect actual &&
815 echo HEAD:up-down-trailing | git cat-file --batch-check --follow-symlinks >actual &&
816 test_cmp expect actual &&
817 echo HEAD:up-down-file | git cat-file --batch-check --follow-symlinks >actual &&
818 test_cmp found actual &&
819 echo symlink 7 >expect &&
820 echo ../morx >>expect &&
821 echo HEAD:up-up-down-file | git cat-file --batch-check --follow-symlinks >actual &&
822 test_cmp expect actual &&
823 echo HEAD:up-two-down-file | git cat-file --batch-check --follow-symlinks >actual &&
824 test_cmp found actual
827 test_expect_success
'git cat-file --batch-check --follow-symlink breaks loops' '
828 echo loop 10 >expect &&
829 echo HEAD:loop1 >>expect &&
830 echo HEAD:loop1 | git cat-file --batch-check --follow-symlinks >actual &&
831 test_cmp expect actual
834 test_expect_success
'git cat-file --batch --follow-symlink returns correct sha and mode' '
835 echo HEAD:morx | git cat-file --batch >expect &&
836 echo HEAD:morx | git cat-file --batch --follow-symlinks >actual &&
837 test_cmp expect actual
840 test_expect_success
'cat-file --batch-all-objects shows all objects' '
841 # make new repos so we know the full set of objects; we will
842 # also make sure that there are some packed and some loose
843 # objects, some referenced and some not, some duplicates, and that
844 # there are some available only via alternates.
848 echo content >file &&
850 git commit -qm base &&
851 git rev-parse HEAD HEAD^{tree} HEAD:file &&
853 echo not-cloned | git hash-object -w --stdin
854 ) >expect.unsorted &&
855 git clone -s all-one all-two &&
858 echo local-unref | git hash-object -w --stdin
859 ) >>expect.unsorted &&
860 git -C all-two rev-parse HEAD:file |
861 git -C all-two pack-objects .git/objects/pack/pack &&
862 sort <expect.unsorted >expect &&
863 git -C all-two cat-file --batch-all-objects \
864 --batch-check="%(objectname)" >actual &&
865 test_cmp expect actual
868 # The only user-visible difference is that the objects are no longer sorted,
869 # and the resulting sort order is undefined. So we can only check that it
870 # produces the same objects as the ordered case, but that at least exercises
872 test_expect_success
'cat-file --unordered works' '
873 git -C all-two cat-file --batch-all-objects --unordered \
874 --batch-check="%(objectname)" >actual.unsorted &&
875 sort <actual.unsorted >actual &&
876 test_cmp expect actual
879 test_expect_success
'set up object list for --batch-all-objects tests' '
880 git -C all-two cat-file --batch-all-objects --batch-check="%(objectname)" >objects
883 test_expect_success
'cat-file --batch="%(objectname)" with --batch-all-objects will work' '
884 git -C all-two cat-file --batch="%(objectname)" <objects >expect &&
885 git -C all-two cat-file --batch-all-objects --batch="%(objectname)" >actual &&
889 test_expect_success
'cat-file --batch="%(rest)" with --batch-all-objects will work' '
890 git -C all-two cat-file --batch="%(rest)" <objects >expect &&
891 git -C all-two cat-file --batch-all-objects --batch="%(rest)" >actual &&
895 test_expect_success
'cat-file --batch="batman" with --batch-all-objects will work' '
896 git -C all-two cat-file --batch="batman" <objects >expect &&
897 git -C all-two cat-file --batch-all-objects --batch="batman" >actual &&
901 test_expect_success
'set up replacement object' '
902 orig=$(git rev-parse HEAD) &&
903 git cat-file commit $orig >orig &&
908 fake=$(git hash-object -t commit -w fake) &&
909 orig_size=$(git cat-file -s $orig) &&
910 fake_size=$(git cat-file -s $fake) &&
911 git replace $orig $fake
914 test_expect_success
'cat-file --batch respects replace objects' '
915 git cat-file --batch >actual <<-EOF &&
919 echo "$orig commit $fake_size" &&
923 test_cmp expect actual
926 test_expect_success
'cat-file --batch-check respects replace objects' '
927 git cat-file --batch-check >actual <<-EOF &&
930 echo "$orig commit $fake_size" >expect &&
931 test_cmp expect actual
934 # Pull the entry for object with oid "$1" out of the output of
935 # "cat-file --batch", including its object content (which requires
936 # parsing and reading a set amount of bytes, hence perl).
937 extract_batch_output
() {
939 BEGIN { $oid = shift }
940 if (/^$oid \S+ (\d+)$/) {
942 read STDIN, my $buf, $1;
949 test_expect_success
'cat-file --batch-all-objects --batch ignores replace' '
950 git cat-file --batch-all-objects --batch >actual.raw &&
951 extract_batch_output $orig <actual.raw >actual &&
953 echo "$orig commit $orig_size" &&
957 test_cmp expect actual
960 test_expect_success
'cat-file --batch-all-objects --batch-check ignores replace' '
961 git cat-file --batch-all-objects --batch-check >actual.raw &&
962 grep ^$orig actual.raw >actual &&
963 echo "$orig commit $orig_size" >expect &&
964 test_cmp expect actual