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" | remove_timestamp)"
115 remove_timestamp
() {
116 sed -e 's/ [0-9][0-9]* [-+][0-9][0-9][0-9][0-9]$//'
128 batch_output
="$sha1 $type $size
131 test_expect_success
"$type exists" '
132 git cat-file -e $sha1
135 test_expect_success
"Type of $type is correct" '
136 echo $type >expect &&
137 git cat-file -t $sha1 >actual &&
138 test_cmp expect actual
141 test_expect_success
"Size of $type is correct" '
142 echo $size >expect &&
143 git cat-file -s $sha1 >actual &&
144 test_cmp expect actual
147 test_expect_success
"Type of $type is correct using --allow-unknown-type" '
148 echo $type >expect &&
149 git cat-file -t --allow-unknown-type $sha1 >actual &&
150 test_cmp expect actual
153 test_expect_success
"Size of $type is correct using --allow-unknown-type" '
154 echo $size >expect &&
155 git cat-file -s --allow-unknown-type $sha1 >actual &&
156 test_cmp expect actual
159 test -z "$content" ||
160 test_expect_success
"Content of $type is correct" '
161 maybe_remove_timestamp "$content" $no_ts >expect &&
162 maybe_remove_timestamp "$(git cat-file $type $sha1)" $no_ts >actual &&
163 test_cmp expect actual
166 test_expect_success
"Pretty content of $type is correct" '
167 maybe_remove_timestamp "$pretty_content" $no_ts >expect &&
168 maybe_remove_timestamp "$(git cat-file -p $sha1)" $no_ts >actual &&
169 test_cmp expect actual
172 test -z "$content" ||
173 test_expect_success
"--batch output of $type is correct" '
174 maybe_remove_timestamp "$batch_output" $no_ts >expect &&
175 maybe_remove_timestamp "$(echo $sha1 | git cat-file --batch)" $no_ts >actual &&
176 test_cmp expect actual
179 test_expect_success
"--batch-check output of $type is correct" '
180 echo "$sha1 $type $size" >expect &&
181 echo_without_newline $sha1 | git cat-file --batch-check >actual &&
182 test_cmp expect actual
185 for opt
in --buffer --no-buffer
187 test -z "$content" ||
188 test_expect_success
"--batch-command $opt output of $type content is correct" '
189 maybe_remove_timestamp "$batch_output" $no_ts >expect &&
190 maybe_remove_timestamp "$(test_write_lines "contents $sha1" |
191 git cat-file --batch-command $opt)" $no_ts >actual &&
192 test_cmp expect actual
195 test_expect_success
"--batch-command $opt output of $type info is correct" '
196 echo "$sha1 $type $size" >expect &&
197 test_write_lines "info $sha1" |
198 git cat-file --batch-command $opt >actual &&
199 test_cmp expect actual
203 test_expect_success
"custom --batch-check format" '
204 echo "$type $sha1" >expect &&
205 echo $sha1 | git cat-file --batch-check="%(objecttype) %(objectname)" >actual &&
206 test_cmp expect actual
209 test_expect_success
"custom --batch-command format" '
210 echo "$type $sha1" >expect &&
211 echo "info $sha1" | git cat-file --batch-command="%(objecttype) %(objectname)" >actual &&
212 test_cmp expect actual
215 test_expect_success
'--batch-check with %(rest)' '
216 echo "$type this is some extra content" >expect &&
217 echo "$sha1 this is some extra content" |
218 git cat-file --batch-check="%(objecttype) %(rest)" >actual &&
219 test_cmp expect actual
222 test -z "$content" ||
223 test_expect_success
"--batch without type ($type)" '
226 maybe_remove_timestamp "$content" $no_ts
228 echo $sha1 | git cat-file --batch="%(objectsize)" >actual.full &&
229 maybe_remove_timestamp "$(cat actual.full)" $no_ts >actual &&
230 test_cmp expect actual
233 test -z "$content" ||
234 test_expect_success
"--batch without size ($type)" '
237 maybe_remove_timestamp "$content" $no_ts
239 echo $sha1 | git cat-file --batch="%(objecttype)" >actual.full &&
240 maybe_remove_timestamp "$(cat actual.full)" $no_ts >actual &&
241 test_cmp expect actual
245 hello_content
="Hello World"
246 hello_size
=$
(strlen
"$hello_content")
247 hello_sha1
=$
(echo_without_newline
"$hello_content" | git hash-object
--stdin)
249 test_expect_success
"setup" '
250 echo_without_newline "$hello_content" > hello &&
251 git update-index --add hello
254 run_tests
'blob' $hello_sha1 $hello_size "$hello_content" "$hello_content"
256 test_expect_success
'--batch-command --buffer with flush for blob info' '
257 echo "$hello_sha1 blob $hello_size" >expect &&
258 test_write_lines "info $hello_sha1" "flush" |
259 GIT_TEST_CAT_FILE_NO_FLUSH_ON_EXIT=1 \
260 git cat-file --batch-command --buffer >actual &&
261 test_cmp expect actual
264 test_expect_success
'--batch-command --buffer without flush for blob info' '
266 test_write_lines "info $hello_sha1" |
267 GIT_TEST_CAT_FILE_NO_FLUSH_ON_EXIT=1 \
268 git cat-file --batch-command --buffer >>output &&
269 test_must_be_empty output
272 test_expect_success
'--batch-check without %(rest) considers whole line' '
273 echo "$hello_sha1 blob $hello_size" >expect &&
274 git update-index --add --cacheinfo 100644 $hello_sha1 "white space" &&
275 test_when_finished "git update-index --remove \"white space\"" &&
276 echo ":white space" | git cat-file --batch-check >actual &&
277 test_cmp expect actual
280 tree_sha1
=$
(git write-tree
)
281 tree_size
=$
(($
(test_oid rawsz
) + 13))
282 tree_pretty_content
="100644 blob $hello_sha1 hello"
284 run_tests
'tree' $tree_sha1 $tree_size "" "$tree_pretty_content"
286 commit_message
="Initial commit"
287 commit_sha1
=$
(echo_without_newline
"$commit_message" | git commit-tree
$tree_sha1)
288 commit_size
=$
(($
(test_oid hexsz
) + 137))
289 commit_content
="tree $tree_sha1
290 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 0000000000 +0000
291 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 0000000000 +0000
295 run_tests
'commit' $commit_sha1 $commit_size "$commit_content" "$commit_content" 1
297 tag_header_without_timestamp
="object $hello_sha1
300 tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
301 tag_description
="This is a tag"
302 tag_content
="$tag_header_without_timestamp 0000000000 +0000
306 tag_sha1
=$
(echo_without_newline
"$tag_content" | git hash-object
-t tag
--stdin -w)
307 tag_size
=$
(strlen
"$tag_content")
309 run_tests
'tag' $tag_sha1 $tag_size "$tag_content" "$tag_content" 1
311 test_expect_success \
312 "Reach a blob from a tag pointing to it" \
313 "test '$hello_content' = \"\$(git cat-file blob $tag_sha1)\""
315 for batch in batch batch-check batch-command
319 test_expect_success
"Passing -$opt with --$batch fails" '
320 test_must_fail git cat-file --$batch -$opt $hello_sha1
323 test_expect_success
"Passing --$batch with -$opt fails" '
324 test_must_fail git cat-file -$opt --$batch $hello_sha1
328 test_expect_success
"Passing <type> with --$batch fails" '
329 test_must_fail git cat-file --$batch blob $hello_sha1
332 test_expect_success
"Passing --$batch with <type> fails" '
333 test_must_fail git cat-file blob --$batch $hello_sha1
336 test_expect_success
"Passing sha1 with --$batch fails" '
337 test_must_fail git cat-file --$batch $hello_sha1
343 test_expect_success
"Passing -$opt with --follow-symlinks fails" '
344 test_must_fail git cat-file --follow-symlinks -$opt $hello_sha1
348 test_expect_success
"--batch-check for a non-existent named object" '
349 test "foobar42 missing
350 foobar84 missing" = \
351 "$( ( echo foobar42 && echo_without_newline foobar84 ) | git cat-file --batch-check)"
354 test_expect_success
"--batch-check for a non-existent hash" '
355 test "0000000000000000000000000000000000000042 missing
356 0000000000000000000000000000000000000084 missing" = \
357 "$( ( echo 0000000000000000000000000000000000000042 &&
358 echo_without_newline 0000000000000000000000000000000000000084 ) |
359 git cat-file --batch-check)"
362 test_expect_success
"--batch for an existent and a non-existent hash" '
363 test "$tag_sha1 tag $tag_size
365 0000000000000000000000000000000000000000 missing" = \
366 "$( ( echo $tag_sha1 &&
367 echo_without_newline 0000000000000000000000000000000000000000 ) |
368 git cat-file --batch)"
371 test_expect_success
"--batch-check for an empty line" '
372 test " missing" = "$(echo | git cat-file --batch-check)"
375 test_expect_success
'empty --batch-check notices missing object' '
376 echo "$ZERO_OID missing" >expect &&
377 echo "$ZERO_OID" | git cat-file --batch-check="" >actual &&
378 test_cmp expect actual
381 batch_input
="$hello_sha1
388 batch_output
="$hello_sha1 blob $hello_size
390 $commit_sha1 commit $commit_size
392 $tag_sha1 tag $tag_size
397 test_expect_success
'--batch with multiple sha1s gives correct format' '
398 test "$(maybe_remove_timestamp "$batch_output" 1)" = "$(maybe_remove_timestamp "$(echo_without_newline "$batch_input" | git cat-file --batch)" 1)"
401 batch_check_input
="$hello_sha1
409 batch_check_output
="$hello_sha1 blob $hello_size
410 $tree_sha1 tree $tree_size
411 $commit_sha1 commit $commit_size
412 $tag_sha1 tag $tag_size
416 test_expect_success
"--batch-check with multiple sha1s gives correct format" '
417 test "$batch_check_output" = \
418 "$(echo_without_newline "$batch_check_input" | git cat-file --batch-check)"
421 test_expect_success
'--batch-command with multiple info calls gives correct format' '
422 cat >expect <<-EOF &&
423 $hello_sha1 blob $hello_size
424 $tree_sha1 tree $tree_size
425 $commit_sha1 commit $commit_size
426 $tag_sha1 tag $tag_size
430 git cat-file --batch-command --buffer >actual <<-EOF &&
438 test_cmp expect actual
441 test_expect_success
'--batch-command with multiple command calls gives correct format' '
442 remove_timestamp >expect <<-EOF &&
443 $hello_sha1 blob $hello_size
445 $commit_sha1 commit $commit_size
447 $tag_sha1 tag $tag_size
452 git cat-file --batch-command --buffer >actual_raw <<-EOF &&
454 contents $commit_sha1
460 remove_timestamp <actual_raw >actual &&
461 test_cmp expect actual
464 test_expect_success
'setup blobs which are likely to delta' '
465 test-tool genrandom foo 10240 >foo &&
466 { cat foo && echo plus; } >foo-plus &&
467 git add foo foo-plus &&
475 test_expect_success
'confirm that neither loose blob is a delta' '
476 cat >expect <<-EOF &&
480 git cat-file --batch-check="%(deltabase)" <blobs >actual &&
481 test_cmp expect actual
484 # To avoid relying too much on the current delta heuristics,
485 # we will check only that one of the two objects is a delta
486 # against the other, but not the order. We can do so by just
487 # asking for the base of both, and checking whether either
488 # sha1 appears in the output.
489 test_expect_success
'%(deltabase) reports packed delta bases' '
491 git cat-file --batch-check="%(deltabase)" <blobs >actual &&
493 grep "$(git rev-parse HEAD:foo)" actual ||
494 grep "$(git rev-parse HEAD:foo-plus)" actual
498 test_expect_success
'setup bogus data' '
499 bogus_short_type="bogus" &&
500 bogus_short_content="bogus" &&
501 bogus_short_size=$(strlen "$bogus_short_content") &&
502 bogus_short_sha1=$(echo_without_newline "$bogus_short_content" | git hash-object -t $bogus_short_type --literally -w --stdin) &&
504 bogus_long_type="abcdefghijklmnopqrstuvwxyz1234679" &&
505 bogus_long_content="bogus" &&
506 bogus_long_size=$(strlen "$bogus_long_content") &&
507 bogus_long_sha1=$(echo_without_newline "$bogus_long_content" | git hash-object -t $bogus_long_type --literally -w --stdin)
510 for arg1
in '' --allow-unknown-type
514 if test "$arg1" = "--allow-unknown-type" && test "$arg2" = "-p"
520 test_expect_success
"cat-file $arg1 $arg2 error on bogus short OID" '
521 cat >expect <<-\EOF &&
522 fatal: invalid object type
525 if test "$arg1" = "--allow-unknown-type"
527 git cat-file $arg1 $arg2 $bogus_short_sha1
529 test_must_fail git cat-file $arg1 $arg2 $bogus_short_sha1 >out 2>actual &&
530 test_must_be_empty out &&
531 test_cmp expect actual
535 test_expect_success
"cat-file $arg1 $arg2 error on bogus full OID" '
536 if test "$arg2" = "-p"
539 error: header for $bogus_long_sha1 too long, exceeds 32 bytes
540 fatal: Not a valid object name $bogus_long_sha1
544 error: header for $bogus_long_sha1 too long, exceeds 32 bytes
545 fatal: git cat-file: could not get object info
549 if test "$arg1" = "--allow-unknown-type"
551 git cat-file $arg1 $arg2 $bogus_short_sha1
553 test_must_fail git cat-file $arg1 $arg2 $bogus_long_sha1 >out 2>actual &&
554 test_must_be_empty out &&
555 test_cmp expect actual
559 test_expect_success
"cat-file $arg1 $arg2 error on missing short OID" '
560 cat >expect.err <<-EOF &&
561 fatal: Not a valid object name $(test_oid deadbeef_short)
563 test_must_fail git cat-file $arg1 $arg2 $(test_oid deadbeef_short) >out 2>err.actual &&
564 test_must_be_empty out
567 test_expect_success
"cat-file $arg1 $arg2 error on missing full OID" '
568 if test "$arg2" = "-p"
570 cat >expect.err <<-EOF
571 fatal: Not a valid object name $(test_oid deadbeef)
574 cat >expect.err <<-\EOF
575 fatal: git cat-file: could not get object info
578 test_must_fail git cat-file $arg1 $arg2 $(test_oid deadbeef) >out 2>err.actual &&
579 test_must_be_empty out &&
580 test_cmp expect.err err.actual
585 test_expect_success
'-e is OK with a broken object without --allow-unknown-type' '
586 git cat-file -e $bogus_short_sha1
589 test_expect_success
'-e can not be combined with --allow-unknown-type' '
590 test_expect_code 128 git cat-file -e --allow-unknown-type $bogus_short_sha1
593 test_expect_success
'-p cannot print a broken object even with --allow-unknown-type' '
594 test_must_fail git cat-file -p $bogus_short_sha1 &&
595 test_expect_code 128 git cat-file -p --allow-unknown-type $bogus_short_sha1
598 test_expect_success
'<type> <hash> does not work with objects of broken types' '
599 cat >err.expect <<-\EOF &&
600 fatal: invalid object type "bogus"
602 test_must_fail git cat-file $bogus_short_type $bogus_short_sha1 2>err.actual &&
603 test_cmp err.expect err.actual
606 test_expect_success
'broken types combined with --batch and --batch-check' '
607 echo $bogus_short_sha1 >bogus-oid &&
609 cat >err.expect <<-\EOF &&
610 fatal: invalid object type
613 test_must_fail git cat-file --batch <bogus-oid 2>err.actual &&
614 test_cmp err.expect err.actual &&
616 test_must_fail git cat-file --batch-check <bogus-oid 2>err.actual &&
617 test_cmp err.expect err.actual
620 test_expect_success
'the --batch and --batch-check options do not combine with --allow-unknown-type' '
621 test_expect_code 128 git cat-file --batch --allow-unknown-type <bogus-oid &&
622 test_expect_code 128 git cat-file --batch-check --allow-unknown-type <bogus-oid
625 test_expect_success
'the --allow-unknown-type option does not consider replacement refs' '
626 cat >expect <<-EOF &&
629 git cat-file -t --allow-unknown-type $bogus_short_sha1 >actual &&
630 test_cmp expect actual &&
632 # Create it manually, as "git replace" will die on bogus
634 head=$(git rev-parse --verify HEAD) &&
635 test_when_finished "test-tool ref-store main delete-refs 0 msg refs/replace/$bogus_short_sha1" &&
636 test-tool ref-store main update-ref msg "refs/replace/$bogus_short_sha1" $head $ZERO_OID REF_SKIP_OID_VERIFICATION &&
638 cat >expect <<-EOF &&
641 git cat-file -t --allow-unknown-type $bogus_short_sha1 >actual &&
642 test_cmp expect actual
645 test_expect_success
"Type of broken object is correct" '
646 echo $bogus_short_type >expect &&
647 git cat-file -t --allow-unknown-type $bogus_short_sha1 >actual &&
648 test_cmp expect actual
651 test_expect_success
"Size of broken object is correct" '
652 echo $bogus_short_size >expect &&
653 git cat-file -s --allow-unknown-type $bogus_short_sha1 >actual &&
654 test_cmp expect actual
657 test_expect_success
'clean up broken object' '
658 rm .git/objects/$(test_oid_to_path $bogus_short_sha1)
661 test_expect_success
"Type of broken object is correct when type is large" '
662 echo $bogus_long_type >expect &&
663 git cat-file -t --allow-unknown-type $bogus_long_sha1 >actual &&
664 test_cmp expect actual
667 test_expect_success
"Size of large broken object is correct when type is large" '
668 echo $bogus_long_size >expect &&
669 git cat-file -s --allow-unknown-type $bogus_long_sha1 >actual &&
670 test_cmp expect actual
673 test_expect_success
'clean up broken object' '
674 rm .git/objects/$(test_oid_to_path $bogus_long_sha1)
677 test_expect_success
'cat-file -t and -s on corrupt loose object' '
678 git init --bare corrupt-loose.git &&
680 cd corrupt-loose.git &&
682 # Setup and create the empty blob and its path
683 empty_path=$(git rev-parse --git-path objects/$(test_oid_to_path "$EMPTY_BLOB")) &&
684 empty_blob=$(git hash-object -w --stdin </dev/null) &&
686 # Create another blob and its path
687 echo other >other.blob &&
688 other_blob=$(git hash-object -w --stdin <other.blob) &&
689 other_path=$(git rev-parse --git-path objects/$(test_oid_to_path "$other_blob")) &&
691 # Before the swap the size is 0
692 cat >out.expect <<-EOF &&
695 git cat-file -s "$EMPTY_BLOB" >out.actual 2>err.actual &&
696 test_must_be_empty err.actual &&
697 test_cmp out.expect out.actual &&
699 # Swap the two to corrupt the repository
700 mv -f "$other_path" "$empty_path" &&
701 test_must_fail git fsck 2>err.fsck &&
702 grep "hash-path mismatch" err.fsck &&
704 # confirm that cat-file is reading the new swapped-in
706 cat >out.expect <<-EOF &&
709 git cat-file -t "$EMPTY_BLOB" >out.actual 2>err.actual &&
710 test_must_be_empty err.actual &&
711 test_cmp out.expect out.actual &&
713 # ... since it has a different size now.
714 cat >out.expect <<-EOF &&
717 git cat-file -s "$EMPTY_BLOB" >out.actual 2>err.actual &&
718 test_must_be_empty err.actual &&
719 test_cmp out.expect out.actual &&
721 # So far "cat-file" has been happy to spew the found
722 # content out as-is. Try to make it zlib-invalid.
723 mv -f other.blob "$empty_path" &&
724 test_must_fail git fsck 2>err.fsck &&
725 cat >expect <<-EOF &&
726 error: inflate: data stream error (incorrect header check)
727 error: unable to unpack header of ./$empty_path
728 error: $empty_blob: object corrupt or missing: ./$empty_path
730 grep "^error: " err.fsck >actual &&
731 test_cmp expect actual
735 # Tests for git cat-file --follow-symlinks
736 test_expect_success
'prep for symlink tests' '
737 echo_without_newline "$hello_content" >morx &&
738 test_ln_s_add morx same-dir-link &&
739 test_ln_s_add dir link-to-dir &&
740 test_ln_s_add ../fleem out-of-repo-link &&
741 test_ln_s_add .. out-of-repo-link-dir &&
742 test_ln_s_add same-dir-link link-to-link &&
743 test_ln_s_add nope broken-same-dir-link &&
745 test_ln_s_add ../morx dir/parent-dir-link &&
746 test_ln_s_add .. dir/link-dir &&
747 test_ln_s_add ../../escape dir/out-of-repo-link &&
748 test_ln_s_add ../.. dir/out-of-repo-link-dir &&
749 test_ln_s_add nope dir/broken-link-in-dir &&
751 test_ln_s_add ../../morx dir/subdir/grandparent-dir-link &&
752 test_ln_s_add ../../../great-escape dir/subdir/out-of-repo-link &&
753 test_ln_s_add ../../.. dir/subdir/out-of-repo-link-dir &&
754 test_ln_s_add ../../../ dir/subdir/out-of-repo-link-dir-trailing &&
755 test_ln_s_add ../parent-dir-link dir/subdir/parent-dir-link-to-link &&
756 echo_without_newline "$hello_content" >dir/subdir/ind2 &&
757 echo_without_newline "$hello_content" >dir/ind1 &&
758 test_ln_s_add dir dirlink &&
759 test_ln_s_add dir/subdir subdirlink &&
760 test_ln_s_add subdir/ind2 dir/link-to-child &&
761 test_ln_s_add dir/link-to-child link-to-down-link &&
762 test_ln_s_add dir/.. up-down &&
763 test_ln_s_add dir/../ up-down-trailing &&
764 test_ln_s_add dir/../morx up-down-file &&
765 test_ln_s_add dir/../../morx up-up-down-file &&
766 test_ln_s_add subdirlink/../../morx up-two-down-file &&
767 test_ln_s_add loop1 loop2 &&
768 test_ln_s_add loop2 loop1 &&
769 git add morx dir/subdir/ind2 dir/ind1 &&
770 git commit -am "test" &&
771 echo $hello_sha1 blob $hello_size >found
774 test_expect_success
'git cat-file --batch-check --follow-symlinks works for non-links' '
775 echo HEAD:morx | git cat-file --batch-check --follow-symlinks >actual &&
776 test_cmp found actual &&
777 echo HEAD:nope missing >expect &&
778 echo HEAD:nope | git cat-file --batch-check --follow-symlinks >actual &&
779 test_cmp expect actual
782 test_expect_success
'git cat-file --batch-check --follow-symlinks works for in-repo, same-dir links' '
783 echo HEAD:same-dir-link | git cat-file --batch-check --follow-symlinks >actual &&
784 test_cmp found actual
787 test_expect_success
'git cat-file --batch-check --follow-symlinks works for in-repo, links to dirs' '
788 echo HEAD:link-to-dir/ind1 | git cat-file --batch-check --follow-symlinks >actual &&
789 test_cmp found actual
793 test_expect_success
'git cat-file --batch-check --follow-symlinks works for broken in-repo, same-dir links' '
794 echo dangling 25 >expect &&
795 echo HEAD:broken-same-dir-link >>expect &&
796 echo HEAD:broken-same-dir-link | git cat-file --batch-check --follow-symlinks >actual &&
797 test_cmp expect actual
800 test_expect_success
'git cat-file --batch-check --follow-symlinks works for same-dir links-to-links' '
801 echo HEAD:link-to-link | git cat-file --batch-check --follow-symlinks >actual &&
802 test_cmp found actual
805 test_expect_success
'git cat-file --batch-check --follow-symlinks works for parent-dir links' '
806 echo HEAD:dir/parent-dir-link | git cat-file --batch-check --follow-symlinks >actual &&
807 test_cmp found actual &&
808 echo notdir 29 >expect &&
809 echo HEAD:dir/parent-dir-link/nope >>expect &&
810 echo HEAD:dir/parent-dir-link/nope | git cat-file --batch-check --follow-symlinks >actual &&
811 test_cmp expect actual
814 test_expect_success
'git cat-file --batch-check --follow-symlinks works for .. links' '
815 echo dangling 22 >expect &&
816 echo HEAD:dir/link-dir/nope >>expect &&
817 echo HEAD:dir/link-dir/nope | git cat-file --batch-check --follow-symlinks >actual &&
818 test_cmp expect actual &&
819 echo HEAD:dir/link-dir/morx | git cat-file --batch-check --follow-symlinks >actual &&
820 test_cmp found actual &&
821 echo dangling 27 >expect &&
822 echo HEAD:dir/broken-link-in-dir >>expect &&
823 echo HEAD:dir/broken-link-in-dir | git cat-file --batch-check --follow-symlinks >actual &&
824 test_cmp expect actual
827 test_expect_success
'git cat-file --batch-check --follow-symlinks works for ../.. links' '
828 echo notdir 41 >expect &&
829 echo HEAD:dir/subdir/grandparent-dir-link/nope >>expect &&
830 echo HEAD:dir/subdir/grandparent-dir-link/nope | git cat-file --batch-check --follow-symlinks >actual &&
831 test_cmp expect actual &&
832 echo HEAD:dir/subdir/grandparent-dir-link | git cat-file --batch-check --follow-symlinks >actual &&
833 test_cmp found actual &&
834 echo HEAD:dir/subdir/parent-dir-link-to-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 dir/ links' '
839 echo dangling 17 >expect &&
840 echo HEAD:dirlink/morx >>expect &&
841 echo HEAD:dirlink/morx | git cat-file --batch-check --follow-symlinks >actual &&
842 test_cmp expect actual &&
843 echo $hello_sha1 blob $hello_size >expect &&
844 echo HEAD:dirlink/ind1 | git cat-file --batch-check --follow-symlinks >actual &&
845 test_cmp expect actual
848 test_expect_success
'git cat-file --batch-check --follow-symlinks works for dir/subdir links' '
849 echo dangling 20 >expect &&
850 echo HEAD:subdirlink/morx >>expect &&
851 echo HEAD:subdirlink/morx | git cat-file --batch-check --follow-symlinks >actual &&
852 test_cmp expect actual &&
853 echo HEAD:subdirlink/ind2 | git cat-file --batch-check --follow-symlinks >actual &&
854 test_cmp found actual
857 test_expect_success
'git cat-file --batch-check --follow-symlinks works for dir ->subdir links' '
858 echo notdir 27 >expect &&
859 echo HEAD:dir/link-to-child/morx >>expect &&
860 echo HEAD:dir/link-to-child/morx | git cat-file --batch-check --follow-symlinks >actual &&
861 test_cmp expect actual &&
862 echo HEAD:dir/link-to-child | git cat-file --batch-check --follow-symlinks >actual &&
863 test_cmp found actual &&
864 echo HEAD:link-to-down-link | git cat-file --batch-check --follow-symlinks >actual &&
865 test_cmp found actual
868 test_expect_success
'git cat-file --batch-check --follow-symlinks works for out-of-repo symlinks' '
869 echo symlink 8 >expect &&
870 echo ../fleem >>expect &&
871 echo HEAD:out-of-repo-link | git cat-file --batch-check --follow-symlinks >actual &&
872 test_cmp expect actual &&
873 echo symlink 2 >expect &&
875 echo HEAD:out-of-repo-link-dir | git cat-file --batch-check --follow-symlinks >actual &&
876 test_cmp expect actual
879 test_expect_success
'git cat-file --batch-check --follow-symlinks works for out-of-repo symlinks in dirs' '
880 echo symlink 9 >expect &&
881 echo ../escape >>expect &&
882 echo HEAD:dir/out-of-repo-link | git cat-file --batch-check --follow-symlinks >actual &&
883 test_cmp expect actual &&
884 echo symlink 2 >expect &&
886 echo HEAD:dir/out-of-repo-link-dir | git cat-file --batch-check --follow-symlinks >actual &&
887 test_cmp expect actual
890 test_expect_success
'git cat-file --batch-check --follow-symlinks works for out-of-repo symlinks in subdirs' '
891 echo symlink 15 >expect &&
892 echo ../great-escape >>expect &&
893 echo HEAD:dir/subdir/out-of-repo-link | git cat-file --batch-check --follow-symlinks >actual &&
894 test_cmp expect actual &&
895 echo symlink 2 >expect &&
897 echo HEAD:dir/subdir/out-of-repo-link-dir | git cat-file --batch-check --follow-symlinks >actual &&
898 test_cmp expect actual &&
899 echo symlink 3 >expect &&
901 echo HEAD:dir/subdir/out-of-repo-link-dir-trailing | git cat-file --batch-check --follow-symlinks >actual &&
902 test_cmp expect actual
905 test_expect_success
'git cat-file --batch-check --follow-symlinks works for symlinks with internal ..' '
906 echo HEAD: | git cat-file --batch-check >expect &&
907 echo HEAD:up-down | git cat-file --batch-check --follow-symlinks >actual &&
908 test_cmp expect actual &&
909 echo HEAD:up-down-trailing | git cat-file --batch-check --follow-symlinks >actual &&
910 test_cmp expect actual &&
911 echo HEAD:up-down-file | git cat-file --batch-check --follow-symlinks >actual &&
912 test_cmp found actual &&
913 echo symlink 7 >expect &&
914 echo ../morx >>expect &&
915 echo HEAD:up-up-down-file | git cat-file --batch-check --follow-symlinks >actual &&
916 test_cmp expect actual &&
917 echo HEAD:up-two-down-file | git cat-file --batch-check --follow-symlinks >actual &&
918 test_cmp found actual
921 test_expect_success
'git cat-file --batch-check --follow-symlink breaks loops' '
922 echo loop 10 >expect &&
923 echo HEAD:loop1 >>expect &&
924 echo HEAD:loop1 | git cat-file --batch-check --follow-symlinks >actual &&
925 test_cmp expect actual
928 test_expect_success
'git cat-file --batch --follow-symlink returns correct sha and mode' '
929 echo HEAD:morx | git cat-file --batch >expect &&
930 echo HEAD:morx | git cat-file --batch --follow-symlinks >actual &&
931 test_cmp expect actual
934 test_expect_success
'cat-file --batch-all-objects shows all objects' '
935 # make new repos so we know the full set of objects; we will
936 # also make sure that there are some packed and some loose
937 # objects, some referenced and some not, some duplicates, and that
938 # there are some available only via alternates.
942 echo content >file &&
944 git commit -qm base &&
945 git rev-parse HEAD HEAD^{tree} HEAD:file &&
947 echo not-cloned | git hash-object -w --stdin
948 ) >expect.unsorted &&
949 git clone -s all-one all-two &&
952 echo local-unref | git hash-object -w --stdin
953 ) >>expect.unsorted &&
954 git -C all-two rev-parse HEAD:file |
955 git -C all-two pack-objects .git/objects/pack/pack &&
956 sort <expect.unsorted >expect &&
957 git -C all-two cat-file --batch-all-objects \
958 --batch-check="%(objectname)" >actual &&
959 test_cmp expect actual
962 # The only user-visible difference is that the objects are no longer sorted,
963 # and the resulting sort order is undefined. So we can only check that it
964 # produces the same objects as the ordered case, but that at least exercises
966 test_expect_success
'cat-file --unordered works' '
967 git -C all-two cat-file --batch-all-objects --unordered \
968 --batch-check="%(objectname)" >actual.unsorted &&
969 sort <actual.unsorted >actual &&
970 test_cmp expect actual
973 test_expect_success
'set up object list for --batch-all-objects tests' '
974 git -C all-two cat-file --batch-all-objects --batch-check="%(objectname)" >objects
977 test_expect_success
'cat-file --batch="%(objectname)" with --batch-all-objects will work' '
978 git -C all-two cat-file --batch="%(objectname)" <objects >expect &&
979 git -C all-two cat-file --batch-all-objects --batch="%(objectname)" >actual &&
983 test_expect_success
'cat-file --batch="%(rest)" with --batch-all-objects will work' '
984 git -C all-two cat-file --batch="%(rest)" <objects >expect &&
985 git -C all-two cat-file --batch-all-objects --batch="%(rest)" >actual &&
989 test_expect_success
'cat-file --batch="batman" with --batch-all-objects will work' '
990 git -C all-two cat-file --batch="batman" <objects >expect &&
991 git -C all-two cat-file --batch-all-objects --batch="batman" >actual &&
995 test_expect_success
'set up replacement object' '
996 orig=$(git rev-parse HEAD) &&
997 git cat-file commit $orig >orig &&
1002 fake=$(git hash-object -t commit -w fake) &&
1003 orig_size=$(git cat-file -s $orig) &&
1004 fake_size=$(git cat-file -s $fake) &&
1005 git replace $orig $fake
1008 test_expect_success
'cat-file --batch respects replace objects' '
1009 git cat-file --batch >actual <<-EOF &&
1013 echo "$orig commit $fake_size" &&
1017 test_cmp expect actual
1020 test_expect_success
'cat-file --batch-check respects replace objects' '
1021 git cat-file --batch-check >actual <<-EOF &&
1024 echo "$orig commit $fake_size" >expect &&
1025 test_cmp expect actual
1028 # Pull the entry for object with oid "$1" out of the output of
1029 # "cat-file --batch", including its object content (which requires
1030 # parsing and reading a set amount of bytes, hence perl).
1031 extract_batch_output
() {
1033 BEGIN { $oid = shift }
1034 if (/^$oid \S+ (\d+)$/) {
1036 read STDIN, my $buf, $1;
1043 test_expect_success
'cat-file --batch-all-objects --batch ignores replace' '
1044 git cat-file --batch-all-objects --batch >actual.raw &&
1045 extract_batch_output $orig <actual.raw >actual &&
1047 echo "$orig commit $orig_size" &&
1051 test_cmp expect actual
1054 test_expect_success
'cat-file --batch-all-objects --batch-check ignores replace' '
1055 git cat-file --batch-all-objects --batch-check >actual.raw &&
1056 grep ^$orig actual.raw >actual &&
1057 echo "$orig commit $orig_size" >expect &&
1058 test_cmp expect actual
1060 test_expect_success
'batch-command empty command' '
1062 test_expect_code 128 git cat-file --batch-command <cmd 2>err &&
1063 grep "^fatal:.*empty command in input.*" err
1066 test_expect_success
'batch-command whitespace before command' '
1067 echo " info deadbeef" >cmd &&
1068 test_expect_code 128 git cat-file --batch-command <cmd 2>err &&
1069 grep "^fatal:.*whitespace before command.*" err
1072 test_expect_success
'batch-command unknown command' '
1073 echo unknown_command >cmd &&
1074 test_expect_code 128 git cat-file --batch-command <cmd 2>err &&
1075 grep "^fatal:.*unknown command.*" err
1078 test_expect_success
'batch-command missing arguments' '
1080 test_expect_code 128 git cat-file --batch-command <cmd 2>err &&
1081 grep "^fatal:.*info requires arguments.*" err
1084 test_expect_success
'batch-command flush with arguments' '
1085 echo "flush arg" >cmd &&
1086 test_expect_code 128 git cat-file --batch-command --buffer <cmd 2>err &&
1087 grep "^fatal:.*flush takes no arguments.*" err
1090 test_expect_success
'batch-command flush without --buffer' '
1091 echo "flush" >cmd &&
1092 test_expect_code 128 git cat-file --batch-command <cmd 2>err &&
1093 grep "^fatal:.*flush is only for --buffer mode.*" err