]> git.ipfire.org Git - thirdparty/git.git/blame - t/t1006-cat-file.sh
cat-file: mention --unordered along with --batch-all-objects
[thirdparty/git.git] / t / t1006-cat-file.sh
CommitLineData
b335d3f1
AR
1#!/bin/sh
2
3test_description='git cat-file'
4
5. ./test-lib.sh
6
7echo_without_newline () {
8 printf '%s' "$*"
9}
10
11strlen () {
12 echo_without_newline "$1" | wc -c | sed -e 's/^ *//'
13}
14
15maybe_remove_timestamp () {
16 if test -z "$2"; then
17 echo_without_newline "$1"
18 else
19 echo_without_newline "$(printf '%s\n' "$1" | sed -e 's/ [0-9][0-9]* [-+][0-9][0-9][0-9][0-9]$//')"
20 fi
21}
22
23run_tests () {
24 type=$1
25 sha1=$2
26 size=$3
27 content=$4
28 pretty_content=$5
29 no_ts=$6
30
a8128ed6
AR
31 batch_output="$sha1 $type $size
32$content"
33
b335d3f1
AR
34 test_expect_success "$type exists" '
35 git cat-file -e $sha1
36 '
37
38 test_expect_success "Type of $type is correct" '
03c893cb
JK
39 echo $type >expect &&
40 git cat-file -t $sha1 >actual &&
41 test_cmp expect actual
b335d3f1
AR
42 '
43
44 test_expect_success "Size of $type is correct" '
03c893cb
JK
45 echo $size >expect &&
46 git cat-file -s $sha1 >actual &&
47 test_cmp expect actual
b335d3f1
AR
48 '
49
3e370f9f
KN
50 test_expect_success "Type of $type is correct using --allow-unknown-type" '
51 echo $type >expect &&
52 git cat-file -t --allow-unknown-type $sha1 >actual &&
53 test_cmp expect actual
54 '
55
56 test_expect_success "Size of $type is correct using --allow-unknown-type" '
57 echo $size >expect &&
58 git cat-file -s --allow-unknown-type $sha1 >actual &&
59 test_cmp expect actual
60 '
61
b335d3f1
AR
62 test -z "$content" ||
63 test_expect_success "Content of $type is correct" '
03c893cb
JK
64 maybe_remove_timestamp "$content" $no_ts >expect &&
65 maybe_remove_timestamp "$(git cat-file $type $sha1)" $no_ts >actual &&
66 test_cmp expect actual
b335d3f1
AR
67 '
68
69 test_expect_success "Pretty content of $type is correct" '
03c893cb
JK
70 maybe_remove_timestamp "$pretty_content" $no_ts >expect &&
71 maybe_remove_timestamp "$(git cat-file -p $sha1)" $no_ts >actual &&
72 test_cmp expect actual
b335d3f1 73 '
05d5667f 74
a8128ed6
AR
75 test -z "$content" ||
76 test_expect_success "--batch output of $type is correct" '
03c893cb
JK
77 maybe_remove_timestamp "$batch_output" $no_ts >expect &&
78 maybe_remove_timestamp "$(echo $sha1 | git cat-file --batch)" $no_ts >actual &&
79 test_cmp expect actual
a8128ed6
AR
80 '
81
05d5667f 82 test_expect_success "--batch-check output of $type is correct" '
03c893cb
JK
83 echo "$sha1 $type $size" >expect &&
84 echo_without_newline $sha1 | git cat-file --batch-check >actual &&
85 test_cmp expect actual
05d5667f 86 '
93d2a607
JK
87
88 test_expect_success "custom --batch-check format" '
89 echo "$type $sha1" >expect &&
90 echo $sha1 | git cat-file --batch-check="%(objecttype) %(objectname)" >actual &&
91 test_cmp expect actual
92 '
97be0407
JK
93
94 test_expect_success '--batch-check with %(rest)' '
95 echo "$type this is some extra content" >expect &&
96 echo "$sha1 this is some extra content" |
97 git cat-file --batch-check="%(objecttype) %(rest)" >actual &&
98 test_cmp expect actual
99 '
6554dfa9
JK
100
101 test -z "$content" ||
102 test_expect_success "--batch without type ($type)" '
103 {
104 echo "$size" &&
105 maybe_remove_timestamp "$content" $no_ts
106 } >expect &&
107 echo $sha1 | git cat-file --batch="%(objectsize)" >actual.full &&
108 maybe_remove_timestamp "$(cat actual.full)" $no_ts >actual &&
109 test_cmp expect actual
110 '
111
112 test -z "$content" ||
113 test_expect_success "--batch without size ($type)" '
114 {
115 echo "$type" &&
116 maybe_remove_timestamp "$content" $no_ts
117 } >expect &&
118 echo $sha1 | git cat-file --batch="%(objecttype)" >actual.full &&
119 maybe_remove_timestamp "$(cat actual.full)" $no_ts >actual &&
120 test_cmp expect actual
121 '
b335d3f1
AR
122}
123
124hello_content="Hello World"
125hello_size=$(strlen "$hello_content")
126hello_sha1=$(echo_without_newline "$hello_content" | git hash-object --stdin)
127
128test_expect_success "setup" '
129 echo_without_newline "$hello_content" > hello &&
130 git update-index --add hello
131'
132
133run_tests 'blob' $hello_sha1 $hello_size "$hello_content" "$hello_content"
134
97be0407
JK
135test_expect_success '--batch-check without %(rest) considers whole line' '
136 echo "$hello_sha1 blob $hello_size" >expect &&
137 git update-index --add --cacheinfo 100644 $hello_sha1 "white space" &&
138 test_when_finished "git update-index --remove \"white space\"" &&
139 echo ":white space" | git cat-file --batch-check >actual &&
140 test_cmp expect actual
141'
142
b335d3f1 143tree_sha1=$(git write-tree)
e95f5313 144tree_size=$(($(test_oid rawsz) + 13))
b335d3f1
AR
145tree_pretty_content="100644 blob $hello_sha1 hello"
146
147run_tests 'tree' $tree_sha1 $tree_size "" "$tree_pretty_content"
148
41ccfdd9 149commit_message="Initial commit"
b335d3f1 150commit_sha1=$(echo_without_newline "$commit_message" | git commit-tree $tree_sha1)
e95f5313 151commit_size=$(($(test_oid hexsz) + 137))
b335d3f1
AR
152commit_content="tree $tree_sha1
153author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 0000000000 +0000
154committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 0000000000 +0000
155
156$commit_message"
157
158run_tests 'commit' $commit_sha1 $commit_size "$commit_content" "$commit_content" 1
159
160tag_header_without_timestamp="object $hello_sha1
161type blob
162tag hellotag
163tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
164tag_description="This is a tag"
165tag_content="$tag_header_without_timestamp 0000000000 +0000
166
b335d3f1
AR
167$tag_description"
168
acf9de4c 169tag_sha1=$(echo_without_newline "$tag_content" | git hash-object -t tag --stdin -w)
b335d3f1
AR
170tag_size=$(strlen "$tag_content")
171
9cfa5126 172run_tests 'tag' $tag_sha1 $tag_size "$tag_content" "$tag_content" 1
b335d3f1
AR
173
174test_expect_success \
175 "Reach a blob from a tag pointing to it" \
176 "test '$hello_content' = \"\$(git cat-file blob $tag_sha1)\""
177
a8128ed6 178for batch in batch batch-check
05d5667f 179do
a8128ed6
AR
180 for opt in t s e p
181 do
182 test_expect_success "Passing -$opt with --$batch fails" '
183 test_must_fail git cat-file --$batch -$opt $hello_sha1
184 '
185
186 test_expect_success "Passing --$batch with -$opt fails" '
187 test_must_fail git cat-file -$opt --$batch $hello_sha1
188 '
189 done
190
191 test_expect_success "Passing <type> with --$batch fails" '
192 test_must_fail git cat-file --$batch blob $hello_sha1
05d5667f
AR
193 '
194
a8128ed6
AR
195 test_expect_success "Passing --$batch with <type> fails" '
196 test_must_fail git cat-file blob --$batch $hello_sha1
05d5667f 197 '
05d5667f 198
a8128ed6
AR
199 test_expect_success "Passing sha1 with --$batch fails" '
200 test_must_fail git cat-file --$batch $hello_sha1
201 '
202done
05d5667f 203
122d5346
DT
204for opt in t s e p
205do
206 test_expect_success "Passing -$opt with --follow-symlinks fails" '
207 test_must_fail git cat-file --follow-symlinks -$opt $hello_sha1
208 '
209done
210
3c076dbe
LW
211test_expect_success "--batch-check for a non-existent named object" '
212 test "foobar42 missing
213foobar84 missing" = \
214 "$( ( echo foobar42; echo_without_newline foobar84; ) | git cat-file --batch-check)"
215'
216
217test_expect_success "--batch-check for a non-existent hash" '
218 test "0000000000000000000000000000000000000042 missing
2190000000000000000000000000000000000000084 missing" = \
220 "$( ( echo 0000000000000000000000000000000000000042;
bdbc17e8
MD
221 echo_without_newline 0000000000000000000000000000000000000084; ) |
222 git cat-file --batch-check)"
3c076dbe
LW
223'
224
225test_expect_success "--batch for an existent and a non-existent hash" '
226 test "$tag_sha1 tag $tag_size
227$tag_content
2280000000000000000000000000000000000000000 missing" = \
229 "$( ( echo $tag_sha1;
bdbc17e8
MD
230 echo_without_newline 0000000000000000000000000000000000000000; ) |
231 git cat-file --batch)"
05d5667f
AR
232'
233
2e3a16b2 234test_expect_success "--batch-check for an empty line" '
05d5667f
AR
235 test " missing" = "$(echo | git cat-file --batch-check)"
236'
237
4ef8d1dd 238test_expect_success 'empty --batch-check notices missing object' '
8125a58b 239 echo "$ZERO_OID missing" >expect &&
240 echo "$ZERO_OID" | git cat-file --batch-check="" >actual &&
4ef8d1dd
JH
241 test_cmp expect actual
242'
243
a8128ed6
AR
244batch_input="$hello_sha1
245$commit_sha1
246$tag_sha1
247deadbeef
248
249"
250
251batch_output="$hello_sha1 blob $hello_size
252$hello_content
253$commit_sha1 commit $commit_size
254$commit_content
255$tag_sha1 tag $tag_size
256$tag_content
257deadbeef missing
258 missing"
259
6c41e21d
MB
260test_expect_success '--batch with multiple sha1s gives correct format' '
261 test "$(maybe_remove_timestamp "$batch_output" 1)" = "$(maybe_remove_timestamp "$(echo_without_newline "$batch_input" | git cat-file --batch)" 1)"
262'
a8128ed6 263
05d5667f
AR
264batch_check_input="$hello_sha1
265$tree_sha1
266$commit_sha1
267$tag_sha1
268deadbeef
269
270"
271
272batch_check_output="$hello_sha1 blob $hello_size
273$tree_sha1 tree $tree_size
274$commit_sha1 commit $commit_size
275$tag_sha1 tag $tag_size
276deadbeef missing
277 missing"
278
279test_expect_success "--batch-check with multiple sha1s gives correct format" '
280 test "$batch_check_output" = \
281 "$(echo_without_newline "$batch_check_input" | git cat-file --batch-check)"
282'
283
65ea9c3c 284test_expect_success 'setup blobs which are likely to delta' '
c680668d 285 test-tool genrandom foo 10240 >foo &&
65ea9c3c
JK
286 { cat foo; echo plus; } >foo-plus &&
287 git add foo foo-plus &&
288 git commit -m foo &&
289 cat >blobs <<-\EOF
290 HEAD:foo
291 HEAD:foo-plus
292 EOF
293'
294
295test_expect_success 'confirm that neither loose blob is a delta' '
99094a7a 296 cat >expect <<-EOF &&
8125a58b 297 $ZERO_OID
298 $ZERO_OID
65ea9c3c
JK
299 EOF
300 git cat-file --batch-check="%(deltabase)" <blobs >actual &&
301 test_cmp expect actual
302'
303
304# To avoid relying too much on the current delta heuristics,
305# we will check only that one of the two objects is a delta
306# against the other, but not the order. We can do so by just
307# asking for the base of both, and checking whether either
308# sha1 appears in the output.
309test_expect_success '%(deltabase) reports packed delta bases' '
310 git repack -ad &&
311 git cat-file --batch-check="%(deltabase)" <blobs >actual &&
312 {
313 grep "$(git rev-parse HEAD:foo)" actual ||
314 grep "$(git rev-parse HEAD:foo-plus)" actual
315 }
316'
317
3e370f9f
KN
318bogus_type="bogus"
319bogus_content="bogus"
320bogus_size=$(strlen "$bogus_content")
321bogus_sha1=$(echo_without_newline "$bogus_content" | git hash-object -t $bogus_type --literally -w --stdin)
322
323test_expect_success "Type of broken object is correct" '
324 echo $bogus_type >expect &&
325 git cat-file -t --allow-unknown-type $bogus_sha1 >actual &&
326 test_cmp expect actual
327'
328
329test_expect_success "Size of broken object is correct" '
330 echo $bogus_size >expect &&
331 git cat-file -s --allow-unknown-type $bogus_sha1 >actual &&
332 test_cmp expect actual
333'
e879295b
JK
334
335test_expect_success 'clean up broken object' '
336 rm .git/objects/$(test_oid_to_path $bogus_sha1)
337'
338
3e370f9f
KN
339bogus_type="abcdefghijklmnopqrstuvwxyz1234679"
340bogus_content="bogus"
341bogus_size=$(strlen "$bogus_content")
342bogus_sha1=$(echo_without_newline "$bogus_content" | git hash-object -t $bogus_type --literally -w --stdin)
343
344test_expect_success "Type of broken object is correct when type is large" '
345 echo $bogus_type >expect &&
346 git cat-file -t --allow-unknown-type $bogus_sha1 >actual &&
347 test_cmp expect actual
348'
349
350test_expect_success "Size of large broken object is correct when type is large" '
351 echo $bogus_size >expect &&
352 git cat-file -s --allow-unknown-type $bogus_sha1 >actual &&
353 test_cmp expect actual
354'
355
e879295b
JK
356test_expect_success 'clean up broken object' '
357 rm .git/objects/$(test_oid_to_path $bogus_sha1)
358'
359
122d5346
DT
360# Tests for git cat-file --follow-symlinks
361test_expect_success 'prep for symlink tests' '
362 echo_without_newline "$hello_content" >morx &&
363 test_ln_s_add morx same-dir-link &&
364 test_ln_s_add dir link-to-dir &&
365 test_ln_s_add ../fleem out-of-repo-link &&
366 test_ln_s_add .. out-of-repo-link-dir &&
367 test_ln_s_add same-dir-link link-to-link &&
368 test_ln_s_add nope broken-same-dir-link &&
369 mkdir dir &&
370 test_ln_s_add ../morx dir/parent-dir-link &&
371 test_ln_s_add .. dir/link-dir &&
372 test_ln_s_add ../../escape dir/out-of-repo-link &&
373 test_ln_s_add ../.. dir/out-of-repo-link-dir &&
374 test_ln_s_add nope dir/broken-link-in-dir &&
375 mkdir dir/subdir &&
376 test_ln_s_add ../../morx dir/subdir/grandparent-dir-link &&
377 test_ln_s_add ../../../great-escape dir/subdir/out-of-repo-link &&
378 test_ln_s_add ../../.. dir/subdir/out-of-repo-link-dir &&
379 test_ln_s_add ../../../ dir/subdir/out-of-repo-link-dir-trailing &&
380 test_ln_s_add ../parent-dir-link dir/subdir/parent-dir-link-to-link &&
381 echo_without_newline "$hello_content" >dir/subdir/ind2 &&
382 echo_without_newline "$hello_content" >dir/ind1 &&
383 test_ln_s_add dir dirlink &&
384 test_ln_s_add dir/subdir subdirlink &&
385 test_ln_s_add subdir/ind2 dir/link-to-child &&
386 test_ln_s_add dir/link-to-child link-to-down-link &&
387 test_ln_s_add dir/.. up-down &&
388 test_ln_s_add dir/../ up-down-trailing &&
389 test_ln_s_add dir/../morx up-down-file &&
390 test_ln_s_add dir/../../morx up-up-down-file &&
391 test_ln_s_add subdirlink/../../morx up-two-down-file &&
392 test_ln_s_add loop1 loop2 &&
393 test_ln_s_add loop2 loop1 &&
394 git add morx dir/subdir/ind2 dir/ind1 &&
395 git commit -am "test" &&
396 echo $hello_sha1 blob $hello_size >found
397'
398
399test_expect_success 'git cat-file --batch-check --follow-symlinks works for non-links' '
400 echo HEAD:morx | git cat-file --batch-check --follow-symlinks >actual &&
401 test_cmp found actual &&
402 echo HEAD:nope missing >expect &&
403 echo HEAD:nope | git cat-file --batch-check --follow-symlinks >actual &&
404 test_cmp expect actual
405'
406
407test_expect_success 'git cat-file --batch-check --follow-symlinks works for in-repo, same-dir links' '
408 echo HEAD:same-dir-link | git cat-file --batch-check --follow-symlinks >actual &&
409 test_cmp found actual
410'
411
412test_expect_success 'git cat-file --batch-check --follow-symlinks works for in-repo, links to dirs' '
413 echo HEAD:link-to-dir/ind1 | git cat-file --batch-check --follow-symlinks >actual &&
414 test_cmp found actual
415'
416
417
418test_expect_success 'git cat-file --batch-check --follow-symlinks works for broken in-repo, same-dir links' '
419 echo dangling 25 >expect &&
420 echo HEAD:broken-same-dir-link >>expect &&
421 echo HEAD:broken-same-dir-link | git cat-file --batch-check --follow-symlinks >actual &&
422 test_cmp expect actual
423'
424
425test_expect_success 'git cat-file --batch-check --follow-symlinks works for same-dir links-to-links' '
426 echo HEAD:link-to-link | git cat-file --batch-check --follow-symlinks >actual &&
427 test_cmp found actual
428'
429
430test_expect_success 'git cat-file --batch-check --follow-symlinks works for parent-dir links' '
431 echo HEAD:dir/parent-dir-link | git cat-file --batch-check --follow-symlinks >actual &&
432 test_cmp found actual &&
433 echo notdir 29 >expect &&
434 echo HEAD:dir/parent-dir-link/nope >>expect &&
435 echo HEAD:dir/parent-dir-link/nope | git cat-file --batch-check --follow-symlinks >actual &&
436 test_cmp expect actual
437'
438
439test_expect_success 'git cat-file --batch-check --follow-symlinks works for .. links' '
440 echo dangling 22 >expect &&
441 echo HEAD:dir/link-dir/nope >>expect &&
442 echo HEAD:dir/link-dir/nope | git cat-file --batch-check --follow-symlinks >actual &&
443 test_cmp expect actual &&
444 echo HEAD:dir/link-dir/morx | git cat-file --batch-check --follow-symlinks >actual &&
445 test_cmp found actual &&
446 echo dangling 27 >expect &&
447 echo HEAD:dir/broken-link-in-dir >>expect &&
448 echo HEAD:dir/broken-link-in-dir | git cat-file --batch-check --follow-symlinks >actual &&
449 test_cmp expect actual
450'
451
452test_expect_success 'git cat-file --batch-check --follow-symlinks works for ../.. links' '
453 echo notdir 41 >expect &&
454 echo HEAD:dir/subdir/grandparent-dir-link/nope >>expect &&
455 echo HEAD:dir/subdir/grandparent-dir-link/nope | git cat-file --batch-check --follow-symlinks >actual &&
456 test_cmp expect actual &&
457 echo HEAD:dir/subdir/grandparent-dir-link | git cat-file --batch-check --follow-symlinks >actual &&
458 test_cmp found actual &&
459 echo HEAD:dir/subdir/parent-dir-link-to-link | git cat-file --batch-check --follow-symlinks >actual &&
460 test_cmp found actual
461'
462
463test_expect_success 'git cat-file --batch-check --follow-symlinks works for dir/ links' '
464 echo dangling 17 >expect &&
465 echo HEAD:dirlink/morx >>expect &&
466 echo HEAD:dirlink/morx | git cat-file --batch-check --follow-symlinks >actual &&
467 test_cmp expect actual &&
468 echo $hello_sha1 blob $hello_size >expect &&
469 echo HEAD:dirlink/ind1 | git cat-file --batch-check --follow-symlinks >actual &&
470 test_cmp expect actual
471'
472
473test_expect_success 'git cat-file --batch-check --follow-symlinks works for dir/subdir links' '
474 echo dangling 20 >expect &&
475 echo HEAD:subdirlink/morx >>expect &&
476 echo HEAD:subdirlink/morx | git cat-file --batch-check --follow-symlinks >actual &&
477 test_cmp expect actual &&
478 echo HEAD:subdirlink/ind2 | git cat-file --batch-check --follow-symlinks >actual &&
479 test_cmp found actual
480'
481
482test_expect_success 'git cat-file --batch-check --follow-symlinks works for dir ->subdir links' '
483 echo notdir 27 >expect &&
484 echo HEAD:dir/link-to-child/morx >>expect &&
485 echo HEAD:dir/link-to-child/morx | git cat-file --batch-check --follow-symlinks >actual &&
486 test_cmp expect actual &&
487 echo HEAD:dir/link-to-child | git cat-file --batch-check --follow-symlinks >actual &&
488 test_cmp found actual &&
489 echo HEAD:link-to-down-link | git cat-file --batch-check --follow-symlinks >actual &&
490 test_cmp found actual
491'
492
493test_expect_success 'git cat-file --batch-check --follow-symlinks works for out-of-repo symlinks' '
494 echo symlink 8 >expect &&
495 echo ../fleem >>expect &&
496 echo HEAD:out-of-repo-link | git cat-file --batch-check --follow-symlinks >actual &&
497 test_cmp expect actual &&
498 echo symlink 2 >expect &&
499 echo .. >>expect &&
500 echo HEAD:out-of-repo-link-dir | git cat-file --batch-check --follow-symlinks >actual &&
501 test_cmp expect actual
502'
503
504test_expect_success 'git cat-file --batch-check --follow-symlinks works for out-of-repo symlinks in dirs' '
505 echo symlink 9 >expect &&
506 echo ../escape >>expect &&
507 echo HEAD:dir/out-of-repo-link | git cat-file --batch-check --follow-symlinks >actual &&
508 test_cmp expect actual &&
509 echo symlink 2 >expect &&
510 echo .. >>expect &&
511 echo HEAD:dir/out-of-repo-link-dir | git cat-file --batch-check --follow-symlinks >actual &&
512 test_cmp expect actual
513'
514
515test_expect_success 'git cat-file --batch-check --follow-symlinks works for out-of-repo symlinks in subdirs' '
516 echo symlink 15 >expect &&
517 echo ../great-escape >>expect &&
518 echo HEAD:dir/subdir/out-of-repo-link | git cat-file --batch-check --follow-symlinks >actual &&
519 test_cmp expect actual &&
520 echo symlink 2 >expect &&
521 echo .. >>expect &&
522 echo HEAD:dir/subdir/out-of-repo-link-dir | git cat-file --batch-check --follow-symlinks >actual &&
523 test_cmp expect actual &&
524 echo symlink 3 >expect &&
525 echo ../ >>expect &&
526 echo HEAD:dir/subdir/out-of-repo-link-dir-trailing | git cat-file --batch-check --follow-symlinks >actual &&
527 test_cmp expect actual
528'
529
530test_expect_success 'git cat-file --batch-check --follow-symlinks works for symlinks with internal ..' '
531 echo HEAD: | git cat-file --batch-check >expect &&
532 echo HEAD:up-down | git cat-file --batch-check --follow-symlinks >actual &&
533 test_cmp expect actual &&
534 echo HEAD:up-down-trailing | git cat-file --batch-check --follow-symlinks >actual &&
535 test_cmp expect actual &&
536 echo HEAD:up-down-file | git cat-file --batch-check --follow-symlinks >actual &&
537 test_cmp found actual &&
538 echo symlink 7 >expect &&
539 echo ../morx >>expect &&
540 echo HEAD:up-up-down-file | git cat-file --batch-check --follow-symlinks >actual &&
541 test_cmp expect actual &&
542 echo HEAD:up-two-down-file | git cat-file --batch-check --follow-symlinks >actual &&
543 test_cmp found actual
544'
545
546test_expect_success 'git cat-file --batch-check --follow-symlink breaks loops' '
547 echo loop 10 >expect &&
548 echo HEAD:loop1 >>expect &&
549 echo HEAD:loop1 | git cat-file --batch-check --follow-symlinks >actual &&
550 test_cmp expect actual
551'
552
553test_expect_success 'git cat-file --batch --follow-symlink returns correct sha and mode' '
554 echo HEAD:morx | git cat-file --batch >expect &&
555 echo HEAD:morx | git cat-file --batch --follow-symlinks >actual &&
556 test_cmp expect actual
557'
67f0b6f3 558
6a951937 559test_expect_success 'cat-file --batch-all-objects shows all objects' '
3115ee45 560 # make new repos so we know the full set of objects; we will
6a951937 561 # also make sure that there are some packed and some loose
aa2f5ef5
JK
562 # objects, some referenced and some not, some duplicates, and that
563 # there are some available only via alternates.
6a951937
JK
564 git init all-one &&
565 (
566 cd all-one &&
567 echo content >file &&
568 git add file &&
569 git commit -qm base &&
570 git rev-parse HEAD HEAD^{tree} HEAD:file &&
571 git repack -ad &&
572 echo not-cloned | git hash-object -w --stdin
573 ) >expect.unsorted &&
574 git clone -s all-one all-two &&
575 (
576 cd all-two &&
577 echo local-unref | git hash-object -w --stdin
578 ) >>expect.unsorted &&
aa2f5ef5
JK
579 git -C all-two rev-parse HEAD:file |
580 git -C all-two pack-objects .git/objects/pack/pack &&
6a951937
JK
581 sort <expect.unsorted >expect &&
582 git -C all-two cat-file --batch-all-objects \
3115ee45 583 --batch-check="%(objectname)" >actual &&
6a951937
JK
584 test_cmp expect actual
585'
586
0750bb5b
JK
587# The only user-visible difference is that the objects are no longer sorted,
588# and the resulting sort order is undefined. So we can only check that it
589# produces the same objects as the ordered case, but that at least exercises
590# the code.
591test_expect_success 'cat-file --unordered works' '
592 git -C all-two cat-file --batch-all-objects --unordered \
593 --batch-check="%(objectname)" >actual.unsorted &&
594 sort <actual.unsorted >actual &&
595 test_cmp expect actual
596'
597
e16acc80
ZH
598test_expect_success 'set up object list for --batch-all-objects tests' '
599 git -C all-two cat-file --batch-all-objects --batch-check="%(objectname)" >objects
600'
601
602test_expect_success 'cat-file --batch="%(objectname)" with --batch-all-objects will work' '
603 git -C all-two cat-file --batch="%(objectname)" <objects >expect &&
604 git -C all-two cat-file --batch-all-objects --batch="%(objectname)" >actual &&
605 cmp expect actual
606'
607
608test_expect_success 'cat-file --batch="%(rest)" with --batch-all-objects will work' '
609 git -C all-two cat-file --batch="%(rest)" <objects >expect &&
610 git -C all-two cat-file --batch-all-objects --batch="%(rest)" >actual &&
611 cmp expect actual
612'
613
614test_expect_success 'cat-file --batch="batman" with --batch-all-objects will work' '
615 git -C all-two cat-file --batch="batman" <objects >expect &&
616 git -C all-two cat-file --batch-all-objects --batch="batman" >actual &&
617 cmp expect actual
618'
619
b335d3f1 620test_done