Merge branch 'jk/cat-file-batch-wo-type-fix' into next

'git cat-file --batch-command' that asked for 'contents' without
'type' segfaults, which has been corrected.

* jk/cat-file-batch-wo-type-fix:
  cat-file: handle content request for --batch-command without type
next
Junio C Hamano 2026-07-31 08:55:06 -07:00
commit 2d67bd3ccf
2 changed files with 11 additions and 0 deletions

View File

@ -789,8 +789,11 @@ static void parse_cmd_contents(struct batch_options *opt,
struct strbuf *output,
struct expand_data *data)
{
enum object_type *saved_typep = data->info.typep;
data->info.typep = &data->type;
opt->batch_mode = BATCH_MODE_CONTENTS;
batch_one_object(line, output, opt, data);
data->info.typep = saved_typep;
}

static void parse_cmd_info(struct batch_options *opt,

View File

@ -1340,6 +1340,14 @@ test_expect_success 'batch-command flush without --buffer' '
test_grep "^fatal:.*flush is only for --buffer mode.*" err
'

test_expect_success 'batch-command contents auto-handles type' '
echo "HEAD" |
git cat-file --batch="%(objectname)" >expect &&
echo "contents HEAD" |
git cat-file --batch-command="%(objectname)" >actual &&
test_cmp expect actual
'

perl_script='
use warnings;
use strict;