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