read-tree: narrow scope of index expansion for '--prefix'
[alt-git.git] / t / t1006-cat-file.sh
blob145eee11df97c9cf63542e49e42f80ecabab1b73
1 #!/bin/sh
3 test_description='git cat-file'
5 . ./test-lib.sh
7 test_cmdmode_usage () {
8 test_expect_code 129 "$@" 2>err &&
9 grep "^error:.*is incompatible with" err
12 for switches in \
13 '-e -p' \
14 '-p -t' \
15 '-t -s' \
16 '-s --textconv' \
17 '--textconv --filters' \
18 '--batch-all-objects -e'
20 test_expect_success "usage: cmdmode $switches" '
21 test_cmdmode_usage git cat-file $switches
23 done
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
35 done
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"
45 for opt in $cw_modes
47 test_expect_success "usage: $opt requires another option" '
48 test_missing_usage git cat-file $opt
50 done
52 for opt in $short_modes
54 test_expect_success "usage: $opt requires another option" '
55 test_missing_usage git cat-file $opt
58 for opt2 in --batch \
59 --batch-check \
60 --follow-symlinks \
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
66 done
67 done
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
76 args="one two three"
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
86 done
87 done
89 for opt in --buffer \
90 --follow-symlinks \
91 --batch-all-objects
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
97 done
99 echo_without_newline () {
100 printf '%s' "$*"
103 strlen () {
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"
110 else
111 echo_without_newline "$(printf '%s\n' "$1" | sed -e 's/ [0-9][0-9]* [-+][0-9][0-9][0-9][0-9]$//')"
115 run_tests () {
116 type=$1
117 sha1=$2
118 size=$3
119 content=$4
120 pretty_content=$5
121 no_ts=$6
123 batch_output="$sha1 $type $size
124 $content"
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)" '
196 echo "$size" &&
197 maybe_remove_timestamp "$content" $no_ts
198 } >expect &&
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)" '
207 echo "$type" &&
208 maybe_remove_timestamp "$content" $no_ts
209 } >expect &&
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
248 $commit_message"
250 run_tests 'commit' $commit_sha1 $commit_size "$commit_content" "$commit_content" 1
252 tag_header_without_timestamp="object $hello_sha1
253 type blob
254 tag hellotag
255 tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
256 tag_description="This is a tag"
257 tag_content="$tag_header_without_timestamp 0000000000 +0000
259 $tag_description"
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
272 for opt in t s e p
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
281 done
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
294 done
296 for opt in t s e p
298 test_expect_success "Passing -$opt with --follow-symlinks fails" '
299 test_must_fail git cat-file --follow-symlinks -$opt $hello_sha1
301 done
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
319 $tag_content
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
337 $commit_sha1
338 $tag_sha1
339 deadbeef
343 batch_output="$hello_sha1 blob $hello_size
344 $hello_content
345 $commit_sha1 commit $commit_size
346 $commit_content
347 $tag_sha1 tag $tag_size
348 $tag_content
349 deadbeef missing
350 missing"
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
357 $tree_sha1
358 $commit_sha1
359 $tag_sha1
360 deadbeef
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
368 deadbeef missing
369 missing"
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 &&
380 git commit -m foo &&
381 cat >blobs <<-\EOF
382 HEAD:foo
383 HEAD:foo-plus
387 test_expect_success 'confirm that neither loose blob is a delta' '
388 cat >expect <<-EOF &&
389 $ZERO_OID
390 $ZERO_OID
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' '
402 git repack -ad &&
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
424 for arg2 in -s -t -p
426 if test "$arg1" = "--allow-unknown-type" && test "$arg2" = "-p"
427 then
428 continue
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"
438 then
439 git cat-file $arg1 $arg2 $bogus_short_sha1
440 else
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"
449 then
450 cat >expect <<-EOF
451 error: header for $bogus_long_sha1 too long, exceeds 32 bytes
452 fatal: Not a valid object name $bogus_long_sha1
454 else
455 cat >expect <<-EOF
456 error: header for $bogus_long_sha1 too long, exceeds 32 bytes
457 fatal: git cat-file: could not get object info
459 fi &&
461 if test "$arg1" = "--allow-unknown-type"
462 then
463 git cat-file $arg1 $arg2 $bogus_short_sha1
464 else
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"
481 then
482 cat >expect.err <<-EOF
483 fatal: Not a valid object name $(test_oid deadbeef)
485 else
486 cat >expect.err <<-\EOF
487 fatal: git cat-file: could not get object info
489 fi &&
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
494 done
495 done
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 &&
539 $bogus_short_type
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
545 # types.
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 &&
551 commit
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
617 # blob...
618 cat >out.expect <<-EOF &&
619 blob
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 &&
650 mkdir dir &&
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 &&
656 mkdir dir/subdir &&
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 &&
780 echo .. >>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 &&
791 echo .. >>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 &&
802 echo .. >>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 &&
806 echo ../ >>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.
845 git init all-one &&
847 cd all-one &&
848 echo content >file &&
849 git add file &&
850 git commit -qm base &&
851 git rev-parse HEAD HEAD^{tree} HEAD:file &&
852 git repack -ad &&
853 echo not-cloned | git hash-object -w --stdin
854 ) >expect.unsorted &&
855 git clone -s all-one all-two &&
857 cd 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
871 # the code.
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 &&
886 cmp expect 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 &&
892 cmp expect 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 &&
898 cmp expect actual
901 test_expect_success 'set up replacement object' '
902 orig=$(git rev-parse HEAD) &&
903 git cat-file commit $orig >orig &&
905 cat orig &&
906 echo extra
907 } >fake &&
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 &&
916 $orig
919 echo "$orig commit $fake_size" &&
920 cat fake &&
921 echo
922 } >expect &&
923 test_cmp expect actual
926 test_expect_success 'cat-file --batch-check respects replace objects' '
927 git cat-file --batch-check >actual <<-EOF &&
928 $orig
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 () {
938 perl -ne '
939 BEGIN { $oid = shift }
940 if (/^$oid \S+ (\d+)$/) {
941 print;
942 read STDIN, my $buf, $1;
943 print $buf;
944 print "\n";
946 ' "$@"
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" &&
954 cat orig &&
955 echo
956 } >expect &&
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
967 test_done