Skip to content

Commit d75dfb1

Browse files
peffgitster
authored andcommitted
rev-list: pass diffopt->use_colors through to pretty-print
When rev-list pretty-prints a commit, it creates a new pretty_print_context and copies items from the rev_info struct. We don't currently copy the "use_color" field, though. Nobody seems to have noticed because the only part of pretty.c that cares is the %C(auto,...) placeholder, and presumably not many people use that with the rev-list plumbing (as opposed to with git-log). It will become more noticeable in a future patch, though, when we start treating all user-format colors as auto-colors (in which case it would become impossible to format colors with rev-list, even with --color=always). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d8b6868 commit d75dfb1

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

builtin/rev-list.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ static void show_commit(struct commit *commit, void *data)
122122
ctx.date_mode_explicit = revs->date_mode_explicit;
123123
ctx.fmt = revs->commit_format;
124124
ctx.output_encoding = get_log_output_encoding();
125+
ctx.color = revs->diffopt.use_color;
125126
pretty_print_commit(&ctx, commit, &buf);
126127
if (buf.len) {
127128
if (revs->commit_format != CMIT_FMT_ONELINE)

t/t6006-rev-list-format.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,17 @@ test_expect_success '%C(auto) respects --no-color' '
245245
test_cmp expect actual
246246
'
247247

248+
test_expect_success 'rev-list %C(auto,...) respects --color' '
249+
git rev-list --color --format="%C(auto,green)foo%C(auto,reset)" \
250+
-1 HEAD >actual.raw &&
251+
test_decode_color <actual.raw >actual &&
252+
cat >expect <<-EOF &&
253+
commit $(git rev-parse HEAD)
254+
<GREEN>foo<RESET>
255+
EOF
256+
test_cmp expect actual
257+
'
258+
248259
iconv -f utf-8 -t $test_encoding > commit-msg <<EOF
249260
Test printing of complex bodies
250261

0 commit comments

Comments
 (0)