Skip to content

Commit fbb4138

Browse files
committed
Merge branch 'et/pretty-format-c-auto' into maint
The commands in `git log` family take %C(auto) in a custom format string. This unconditionally turned the color on, ignoring --no-color or with --color=auto when the output is not connected to a tty; this was corrected to make the format truly behave as "auto". * et/pretty-format-c-auto: format_commit_message: honor `color=auto` for `%C(auto)`
2 parents 0a20325 + b15a3e0 commit fbb4138

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

pretty.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
10631063
switch (placeholder[0]) {
10641064
case 'C':
10651065
if (starts_with(placeholder + 1, "(auto)")) {
1066-
c->auto_color = 1;
1066+
c->auto_color = want_color(c->pretty_ctx->color);
10671067
return 7; /* consumed 7 bytes, "C(auto)" */
10681068
} else {
10691069
int ret = parse_color(sb, placeholder, c);

t/t6006-rev-list-format.sh

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,45 +184,57 @@ commit $head1
184184
foo
185185
EOF
186186

187-
test_expect_success '%C(auto) does not enable color by default' '
187+
test_expect_success '%C(auto,...) does not enable color by default' '
188188
git log --format=$AUTO_COLOR -1 >actual &&
189189
has_no_color actual
190190
'
191191

192-
test_expect_success '%C(auto) enables colors for color.diff' '
192+
test_expect_success '%C(auto,...) enables colors for color.diff' '
193193
git -c color.diff=always log --format=$AUTO_COLOR -1 >actual &&
194194
has_color actual
195195
'
196196

197-
test_expect_success '%C(auto) enables colors for color.ui' '
197+
test_expect_success '%C(auto,...) enables colors for color.ui' '
198198
git -c color.ui=always log --format=$AUTO_COLOR -1 >actual &&
199199
has_color actual
200200
'
201201

202-
test_expect_success '%C(auto) respects --color' '
202+
test_expect_success '%C(auto,...) respects --color' '
203203
git log --format=$AUTO_COLOR -1 --color >actual &&
204204
has_color actual
205205
'
206206

207-
test_expect_success '%C(auto) respects --no-color' '
207+
test_expect_success '%C(auto,...) respects --no-color' '
208208
git -c color.ui=always log --format=$AUTO_COLOR -1 --no-color >actual &&
209209
has_no_color actual
210210
'
211211

212-
test_expect_success TTY '%C(auto) respects --color=auto (stdout is tty)' '
212+
test_expect_success TTY '%C(auto,...) respects --color=auto (stdout is tty)' '
213213
test_terminal env TERM=vt100 \
214214
git log --format=$AUTO_COLOR -1 --color=auto >actual &&
215215
has_color actual
216216
'
217217

218-
test_expect_success '%C(auto) respects --color=auto (stdout not tty)' '
218+
test_expect_success '%C(auto,...) respects --color=auto (stdout not tty)' '
219219
(
220220
TERM=vt100 && export TERM &&
221221
git log --format=$AUTO_COLOR -1 --color=auto >actual &&
222222
has_no_color actual
223223
)
224224
'
225225

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 &&
229+
test_cmp expect actual
230+
'
231+
232+
test_expect_success '%C(auto) respects --no-color' '
233+
git log --no-color --format="%C(auto)%H" -1 >actual &&
234+
git rev-parse HEAD >expect &&
235+
test_cmp expect actual
236+
'
237+
226238
iconv -f utf-8 -t $test_encoding > commit-msg <<EOF
227239
Test printing of complex bodies
228240

0 commit comments

Comments
 (0)