diff --git a/builtin/cat-file.c b/builtin/cat-file.c index 884b6d5ad3..e85e2cfc1b 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -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, diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh index 0c1dc0fb40..72fc8acc61 100755 --- a/t/t1006-cat-file.sh +++ b/t/t1006-cat-file.sh @@ -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;