89
for opt in --buffer \
90
--follow-symlinks \
91
--batch-all-objects \
92
- -z
92
+ -z \
93
+ -Z
94
do
95
test_expect_success "usage: bad option combination: $opt without batch mode" '
96
test_incompatible_usage git cat-file $opt &&
393
394
"
395
395
-batch_output="$hello_sha1 blob $hello_size
396
-$hello_content
397
-$commit_sha1 commit $commit_size
398
-$commit_content
399
-$tag_sha1 tag $tag_size
400
-$tag_content
401
-deadbeef missing
402
- missing"
396
+printf "%s\0" \
397
+ "$hello_sha1 blob $hello_size" \
398
+ "$hello_content" \
399
+ "$commit_sha1 commit $commit_size" \
400
+ "$commit_content" \
401
+ "$tag_sha1 tag $tag_size" \
402
+ "$tag_content" \
403
+ "deadbeef missing" \
404
+ " missing" >batch_output
405
406
test_expect_success '--batch with multiple sha1s gives correct format' '
405
- echo "$batch_output" >expect &&
407
+ tr "\0" "\n" <batch_output >expect &&
408
echo_without_newline "$batch_input" >in &&
409
git cat-file --batch <in >actual &&
410
test_cmp expect actual
412
413
test_expect_success '--batch, -z with multiple sha1s gives correct format' '
414
echo_without_newline_nul "$batch_input" >in &&
413
- echo "$batch_output" >expect &&
415
+ tr "\0" "\n" <batch_output >expect &&
416
git cat-file --batch -z <in >actual &&
417
test_cmp expect actual
418
'
419
420
+test_expect_success '--batch, -Z with multiple sha1s gives correct format' '
421
+ echo_without_newline_nul "$batch_input" >in &&
422
+ git cat-file --batch -Z <in >actual &&
423
+ test_cmp batch_output actual
424
+'
425
+
426
batch_check_input="$hello_sha1
427
$tree_sha1
428
$commit_sha1
431
432
"
433
426
-batch_check_output="$hello_sha1 blob $hello_size
427
-$tree_sha1 tree $tree_size
428
-$commit_sha1 commit $commit_size
429
-$tag_sha1 tag $tag_size
430
-deadbeef missing
431
- missing"
434
+printf "%s\0" \
435
+ "$hello_sha1 blob $hello_size" \
436
+ "$tree_sha1 tree $tree_size" \
437
+ "$commit_sha1 commit $commit_size" \
438
+ "$tag_sha1 tag $tag_size" \
439
+ "deadbeef missing" \
440
+ " missing" >batch_check_output
441
442
test_expect_success "--batch-check with multiple sha1s gives correct format" '
434
- echo "$batch_check_output" >expect &&
443
+ tr "\0" "\n" <batch_check_output >expect &&
444
echo_without_newline "$batch_check_input" >in &&
445
git cat-file --batch-check <in >actual &&
446
test_cmp expect actual
447
'
448
449
test_expect_success "--batch-check, -z with multiple sha1s gives correct format" '
441
- echo "$batch_check_output" >expect &&
450
+ tr "\0" "\n" <batch_check_output >expect &&
451
echo_without_newline_nul "$batch_check_input" >in &&
452
git cat-file --batch-check -z <in >actual &&
453
test_cmp expect actual
454
'
455
447
-test_expect_success FUNNYNAMES '--batch-check, -z with newline in input' '
456
+test_expect_success "--batch-check, -Z with multiple sha1s gives correct format" '
457
+ echo_without_newline_nul "$batch_check_input" >in &&
458
+ git cat-file --batch-check -Z <in >actual &&
459
+ test_cmp batch_check_output actual
460
+'
461
+
462
+test_expect_success FUNNYNAMES 'setup with newline in input' '
463
touch -- "newline${LF}embedded" &&
464
git add -- "newline${LF}embedded" &&
465
git commit -m "file with newline embedded" &&
466
test_tick &&
467
453
- printf "HEAD:newline${LF}embedded" >in &&
454
- git cat-file --batch-check -z <in >actual &&
468
+ printf "HEAD:newline${LF}embedded" >in
469
+'
470
471
+test_expect_success FUNNYNAMES '--batch-check, -z with newline in input' '
472
+ git cat-file --batch-check -z <in >actual &&
473
echo "$(git rev-parse "HEAD:newline${LF}embedded") blob 0" >expect &&
474
test_cmp expect actual
475
'
476
477
+test_expect_success FUNNYNAMES '--batch-check, -Z with newline in input' '
478
+ git cat-file --batch-check -Z <in >actual &&
479
+ printf "%s\0" "$(git rev-parse "HEAD:newline${LF}embedded") blob 0" >expect &&
480
+ test_cmp expect actual
481
+'
482
+
483
batch_command_multiple_info="info $hello_sha1
484
info $tree_sha1
485
info $commit_sha1
503
echo "$batch_command_multiple_info" | tr "\n" "\0" >in &&
504
git cat-file --batch-command --buffer -z <in >actual &&
505
483
- test_cmp expect actual
506
+ test_cmp expect actual &&
507
+
508
+ echo "$batch_command_multiple_info" | tr "\n" "\0" >in &&
509
+ tr "\n" "\0" <expect >expect_nul &&
510
+ git cat-file --batch-command --buffer -Z <in >actual &&
511
+
512
+ test_cmp expect_nul actual
513
'
514
515
batch_command_multiple_contents="contents $hello_sha1
519
flush"
520
521
test_expect_success '--batch-command with multiple command calls gives correct format' '
493
- cat >expect <<-EOF &&
494
- $hello_sha1 blob $hello_size
495
- $hello_content
496
- $commit_sha1 commit $commit_size
497
- $commit_content
498
- $tag_sha1 tag $tag_size
499
- $tag_content
500
- deadbeef missing
501
- EOF
522
+ printf "%s\0" \
523
+ "$hello_sha1 blob $hello_size" \
524
+ "$hello_content" \
525
+ "$commit_sha1 commit $commit_size" \
526
+ "$commit_content" \
527
+ "$tag_sha1 tag $tag_size" \
528
+ "$tag_content" \
529
+ "deadbeef missing" >expect_nul &&
530
+ tr "\0" "\n" <expect_nul >expect &&
531
532
echo "$batch_command_multiple_contents" >in &&
533
git cat-file --batch-command --buffer <in >actual &&
537
echo "$batch_command_multiple_contents" | tr "\n" "\0" >in &&
538
git cat-file --batch-command --buffer -z <in >actual &&
539
511
- test_cmp expect actual
540
+ test_cmp expect actual &&
541
+
542
+ echo "$batch_command_multiple_contents" | tr "\n" "\0" >in &&
543
+ git cat-file --batch-command --buffer -Z <in >actual &&
544
+
545
+ test_cmp expect_nul actual
546
'
547
548
test_expect_success 'setup blobs which are likely to delta' '
882
test_cmp expect actual
883
'
884
885
+test_expect_success 'git cat-file --batch-check --follow-symlinks -Z works for broken in-repo, same-dir links' '
886
+ printf "HEAD:broken-same-dir-link\0" >in &&
887
+ printf "dangling 25\0HEAD:broken-same-dir-link\0" >expect &&
888
+ git cat-file --batch-check --follow-symlinks -Z <in >actual &&
889
+ test_cmp expect actual
890
+'
891
+
892
test_expect_success 'git cat-file --batch-check --follow-symlinks works for same-dir links-to-links' '
893
echo HEAD:link-to-link | git cat-file --batch-check --follow-symlinks >actual &&
894
test_cmp found actual
903
test_cmp expect actual
904
'
905
906
+test_expect_success 'git cat-file --batch-check --follow-symlinks -Z works for parent-dir links' '
907
+ echo HEAD:dir/parent-dir-link | git cat-file --batch-check --follow-symlinks >actual &&
908
+ test_cmp found actual &&
909
+ printf "notdir 29\0HEAD:dir/parent-dir-link/nope\0" >expect &&
910
+ printf "HEAD:dir/parent-dir-link/nope\0" >in &&
911
+ git cat-file --batch-check --follow-symlinks -Z <in >actual &&
912
+ test_cmp expect actual
913
+'
914
+
915
test_expect_success 'git cat-file --batch-check --follow-symlinks works for .. links' '
916
echo dangling 22 >expect &&
917
echo HEAD:dir/link-dir/nope >>expect &&
1026
test_cmp expect actual
1027
'
1028
1029
+test_expect_success 'git cat-file --batch-check --follow-symlink -Z breaks loops' '
1030
+ printf "loop 10\0HEAD:loop1\0" >expect &&
1031
+ printf "HEAD:loop1\0" >in &&
1032
+ git cat-file --batch-check --follow-symlinks -Z <in >actual &&
1033
+ test_cmp expect actual
1034
+'
1035
+
1036
test_expect_success 'git cat-file --batch --follow-symlink returns correct sha and mode' '
1037
echo HEAD:morx | git cat-file --batch >expect &&
1038
echo HEAD:morx | git cat-file --batch --follow-symlinks >actual &&