Skip to content

Commit c99ad27

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b15a3e0 commit c99ad27

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

pretty.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,8 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
10621062
case 'C':
10631063
if (starts_with(placeholder + 1, "(auto)")) {
10641064
c->auto_color = want_color(c->pretty_ctx->color);
1065+
if (c->auto_color)
1066+
strbuf_addstr(sb, GIT_COLOR_RESET);
10651067
return 7; /* consumed 7 bytes, "C(auto)" */
10661068
} else {
10671069
int ret = parse_color(sb, placeholder, c);

t/t6006-rev-list-format.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ test_expect_success '%C(auto,...) respects --color=auto (stdout not tty)' '
225225

226226
test_expect_success '%C(auto) respects --color' '
227227
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 &&
229229
test_cmp expect actual
230230
'
231231

0 commit comments

Comments
 (0)