33test_description=' git rev-list --pretty=format test'
44
55. ./test-lib.sh
6+ . " $TEST_DIRECTORY " /lib-terminal.sh
67
78test_tick
89test_expect_success ' setup' '
@@ -11,12 +12,24 @@ touch foo && git add foo && git commit -m "added foo" &&
1112'
1213
1314# usage: test_format name format_string <expected_output
14- test_format () {
15+ test_format () {
1516 cat > expect.$1
1617 test_expect_success " format $1 " "
17- git rev-list --pretty=format:'$2 ' master >output.$1 &&
18- test_cmp expect.$1 output.$1
19- "
18+ git rev-list --pretty=format:'$2 ' master >output.$1 &&
19+ test_cmp expect.$1 output.$1
20+ "
21+ }
22+
23+ # Feed to --format to provide predictable colored sequences.
24+ AUTO_COLOR=' %C(auto,red)foo%C(auto,reset)'
25+ has_color () {
26+ printf ' \033[31mfoo\033[m\n' > expect &&
27+ test_cmp expect " $1 "
28+ }
29+
30+ has_no_color () {
31+ echo foo > expect &&
32+ test_cmp expect " $1 "
2033}
2134
2235test_format percent %%h << 'EOF '
@@ -124,6 +137,48 @@ commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
124137[1;31;43mfoo[m
125138EOF
126139
140+ test_expect_success ' %C(auto) does not enable color by default' '
141+ git log --format=$AUTO_COLOR -1 >actual &&
142+ has_no_color actual
143+ '
144+
145+ test_expect_success ' %C(auto) enables colors for color.diff' '
146+ git -c color.diff=always log --format=$AUTO_COLOR -1 >actual &&
147+ has_color actual
148+ '
149+
150+ test_expect_success ' %C(auto) enables colors for color.ui' '
151+ git -c color.ui=always log --format=$AUTO_COLOR -1 >actual &&
152+ has_color actual
153+ '
154+
155+ test_expect_success ' %C(auto) respects --color' '
156+ git log --format=$AUTO_COLOR -1 --color >actual &&
157+ has_color actual
158+ '
159+
160+ test_expect_success ' %C(auto) respects --no-color' '
161+ git -c color.ui=always log --format=$AUTO_COLOR -1 --no-color >actual &&
162+ has_no_color actual
163+ '
164+
165+ test_expect_success TTY ' %C(auto) respects --color=auto (stdout is tty)' '
166+ (
167+ TERM=vt100 && export TERM &&
168+ test_terminal \
169+ git log --format=$AUTO_COLOR -1 --color=auto >actual &&
170+ has_color actual
171+ )
172+ '
173+
174+ test_expect_success ' %C(auto) respects --color=auto (stdout not tty)' '
175+ (
176+ TERM=vt100 && export TERM &&
177+ git log --format=$AUTO_COLOR -1 --color=auto >actual &&
178+ has_no_color actual
179+ )
180+ '
181+
127182cat > commit-msg << 'EOF '
128183Test printing of complex bodies
129184
0 commit comments