Skip to content

Commit 578e602

Browse files
committed
Merge branch 'rs/c-auto-resets-attributes'
When "%C(auto)" appears at the very beginning of the pretty format string, it did not need to issue the reset sequence, but it did. * rs/c-auto-resets-attributes: pretty: avoid adding reset for %C(auto) if output is empty
2 parents fbfe878 + 82b83da commit 578e602

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

pretty.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
10721072
case 'C':
10731073
if (starts_with(placeholder + 1, "(auto)")) {
10741074
c->auto_color = want_color(c->pretty_ctx->color);
1075-
if (c->auto_color)
1075+
if (c->auto_color && sb->len)
10761076
strbuf_addstr(sb, GIT_COLOR_RESET);
10771077
return 7; /* consumed 7 bytes, "C(auto)" */
10781078
} else {

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[m\\033[33m%s\\033[m\\n" $(git rev-parse HEAD) >expect &&
228+
printf "\\033[33m%s\\033[m\\n" $(git rev-parse HEAD) >expect &&
229229
test_cmp expect actual
230230
'
231231

0 commit comments

Comments
 (0)