diff --git a/builtin/cat-file.c b/builtin/cat-file.c index d6ef8414ee..826a1c6620 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -687,8 +687,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 8e2c52652c..d0db1f2a29 100755 --- a/t/t1006-cat-file.sh +++ b/t/t1006-cat-file.sh @@ -1351,6 +1351,14 @@ test_expect_success 'batch-command flush without --buffer' ' 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;