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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Jul 13, 2017 at 11:07 UTC
d75dfb1089d471501f6042341bed647525f6e293
2 files changed
+12
builtin/rev-list.c
+1
@@ -122,6 +122,7 @@ static void show_commit(struct commit *commit, void *data)
122
ctx.date_mode_explicit = revs->date_mode_explicit;
123
ctx.fmt = revs->commit_format;
124
ctx.output_encoding = get_log_output_encoding();
125
+ ctx.color = revs->diffopt.use_color;
126
pretty_print_commit(&ctx, commit, &buf);
127
if (buf.len) {
128
if (revs->commit_format != CMIT_FMT_ONELINE)
t/t6006-rev-list-format.sh
+11
@@ -245,6 +245,17 @@ test_expect_success '%C(auto) respects --no-color' '
245
test_cmp expect actual
246
'
247
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
+
259
iconv -f utf-8 -t $test_encoding > commit-msg <<EOF
260
Test printing of complex bodies
261