pretty: let %C(auto) reset all attributes
Reset colors and attributes upon %C(auto) to enable full automatic control over them; otherwise attributes like bold or reverse could still be in effect from previous %C placeholders. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Sep 17, 2016 at 20:25 UTC
c99ad274b196bc97f22c1c39178784668cb4623d
2 files changed
+3
-1
pretty.c
+2
@@ -1062,6 +1062,8 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
1062
case 'C':
1063
if (starts_with(placeholder + 1, "(auto)")) {
1064
c->auto_color = want_color(c->pretty_ctx->color);
1065
+ if (c->auto_color)
1066
+ strbuf_addstr(sb, GIT_COLOR_RESET);
1067
return 7; /* consumed 7 bytes, "C(auto)" */
1068
} else {
1069
int ret = parse_color(sb, placeholder, c);
t/t6006-rev-list-format.sh
+1
-1
@@ -225,7 +225,7 @@ test_expect_success '%C(auto,...) respects --color=auto (stdout not tty)' '
225
226
test_expect_success '%C(auto) respects --color' '
227
git log --color --format="%C(auto)%H" -1 >actual &&
228
- printf "\\033[33m%s\\033[m\\n" $(git rev-parse HEAD) >expect &&
228
+ printf "\\033[m\\033[33m%s\\033[m\\n" $(git rev-parse HEAD) >expect &&
229
test_cmp expect actual
230
'
231