88
88
89
89
for opt in --buffer \
90
90
--follow-symlinks \
91
- --batch-all-objects
91
+ --batch-all-objects \
92
+ -z
92
93
do
93
94
test_expect_success " usage: bad option combination: $opt without batch mode" '
94
95
test_incompatible_usage git cat-file $opt &&
@@ -100,6 +101,10 @@ echo_without_newline () {
100
101
printf ' %s' " $* "
101
102
}
102
103
104
+ echo_without_newline_nul () {
105
+ echo_without_newline " $@ " | tr ' \n' ' \0'
106
+ }
107
+
103
108
strlen () {
104
109
echo_without_newline " $1 " | wc -c | sed -e ' s/^ *//'
105
110
}
@@ -398,6 +403,12 @@ test_expect_success '--batch with multiple sha1s gives correct format' '
398
403
test "$(maybe_remove_timestamp "$batch_output" 1)" = "$(maybe_remove_timestamp "$(echo_without_newline "$batch_input" | git cat-file --batch)" 1)"
399
404
'
400
405
406
+ test_expect_success ' --batch, -z with multiple sha1s gives correct format' '
407
+ echo_without_newline_nul "$batch_input" >in &&
408
+ test "$(maybe_remove_timestamp "$batch_output" 1)" = \
409
+ "$(maybe_remove_timestamp "$(git cat-file --batch -z <in)" 1)"
410
+ '
411
+
401
412
batch_check_input=" $hello_sha1
402
413
$tree_sha1
403
414
$commit_sha1
@@ -418,6 +429,30 @@ test_expect_success "--batch-check with multiple sha1s gives correct format" '
418
429
"$(echo_without_newline "$batch_check_input" | git cat-file --batch-check)"
419
430
'
420
431
432
+ test_expect_success " --batch-check, -z with multiple sha1s gives correct format" '
433
+ echo_without_newline_nul "$batch_check_input" >in &&
434
+ test "$batch_check_output" = "$(git cat-file --batch-check -z <in)"
435
+ '
436
+
437
+ test_expect_success FUNNYNAMES ' --batch-check, -z with newline in input' '
438
+ touch -- "newline${LF}embedded" &&
439
+ git add -- "newline${LF}embedded" &&
440
+ git commit -m "file with newline embedded" &&
441
+ test_tick &&
442
+
443
+ printf "HEAD:newline${LF}embedded" >in &&
444
+ git cat-file --batch-check -z <in >actual &&
445
+
446
+ echo "$(git rev-parse "HEAD:newline${LF}embedded") blob 0" >expect &&
447
+ test_cmp expect actual
448
+ '
449
+
450
+ batch_command_multiple_info=" info $hello_sha1
451
+ info $tree_sha1
452
+ info $commit_sha1
453
+ info $tag_sha1
454
+ info deadbeef"
455
+
421
456
test_expect_success ' --batch-command with multiple info calls gives correct format' '
422
457
cat >expect <<-EOF &&
423
458
$hello_sha1 blob $hello_size
@@ -427,17 +462,23 @@ test_expect_success '--batch-command with multiple info calls gives correct form
427
462
deadbeef missing
428
463
EOF
429
464
430
- git cat-file --batch-command --buffer >actual <<-EOF &&
431
- info $hello_sha1
432
- info $tree_sha1
433
- info $commit_sha1
434
- info $tag_sha1
435
- info deadbeef
436
- EOF
465
+ echo "$batch_command_multiple_info" >in &&
466
+ git cat-file --batch-command --buffer <in >actual &&
467
+
468
+ test_cmp expect actual &&
469
+
470
+ echo "$batch_command_multiple_info" | tr "\n" "\0" >in &&
471
+ git cat-file --batch-command --buffer -z <in >actual &&
437
472
438
473
test_cmp expect actual
439
474
'
440
475
476
+ batch_command_multiple_contents=" contents $hello_sha1
477
+ contents $commit_sha1
478
+ contents $tag_sha1
479
+ contents deadbeef
480
+ flush"
481
+
441
482
test_expect_success ' --batch-command with multiple command calls gives correct format' '
442
483
remove_timestamp >expect <<-EOF &&
443
484
$hello_sha1 blob $hello_size
@@ -449,13 +490,14 @@ test_expect_success '--batch-command with multiple command calls gives correct f
449
490
deadbeef missing
450
491
EOF
451
492
452
- git cat-file --batch-command --buffer >actual_raw <<-EOF &&
453
- contents $hello_sha1
454
- contents $commit_sha1
455
- contents $tag_sha1
456
- contents deadbeef
457
- flush
458
- EOF
493
+ echo "$batch_command_multiple_contents" >in &&
494
+ git cat-file --batch-command --buffer <in >actual_raw &&
495
+
496
+ remove_timestamp <actual_raw >actual &&
497
+ test_cmp expect actual &&
498
+
499
+ echo "$batch_command_multiple_contents" | tr "\n" "\0" >in &&
500
+ git cat-file --batch-command --buffer -z <in >actual_raw &&
459
501
460
502
remove_timestamp <actual_raw >actual &&
461
503
test_cmp expect actual
0 commit comments