8888
8989for opt in --buffer \
9090 --follow-symlinks \
91- --batch-all-objects
91+ --batch-all-objects \
92+ -z
9293do
9394 test_expect_success " usage: bad option combination: $opt without batch mode" '
9495 test_incompatible_usage git cat-file $opt &&
@@ -100,6 +101,10 @@ echo_without_newline () {
100101 printf ' %s' " $* "
101102}
102103
104+ echo_without_newline_nul () {
105+ echo_without_newline " $@ " | tr ' \n' ' \0'
106+ }
107+
103108strlen () {
104109 echo_without_newline " $1 " | wc -c | sed -e ' s/^ *//'
105110}
@@ -398,6 +403,12 @@ test_expect_success '--batch with multiple sha1s gives correct format' '
398403 test "$(maybe_remove_timestamp "$batch_output" 1)" = "$(maybe_remove_timestamp "$(echo_without_newline "$batch_input" | git cat-file --batch)" 1)"
399404'
400405
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+
401412batch_check_input=" $hello_sha1
402413$tree_sha1
403414$commit_sha1
@@ -418,6 +429,30 @@ test_expect_success "--batch-check with multiple sha1s gives correct format" '
418429 "$(echo_without_newline "$batch_check_input" | git cat-file --batch-check)"
419430'
420431
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+
421456test_expect_success ' --batch-command with multiple info calls gives correct format' '
422457 cat >expect <<-EOF &&
423458 $hello_sha1 blob $hello_size
@@ -427,17 +462,23 @@ test_expect_success '--batch-command with multiple info calls gives correct form
427462 deadbeef missing
428463 EOF
429464
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 &&
437472
438473 test_cmp expect actual
439474'
440475
476+ batch_command_multiple_contents=" contents $hello_sha1
477+ contents $commit_sha1
478+ contents $tag_sha1
479+ contents deadbeef
480+ flush"
481+
441482test_expect_success ' --batch-command with multiple command calls gives correct format' '
442483 remove_timestamp >expect <<-EOF &&
443484 $hello_sha1 blob $hello_size
@@ -449,13 +490,14 @@ test_expect_success '--batch-command with multiple command calls gives correct f
449490 deadbeef missing
450491 EOF
451492
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 &&
459501
460502 remove_timestamp <actual_raw >actual &&
461503 test_cmp expect actual
0 commit comments