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
94 test_expect_success
"usage: bad option combination: $opt without batch mode" '
95 test_incompatible_usage git cat-file $opt &&
96 test_incompatible_usage git cat-file $opt commit HEAD
100 echo_without_newline
() {
104 echo_without_newline_nul
() {
105 echo_without_newline
"$@" |
tr '\n' '\0'
109 echo_without_newline
"$1" |
wc -c |
sed -e 's/^ *//'
119 batch_output
="$sha1 $type $size
122 test_expect_success
"$type exists" '
123 git cat-file -e $sha1
126 test_expect_success
"Type of $type is correct" '
127 echo $type >expect &&
128 git cat-file -t $sha1 >actual &&
129 test_cmp expect actual
132 test_expect_success
"Size of $type is correct" '
133 echo $size >expect &&
134 git cat-file -s $sha1 >actual &&
135 test_cmp expect actual
138 test_expect_success
"Type of $type is correct using --allow-unknown-type" '
139 echo $type >expect &&
140 git cat-file -t --allow-unknown-type $sha1 >actual &&
141 test_cmp expect actual
144 test_expect_success
"Size of $type is correct using --allow-unknown-type" '
145 echo $size >expect &&
146 git cat-file -s --allow-unknown-type $sha1 >actual &&
147 test_cmp expect actual
150 test -z "$content" ||
151 test_expect_success
"Content of $type is correct" '
152 echo_without_newline "$content" >expect &&
153 git cat-file $type $sha1 >actual &&
154 test_cmp expect actual
157 test_expect_success
"Pretty content of $type is correct" '
158 echo_without_newline "$pretty_content" >expect &&
159 git cat-file -p $sha1 >actual &&
160 test_cmp expect actual
163 test -z "$content" ||
164 test_expect_success
"--batch output of $type is correct" '
165 echo "$batch_output" >expect &&
166 echo $sha1 | git cat-file --batch >actual &&
167 test_cmp expect actual
170 test_expect_success
"--batch-check output of $type is correct" '
171 echo "$sha1 $type $size" >expect &&
172 echo_without_newline $sha1 | git cat-file --batch-check >actual &&
173 test_cmp expect actual
176 for opt
in --buffer --no-buffer
178 test -z "$content" ||
179 test_expect_success
"--batch-command $opt output of $type content is correct" '
180 echo "$batch_output" >expect &&
181 test_write_lines "contents $sha1" | git cat-file --batch-command $opt >actual &&
182 test_cmp expect actual
185 test_expect_success
"--batch-command $opt output of $type info is correct" '
186 echo "$sha1 $type $size" >expect &&
187 test_write_lines "info $sha1" |
188 git cat-file --batch-command $opt >actual &&
189 test_cmp expect actual
193 test_expect_success
"custom --batch-check format" '
194 echo "$type $sha1" >expect &&
195 echo $sha1 | git cat-file --batch-check="%(objecttype) %(objectname)" >actual &&
196 test_cmp expect actual
199 test_expect_success
"custom --batch-command format" '
200 echo "$type $sha1" >expect &&
201 echo "info $sha1" | git cat-file --batch-command="%(objecttype) %(objectname)" >actual &&
202 test_cmp expect actual
205 test_expect_success
'--batch-check with %(rest)' '
206 echo "$type this is some extra content" >expect &&
207 echo "$sha1 this is some extra content" |
208 git cat-file --batch-check="%(objecttype) %(rest)" >actual &&
209 test_cmp expect actual
212 test -z "$content" ||
213 test_expect_success
"--batch without type ($type)" '
218 echo $sha1 | git cat-file --batch="%(objectsize)" >actual &&
219 test_cmp expect actual
222 test -z "$content" ||
223 test_expect_success
"--batch without size ($type)" '
228 echo $sha1 | git cat-file --batch="%(objecttype)" >actual &&
229 test_cmp expect actual
233 hello_content
="Hello World"
234 hello_size
=$
(strlen
"$hello_content")
235 hello_sha1
=$
(echo_without_newline
"$hello_content" | git hash-object
--stdin)
237 test_expect_success
"setup" '
238 echo_without_newline "$hello_content" > hello &&
239 git update-index --add hello
242 run_tests
'blob' $hello_sha1 $hello_size "$hello_content" "$hello_content"
244 test_expect_success
'--batch-command --buffer with flush for blob info' '
245 echo "$hello_sha1 blob $hello_size" >expect &&
246 test_write_lines "info $hello_sha1" "flush" |
247 GIT_TEST_CAT_FILE_NO_FLUSH_ON_EXIT=1 \
248 git cat-file --batch-command --buffer >actual &&
249 test_cmp expect actual
252 test_expect_success
'--batch-command --buffer without flush for blob info' '
254 test_write_lines "info $hello_sha1" |
255 GIT_TEST_CAT_FILE_NO_FLUSH_ON_EXIT=1 \
256 git cat-file --batch-command --buffer >>output &&
257 test_must_be_empty output
260 test_expect_success
'--batch-check without %(rest) considers whole line' '
261 echo "$hello_sha1 blob $hello_size" >expect &&
262 git update-index --add --cacheinfo 100644 $hello_sha1 "white space" &&
263 test_when_finished "git update-index --remove \"white space\"" &&
264 echo ":white space" | git cat-file --batch-check >actual &&
265 test_cmp expect actual
268 tree_sha1
=$
(git write-tree
)
269 tree_size
=$
(($
(test_oid rawsz
) + 13))
270 tree_pretty_content
="100644 blob $hello_sha1 hello${LF}"
272 run_tests
'tree' $tree_sha1 $tree_size "" "$tree_pretty_content"
274 commit_message
="Initial commit"
275 commit_sha1
=$
(echo_without_newline
"$commit_message" | git commit-tree
$tree_sha1)
276 commit_size
=$
(($
(test_oid hexsz
) + 137))
277 commit_content
="tree $tree_sha1
278 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE
279 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
283 run_tests
'commit' $commit_sha1 $commit_size "$commit_content" "$commit_content"
285 tag_header_without_timestamp
="object $hello_sha1
288 tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
289 tag_description
="This is a tag"
290 tag_content
="$tag_header_without_timestamp 0 +0000
294 tag_sha1
=$
(echo_without_newline
"$tag_content" | git hash-object
-t tag
--stdin -w)
295 tag_size
=$
(strlen
"$tag_content")
297 run_tests
'tag' $tag_sha1 $tag_size "$tag_content" "$tag_content"
299 test_expect_success
"Reach a blob from a tag pointing to it" '
300 echo_without_newline "$hello_content" >expect &&
301 git cat-file blob $tag_sha1 >actual &&
302 test_cmp expect actual
305 for batch in batch batch-check batch-command
309 test_expect_success
"Passing -$opt with --$batch fails" '
310 test_must_fail git cat-file --$batch -$opt $hello_sha1
313 test_expect_success
"Passing --$batch with -$opt fails" '
314 test_must_fail git cat-file -$opt --$batch $hello_sha1
318 test_expect_success
"Passing <type> with --$batch fails" '
319 test_must_fail git cat-file --$batch blob $hello_sha1
322 test_expect_success
"Passing --$batch with <type> fails" '
323 test_must_fail git cat-file blob --$batch $hello_sha1
326 test_expect_success
"Passing sha1 with --$batch fails" '
327 test_must_fail git cat-file --$batch $hello_sha1
333 test_expect_success
"Passing -$opt with --follow-symlinks fails" '
334 test_must_fail git cat-file --follow-symlinks -$opt $hello_sha1
338 test_expect_success
"--batch-check for a non-existent named object" '
339 cat >expect <<-EOF &&
344 printf "foobar42\nfoobar84" >in &&
345 git cat-file --batch-check <in >actual &&
346 test_cmp expect actual
349 test_expect_success
"--batch-check for a non-existent hash" '
350 cat >expect <<-EOF &&
351 0000000000000000000000000000000000000042 missing
352 0000000000000000000000000000000000000084 missing
355 printf "0000000000000000000000000000000000000042\n0000000000000000000000000000000000000084" >in &&
356 git cat-file --batch-check <in >actual &&
357 test_cmp expect actual
360 test_expect_success
"--batch for an existent and a non-existent hash" '
361 cat >expect <<-EOF &&
362 $tag_sha1 tag $tag_size
364 0000000000000000000000000000000000000000 missing
367 printf "$tag_sha1\n0000000000000000000000000000000000000000" >in &&
368 git cat-file --batch <in >actual &&
369 test_cmp expect actual
372 test_expect_success
"--batch-check for an empty line" '
373 cat >expect <<-EOF &&
378 git cat-file --batch-check <in >actual &&
379 test_cmp expect actual
382 test_expect_success
'empty --batch-check notices missing object' '
383 echo "$ZERO_OID missing" >expect &&
384 echo "$ZERO_OID" | git cat-file --batch-check="" >actual &&
385 test_cmp expect actual
388 batch_input
="$hello_sha1
395 batch_output
="$hello_sha1 blob $hello_size
397 $commit_sha1 commit $commit_size
399 $tag_sha1 tag $tag_size
404 test_expect_success
'--batch with multiple sha1s gives correct format' '
405 echo "$batch_output" >expect &&
406 echo_without_newline "$batch_input" >in &&
407 git cat-file --batch <in >actual &&
408 test_cmp expect actual
411 test_expect_success
'--batch, -z with multiple sha1s gives correct format' '
412 echo_without_newline_nul "$batch_input" >in &&
413 echo "$batch_output" >expect &&
414 git cat-file --batch -z <in >actual &&
415 test_cmp expect actual
418 batch_check_input
="$hello_sha1
426 batch_check_output
="$hello_sha1 blob $hello_size
427 $tree_sha1 tree $tree_size
428 $commit_sha1 commit $commit_size
429 $tag_sha1 tag $tag_size
433 test_expect_success
"--batch-check with multiple sha1s gives correct format" '
434 echo "$batch_check_output" >expect &&
435 echo_without_newline "$batch_check_input" >in &&
436 git cat-file --batch-check <in >actual &&
437 test_cmp expect actual
440 test_expect_success
"--batch-check, -z with multiple sha1s gives correct format" '
441 echo "$batch_check_output" >expect &&
442 echo_without_newline_nul "$batch_check_input" >in &&
443 git cat-file --batch-check -z <in >actual &&
444 test_cmp expect actual
447 test_expect_success FUNNYNAMES
'--batch-check, -z with newline in input' '
448 touch -- "newline${LF}embedded" &&
449 git add -- "newline${LF}embedded" &&
450 git commit -m "file with newline embedded" &&
453 printf "HEAD:newline${LF}embedded" >in &&
454 git cat-file --batch-check -z <in >actual &&
456 echo "$(git rev-parse "HEAD:newline${LF}embedded") blob 0" >expect &&
457 test_cmp expect actual
460 batch_command_multiple_info
="info $hello_sha1
466 test_expect_success
'--batch-command with multiple info calls gives correct format' '
467 cat >expect <<-EOF &&
468 $hello_sha1 blob $hello_size
469 $tree_sha1 tree $tree_size
470 $commit_sha1 commit $commit_size
471 $tag_sha1 tag $tag_size
475 echo "$batch_command_multiple_info" >in &&
476 git cat-file --batch-command --buffer <in >actual &&
478 test_cmp expect actual &&
480 echo "$batch_command_multiple_info" | tr "\n" "\0" >in &&
481 git cat-file --batch-command --buffer -z <in >actual &&
483 test_cmp expect actual
486 batch_command_multiple_contents
="contents $hello_sha1
487 contents $commit_sha1
492 test_expect_success
'--batch-command with multiple command calls gives correct format' '
493 cat >expect <<-EOF &&
494 $hello_sha1 blob $hello_size
496 $commit_sha1 commit $commit_size
498 $tag_sha1 tag $tag_size
503 echo "$batch_command_multiple_contents" >in &&
504 git cat-file --batch-command --buffer <in >actual &&
506 test_cmp expect actual &&
508 echo "$batch_command_multiple_contents" | tr "\n" "\0" >in &&
509 git cat-file --batch-command --buffer -z <in >actual &&
511 test_cmp expect actual
514 test_expect_success
'setup blobs which are likely to delta' '
515 test-tool genrandom foo 10240 >foo &&
516 { cat foo && echo plus; } >foo-plus &&
517 git add foo foo-plus &&
525 test_expect_success
'confirm that neither loose blob is a delta' '
526 cat >expect <<-EOF &&
530 git cat-file --batch-check="%(deltabase)" <blobs >actual &&
531 test_cmp expect actual
534 # To avoid relying too much on the current delta heuristics,
535 # we will check only that one of the two objects is a delta
536 # against the other, but not the order. We can do so by just
537 # asking for the base of both, and checking whether either
538 # sha1 appears in the output.
539 test_expect_success
'%(deltabase) reports packed delta bases' '
541 git cat-file --batch-check="%(deltabase)" <blobs >actual &&
543 grep "$(git rev-parse HEAD:foo)" actual ||
544 grep "$(git rev-parse HEAD:foo-plus)" actual
548 test_expect_success
'setup bogus data' '
549 bogus_short_type="bogus" &&
550 bogus_short_content="bogus" &&
551 bogus_short_size=$(strlen "$bogus_short_content") &&
552 bogus_short_sha1=$(echo_without_newline "$bogus_short_content" | git hash-object -t $bogus_short_type --literally -w --stdin) &&
554 bogus_long_type="abcdefghijklmnopqrstuvwxyz1234679" &&
555 bogus_long_content="bogus" &&
556 bogus_long_size=$(strlen "$bogus_long_content") &&
557 bogus_long_sha1=$(echo_without_newline "$bogus_long_content" | git hash-object -t $bogus_long_type --literally -w --stdin)
560 for arg1
in '' --allow-unknown-type
564 if test "$arg1" = "--allow-unknown-type" && test "$arg2" = "-p"
570 test_expect_success
"cat-file $arg1 $arg2 error on bogus short OID" '
571 cat >expect <<-\EOF &&
572 fatal: invalid object type
575 if test "$arg1" = "--allow-unknown-type"
577 git cat-file $arg1 $arg2 $bogus_short_sha1
579 test_must_fail git cat-file $arg1 $arg2 $bogus_short_sha1 >out 2>actual &&
580 test_must_be_empty out &&
581 test_cmp expect actual
585 test_expect_success
"cat-file $arg1 $arg2 error on bogus full OID" '
586 if test "$arg2" = "-p"
589 error: header for $bogus_long_sha1 too long, exceeds 32 bytes
590 fatal: Not a valid object name $bogus_long_sha1
594 error: header for $bogus_long_sha1 too long, exceeds 32 bytes
595 fatal: git cat-file: could not get object info
599 if test "$arg1" = "--allow-unknown-type"
601 git cat-file $arg1 $arg2 $bogus_short_sha1
603 test_must_fail git cat-file $arg1 $arg2 $bogus_long_sha1 >out 2>actual &&
604 test_must_be_empty out &&
605 test_cmp expect actual
609 test_expect_success
"cat-file $arg1 $arg2 error on missing short OID" '
610 cat >expect.err <<-EOF &&
611 fatal: Not a valid object name $(test_oid deadbeef_short)
613 test_must_fail git cat-file $arg1 $arg2 $(test_oid deadbeef_short) >out 2>err.actual &&
614 test_must_be_empty out &&
615 test_cmp expect.err err.actual
618 test_expect_success
"cat-file $arg1 $arg2 error on missing full OID" '
619 if test "$arg2" = "-p"
621 cat >expect.err <<-EOF
622 fatal: Not a valid object name $(test_oid deadbeef)
625 cat >expect.err <<-\EOF
626 fatal: git cat-file: could not get object info
629 test_must_fail git cat-file $arg1 $arg2 $(test_oid deadbeef) >out 2>err.actual &&
630 test_must_be_empty out &&
631 test_cmp expect.err err.actual
636 test_expect_success
'-e is OK with a broken object without --allow-unknown-type' '
637 git cat-file -e $bogus_short_sha1
640 test_expect_success
'-e can not be combined with --allow-unknown-type' '
641 test_expect_code 128 git cat-file -e --allow-unknown-type $bogus_short_sha1
644 test_expect_success
'-p cannot print a broken object even with --allow-unknown-type' '
645 test_must_fail git cat-file -p $bogus_short_sha1 &&
646 test_expect_code 128 git cat-file -p --allow-unknown-type $bogus_short_sha1
649 test_expect_success
'<type> <hash> does not work with objects of broken types' '
650 cat >err.expect <<-\EOF &&
651 fatal: invalid object type "bogus"
653 test_must_fail git cat-file $bogus_short_type $bogus_short_sha1 2>err.actual &&
654 test_cmp err.expect err.actual
657 test_expect_success
'broken types combined with --batch and --batch-check' '
658 echo $bogus_short_sha1 >bogus-oid &&
660 cat >err.expect <<-\EOF &&
661 fatal: invalid object type
664 test_must_fail git cat-file --batch <bogus-oid 2>err.actual &&
665 test_cmp err.expect err.actual &&
667 test_must_fail git cat-file --batch-check <bogus-oid 2>err.actual &&
668 test_cmp err.expect err.actual
671 test_expect_success
'the --batch and --batch-check options do not combine with --allow-unknown-type' '
672 test_expect_code 128 git cat-file --batch --allow-unknown-type <bogus-oid &&
673 test_expect_code 128 git cat-file --batch-check --allow-unknown-type <bogus-oid
676 test_expect_success
'the --allow-unknown-type option does not consider replacement refs' '
677 cat >expect <<-EOF &&
680 git cat-file -t --allow-unknown-type $bogus_short_sha1 >actual &&
681 test_cmp expect actual &&
683 # Create it manually, as "git replace" will die on bogus
685 head=$(git rev-parse --verify HEAD) &&
686 test_when_finished "test-tool ref-store main delete-refs 0 msg refs/replace/$bogus_short_sha1" &&
687 test-tool ref-store main update-ref msg "refs/replace/$bogus_short_sha1" $head $ZERO_OID REF_SKIP_OID_VERIFICATION &&
689 cat >expect <<-EOF &&
692 git cat-file -t --allow-unknown-type $bogus_short_sha1 >actual &&
693 test_cmp expect actual
696 test_expect_success
"Type of broken object is correct" '
697 echo $bogus_short_type >expect &&
698 git cat-file -t --allow-unknown-type $bogus_short_sha1 >actual &&
699 test_cmp expect actual
702 test_expect_success
"Size of broken object is correct" '
703 echo $bogus_short_size >expect &&
704 git cat-file -s --allow-unknown-type $bogus_short_sha1 >actual &&
705 test_cmp expect actual
708 test_expect_success
'clean up broken object' '
709 rm .git/objects/$(test_oid_to_path $bogus_short_sha1)
712 test_expect_success
"Type of broken object is correct when type is large" '
713 echo $bogus_long_type >expect &&
714 git cat-file -t --allow-unknown-type $bogus_long_sha1 >actual &&
715 test_cmp expect actual
718 test_expect_success
"Size of large broken object is correct when type is large" '
719 echo $bogus_long_size >expect &&
720 git cat-file -s --allow-unknown-type $bogus_long_sha1 >actual &&
721 test_cmp expect actual
724 test_expect_success
'clean up broken object' '
725 rm .git/objects/$(test_oid_to_path $bogus_long_sha1)
728 test_expect_success
'cat-file -t and -s on corrupt loose object' '
729 git init --bare corrupt-loose.git &&
731 cd corrupt-loose.git &&
733 # Setup and create the empty blob and its path
734 empty_path=$(git rev-parse --git-path objects/$(test_oid_to_path "$EMPTY_BLOB")) &&
735 empty_blob=$(git hash-object -w --stdin </dev/null) &&
737 # Create another blob and its path
738 echo other >other.blob &&
739 other_blob=$(git hash-object -w --stdin <other.blob) &&
740 other_path=$(git rev-parse --git-path objects/$(test_oid_to_path "$other_blob")) &&
742 # Before the swap the size is 0
743 cat >out.expect <<-EOF &&
746 git cat-file -s "$EMPTY_BLOB" >out.actual 2>err.actual &&
747 test_must_be_empty err.actual &&
748 test_cmp out.expect out.actual &&
750 # Swap the two to corrupt the repository
751 mv -f "$other_path" "$empty_path" &&
752 test_must_fail git fsck 2>err.fsck &&
753 grep "hash-path mismatch" err.fsck &&
755 # confirm that cat-file is reading the new swapped-in
757 cat >out.expect <<-EOF &&
760 git cat-file -t "$EMPTY_BLOB" >out.actual 2>err.actual &&
761 test_must_be_empty err.actual &&
762 test_cmp out.expect out.actual &&
764 # ... since it has a different size now.
765 cat >out.expect <<-EOF &&
768 git cat-file -s "$EMPTY_BLOB" >out.actual 2>err.actual &&
769 test_must_be_empty err.actual &&
770 test_cmp out.expect out.actual &&
772 # So far "cat-file" has been happy to spew the found
773 # content out as-is. Try to make it zlib-invalid.
774 mv -f other.blob "$empty_path" &&
775 test_must_fail git fsck 2>err.fsck &&
776 cat >expect <<-EOF &&
777 error: inflate: data stream error (incorrect header check)
778 error: unable to unpack header of ./$empty_path
779 error: $empty_blob: object corrupt or missing: ./$empty_path
781 grep "^error: " err.fsck >actual &&
782 test_cmp expect actual
786 # Tests for git cat-file --follow-symlinks
787 test_expect_success
'prep for symlink tests' '
788 echo_without_newline "$hello_content" >morx &&
789 test_ln_s_add morx same-dir-link &&
790 test_ln_s_add dir link-to-dir &&
791 test_ln_s_add ../fleem out-of-repo-link &&
792 test_ln_s_add .. out-of-repo-link-dir &&
793 test_ln_s_add same-dir-link link-to-link &&
794 test_ln_s_add nope broken-same-dir-link &&
796 test_ln_s_add ../morx dir/parent-dir-link &&
797 test_ln_s_add .. dir/link-dir &&
798 test_ln_s_add ../../escape dir/out-of-repo-link &&
799 test_ln_s_add ../.. dir/out-of-repo-link-dir &&
800 test_ln_s_add nope dir/broken-link-in-dir &&
802 test_ln_s_add ../../morx dir/subdir/grandparent-dir-link &&
803 test_ln_s_add ../../../great-escape dir/subdir/out-of-repo-link &&
804 test_ln_s_add ../../.. dir/subdir/out-of-repo-link-dir &&
805 test_ln_s_add ../../../ dir/subdir/out-of-repo-link-dir-trailing &&
806 test_ln_s_add ../parent-dir-link dir/subdir/parent-dir-link-to-link &&
807 echo_without_newline "$hello_content" >dir/subdir/ind2 &&
808 echo_without_newline "$hello_content" >dir/ind1 &&
809 test_ln_s_add dir dirlink &&
810 test_ln_s_add dir/subdir subdirlink &&
811 test_ln_s_add subdir/ind2 dir/link-to-child &&
812 test_ln_s_add dir/link-to-child link-to-down-link &&
813 test_ln_s_add dir/.. up-down &&
814 test_ln_s_add dir/../ up-down-trailing &&
815 test_ln_s_add dir/../morx up-down-file &&
816 test_ln_s_add dir/../../morx up-up-down-file &&
817 test_ln_s_add subdirlink/../../morx up-two-down-file &&
818 test_ln_s_add loop1 loop2 &&
819 test_ln_s_add loop2 loop1 &&
820 git add morx dir/subdir/ind2 dir/ind1 &&
821 git commit -am "test" &&
822 echo $hello_sha1 blob $hello_size >found
825 test_expect_success
'git cat-file --batch-check --follow-symlinks works for non-links' '
826 echo HEAD:morx | git cat-file --batch-check --follow-symlinks >actual &&
827 test_cmp found actual &&
828 echo HEAD:nope missing >expect &&
829 echo HEAD:nope | git cat-file --batch-check --follow-symlinks >actual &&
830 test_cmp expect actual
833 test_expect_success
'git cat-file --batch-check --follow-symlinks works for in-repo, same-dir links' '
834 echo HEAD:same-dir-link | git cat-file --batch-check --follow-symlinks >actual &&
835 test_cmp found actual
838 test_expect_success
'git cat-file --batch-check --follow-symlinks works for in-repo, links to dirs' '
839 echo HEAD:link-to-dir/ind1 | git cat-file --batch-check --follow-symlinks >actual &&
840 test_cmp found actual
844 test_expect_success
'git cat-file --batch-check --follow-symlinks works for broken in-repo, same-dir links' '
845 echo dangling 25 >expect &&
846 echo HEAD:broken-same-dir-link >>expect &&
847 echo HEAD:broken-same-dir-link | git cat-file --batch-check --follow-symlinks >actual &&
848 test_cmp expect actual
851 test_expect_success
'git cat-file --batch-check --follow-symlinks works for same-dir links-to-links' '
852 echo HEAD:link-to-link | git cat-file --batch-check --follow-symlinks >actual &&
853 test_cmp found actual
856 test_expect_success
'git cat-file --batch-check --follow-symlinks works for parent-dir links' '
857 echo HEAD:dir/parent-dir-link | git cat-file --batch-check --follow-symlinks >actual &&
858 test_cmp found actual &&
859 echo notdir 29 >expect &&
860 echo HEAD:dir/parent-dir-link/nope >>expect &&
861 echo HEAD:dir/parent-dir-link/nope | git cat-file --batch-check --follow-symlinks >actual &&
862 test_cmp expect actual
865 test_expect_success
'git cat-file --batch-check --follow-symlinks works for .. links' '
866 echo dangling 22 >expect &&
867 echo HEAD:dir/link-dir/nope >>expect &&
868 echo HEAD:dir/link-dir/nope | git cat-file --batch-check --follow-symlinks >actual &&
869 test_cmp expect actual &&
870 echo HEAD:dir/link-dir/morx | git cat-file --batch-check --follow-symlinks >actual &&
871 test_cmp found actual &&
872 echo dangling 27 >expect &&
873 echo HEAD:dir/broken-link-in-dir >>expect &&
874 echo HEAD:dir/broken-link-in-dir | git cat-file --batch-check --follow-symlinks >actual &&
875 test_cmp expect actual
878 test_expect_success
'git cat-file --batch-check --follow-symlinks works for ../.. links' '
879 echo notdir 41 >expect &&
880 echo HEAD:dir/subdir/grandparent-dir-link/nope >>expect &&
881 echo HEAD:dir/subdir/grandparent-dir-link/nope | git cat-file --batch-check --follow-symlinks >actual &&
882 test_cmp expect actual &&
883 echo HEAD:dir/subdir/grandparent-dir-link | git cat-file --batch-check --follow-symlinks >actual &&
884 test_cmp found actual &&
885 echo HEAD:dir/subdir/parent-dir-link-to-link | git cat-file --batch-check --follow-symlinks >actual &&
886 test_cmp found actual
889 test_expect_success
'git cat-file --batch-check --follow-symlinks works for dir/ links' '
890 echo dangling 17 >expect &&
891 echo HEAD:dirlink/morx >>expect &&
892 echo HEAD:dirlink/morx | git cat-file --batch-check --follow-symlinks >actual &&
893 test_cmp expect actual &&
894 echo $hello_sha1 blob $hello_size >expect &&
895 echo HEAD:dirlink/ind1 | git cat-file --batch-check --follow-symlinks >actual &&
896 test_cmp expect actual
899 test_expect_success
'git cat-file --batch-check --follow-symlinks works for dir/subdir links' '
900 echo dangling 20 >expect &&
901 echo HEAD:subdirlink/morx >>expect &&
902 echo HEAD:subdirlink/morx | git cat-file --batch-check --follow-symlinks >actual &&
903 test_cmp expect actual &&
904 echo HEAD:subdirlink/ind2 | git cat-file --batch-check --follow-symlinks >actual &&
905 test_cmp found actual
908 test_expect_success
'git cat-file --batch-check --follow-symlinks works for dir ->subdir links' '
909 echo notdir 27 >expect &&
910 echo HEAD:dir/link-to-child/morx >>expect &&
911 echo HEAD:dir/link-to-child/morx | git cat-file --batch-check --follow-symlinks >actual &&
912 test_cmp expect actual &&
913 echo HEAD:dir/link-to-child | git cat-file --batch-check --follow-symlinks >actual &&
914 test_cmp found actual &&
915 echo HEAD:link-to-down-link | git cat-file --batch-check --follow-symlinks >actual &&
916 test_cmp found actual
919 test_expect_success
'git cat-file --batch-check --follow-symlinks works for out-of-repo symlinks' '
920 echo symlink 8 >expect &&
921 echo ../fleem >>expect &&
922 echo HEAD:out-of-repo-link | git cat-file --batch-check --follow-symlinks >actual &&
923 test_cmp expect actual &&
924 echo symlink 2 >expect &&
926 echo HEAD:out-of-repo-link-dir | git cat-file --batch-check --follow-symlinks >actual &&
927 test_cmp expect actual
930 test_expect_success
'git cat-file --batch-check --follow-symlinks works for out-of-repo symlinks in dirs' '
931 echo symlink 9 >expect &&
932 echo ../escape >>expect &&
933 echo HEAD:dir/out-of-repo-link | git cat-file --batch-check --follow-symlinks >actual &&
934 test_cmp expect actual &&
935 echo symlink 2 >expect &&
937 echo HEAD:dir/out-of-repo-link-dir | git cat-file --batch-check --follow-symlinks >actual &&
938 test_cmp expect actual
941 test_expect_success
'git cat-file --batch-check --follow-symlinks works for out-of-repo symlinks in subdirs' '
942 echo symlink 15 >expect &&
943 echo ../great-escape >>expect &&
944 echo HEAD:dir/subdir/out-of-repo-link | git cat-file --batch-check --follow-symlinks >actual &&
945 test_cmp expect actual &&
946 echo symlink 2 >expect &&
948 echo HEAD:dir/subdir/out-of-repo-link-dir | git cat-file --batch-check --follow-symlinks >actual &&
949 test_cmp expect actual &&
950 echo symlink 3 >expect &&
952 echo HEAD:dir/subdir/out-of-repo-link-dir-trailing | git cat-file --batch-check --follow-symlinks >actual &&
953 test_cmp expect actual
956 test_expect_success
'git cat-file --batch-check --follow-symlinks works for symlinks with internal ..' '
957 echo HEAD: | git cat-file --batch-check >expect &&
958 echo HEAD:up-down | git cat-file --batch-check --follow-symlinks >actual &&
959 test_cmp expect actual &&
960 echo HEAD:up-down-trailing | git cat-file --batch-check --follow-symlinks >actual &&
961 test_cmp expect actual &&
962 echo HEAD:up-down-file | git cat-file --batch-check --follow-symlinks >actual &&
963 test_cmp found actual &&
964 echo symlink 7 >expect &&
965 echo ../morx >>expect &&
966 echo HEAD:up-up-down-file | git cat-file --batch-check --follow-symlinks >actual &&
967 test_cmp expect actual &&
968 echo HEAD:up-two-down-file | git cat-file --batch-check --follow-symlinks >actual &&
969 test_cmp found actual
972 test_expect_success
'git cat-file --batch-check --follow-symlink breaks loops' '
973 echo loop 10 >expect &&
974 echo HEAD:loop1 >>expect &&
975 echo HEAD:loop1 | git cat-file --batch-check --follow-symlinks >actual &&
976 test_cmp expect actual
979 test_expect_success
'git cat-file --batch --follow-symlink returns correct sha and mode' '
980 echo HEAD:morx | git cat-file --batch >expect &&
981 echo HEAD:morx | git cat-file --batch --follow-symlinks >actual &&
982 test_cmp expect actual
985 test_expect_success
'cat-file --batch-all-objects shows all objects' '
986 # make new repos so we know the full set of objects; we will
987 # also make sure that there are some packed and some loose
988 # objects, some referenced and some not, some duplicates, and that
989 # there are some available only via alternates.
993 echo content >file &&
995 git commit -qm base &&
996 git rev-parse HEAD HEAD^{tree} HEAD:file &&
998 echo not-cloned | git hash-object -w --stdin
999 ) >expect.unsorted &&
1000 git clone -s all-one all-two &&
1003 echo local-unref | git hash-object -w --stdin
1004 ) >>expect.unsorted &&
1005 git -C all-two rev-parse HEAD:file |
1006 git -C all-two pack-objects .git/objects/pack/pack &&
1007 sort <expect.unsorted >expect &&
1008 git -C all-two cat-file --batch-all-objects \
1009 --batch-check="%(objectname)" >actual &&
1010 test_cmp expect actual
1013 # The only user-visible difference is that the objects are no longer sorted,
1014 # and the resulting sort order is undefined. So we can only check that it
1015 # produces the same objects as the ordered case, but that at least exercises
1017 test_expect_success
'cat-file --unordered works' '
1018 git -C all-two cat-file --batch-all-objects --unordered \
1019 --batch-check="%(objectname)" >actual.unsorted &&
1020 sort <actual.unsorted >actual &&
1021 test_cmp expect actual
1024 test_expect_success
'set up object list for --batch-all-objects tests' '
1025 git -C all-two cat-file --batch-all-objects --batch-check="%(objectname)" >objects
1028 test_expect_success
'cat-file --batch="%(objectname)" with --batch-all-objects will work' '
1029 git -C all-two cat-file --batch="%(objectname)" <objects >expect &&
1030 git -C all-two cat-file --batch-all-objects --batch="%(objectname)" >actual &&
1034 test_expect_success
'cat-file --batch="%(rest)" with --batch-all-objects will work' '
1035 git -C all-two cat-file --batch="%(rest)" <objects >expect &&
1036 git -C all-two cat-file --batch-all-objects --batch="%(rest)" >actual &&
1040 test_expect_success
'cat-file --batch="batman" with --batch-all-objects will work' '
1041 git -C all-two cat-file --batch="batman" <objects >expect &&
1042 git -C all-two cat-file --batch-all-objects --batch="batman" >actual &&
1046 test_expect_success
'set up replacement object' '
1047 orig=$(git rev-parse HEAD) &&
1048 git cat-file commit $orig >orig &&
1053 fake=$(git hash-object -t commit -w fake) &&
1054 orig_size=$(git cat-file -s $orig) &&
1055 fake_size=$(git cat-file -s $fake) &&
1056 git replace $orig $fake
1059 test_expect_success
'cat-file --batch respects replace objects' '
1060 git cat-file --batch >actual <<-EOF &&
1064 echo "$orig commit $fake_size" &&
1068 test_cmp expect actual
1071 test_expect_success
'cat-file --batch-check respects replace objects' '
1072 git cat-file --batch-check >actual <<-EOF &&
1075 echo "$orig commit $fake_size" >expect &&
1076 test_cmp expect actual
1079 # Pull the entry for object with oid "$1" out of the output of
1080 # "cat-file --batch", including its object content (which requires
1081 # parsing and reading a set amount of bytes, hence perl).
1082 extract_batch_output
() {
1084 BEGIN { $oid = shift }
1085 if (/^$oid \S+ (\d+)$/) {
1087 read STDIN, my $buf, $1;
1094 test_expect_success
'cat-file --batch-all-objects --batch ignores replace' '
1095 git cat-file --batch-all-objects --batch >actual.raw &&
1096 extract_batch_output $orig <actual.raw >actual &&
1098 echo "$orig commit $orig_size" &&
1102 test_cmp expect actual
1105 test_expect_success
'cat-file --batch-all-objects --batch-check ignores replace' '
1106 git cat-file --batch-all-objects --batch-check >actual.raw &&
1107 grep ^$orig actual.raw >actual &&
1108 echo "$orig commit $orig_size" >expect &&
1109 test_cmp expect actual
1111 test_expect_success
'batch-command empty command' '
1113 test_expect_code 128 git cat-file --batch-command <cmd 2>err &&
1114 grep "^fatal:.*empty command in input.*" err
1117 test_expect_success
'batch-command whitespace before command' '
1118 echo " info deadbeef" >cmd &&
1119 test_expect_code 128 git cat-file --batch-command <cmd 2>err &&
1120 grep "^fatal:.*whitespace before command.*" err
1123 test_expect_success
'batch-command unknown command' '
1124 echo unknown_command >cmd &&
1125 test_expect_code 128 git cat-file --batch-command <cmd 2>err &&
1126 grep "^fatal:.*unknown command.*" err
1129 test_expect_success
'batch-command missing arguments' '
1131 test_expect_code 128 git cat-file --batch-command <cmd 2>err &&
1132 grep "^fatal:.*info requires arguments.*" err
1135 test_expect_success
'batch-command flush with arguments' '
1136 echo "flush arg" >cmd &&
1137 test_expect_code 128 git cat-file --batch-command --buffer <cmd 2>err &&
1138 grep "^fatal:.*flush takes no arguments.*" err
1141 test_expect_success
'batch-command flush without --buffer' '
1142 echo "flush" >cmd &&
1143 test_expect_code 128 git cat-file --batch-command <cmd 2>err &&
1144 grep "^fatal:.*flush is only for --buffer mode.*" err