59
}
60
61
# Feed to --format to provide predictable colored sequences.
62
+BASIC_COLOR='%Credfoo%Creset'
63
+COLOR='%C(red)foo%C(reset)'
64
AUTO_COLOR='%C(auto,red)foo%C(auto,reset)'
65
+ALWAYS_COLOR='%C(always,red)foo%C(always,reset)'
66
has_color () {
67
test_decode_color <"$1" >decoded &&
68
echo "<RED>foo<RESET>" >expect &&
180
<RED>foo<GREEN>bar<BLUE>baz<RESET>xyzzy
181
EOF
182
format="%Credfoo%Cgreenbar%Cbluebaz%Cresetxyzzy" &&
180
- git rev-list --format="$format" -1 master >actual.raw &&
183
+ git rev-list --color --format="$format" -1 master >actual.raw &&
184
test_decode_color <actual.raw >actual &&
185
test_cmp expect actual
186
'
191
<BOLD;RED;BYELLOW>foo<RESET>
192
EOF
193
format="%C(red yellow bold)foo%C(reset)" &&
191
- git rev-list --format="$format" -1 master >actual.raw &&
194
+ git rev-list --color --format="$format" -1 master >actual.raw &&
195
test_decode_color <actual.raw >actual &&
196
test_cmp expect actual
197
'
198
196
-test_expect_success '%C(auto,...) does not enable color by default' '
197
- git log --format=$AUTO_COLOR -1 >actual &&
198
- has_no_color actual
199
-'
200
-
201
-test_expect_success '%C(auto,...) enables colors for color.diff' '
202
- git -c color.diff=always log --format=$AUTO_COLOR -1 >actual &&
203
- has_color actual
204
-'
205
-
206
-test_expect_success '%C(auto,...) enables colors for color.ui' '
207
- git -c color.ui=always log --format=$AUTO_COLOR -1 >actual &&
208
- has_color actual
209
-'
199
+for spec in \
200
+ "%Cred:$BASIC_COLOR" \
201
+ "%C(...):$COLOR" \
202
+ "%C(auto,...):$AUTO_COLOR"
203
+do
204
+ desc=${spec%%:*}
205
+ color=${spec#*:}
206
+ test_expect_success "$desc does not enable color by default" '
207
+ git log --format=$color -1 >actual &&
208
+ has_no_color actual
209
+ '
210
211
-test_expect_success '%C(auto,...) respects --color' '
212
- git log --format=$AUTO_COLOR -1 --color >actual &&
213
- has_color actual
214
-'
211
+ test_expect_success "$desc enables colors for color.diff" '
212
+ git -c color.diff=always log --format=$color -1 >actual &&
213
+ has_color actual
214
+ '
215
216
-test_expect_success '%C(auto,...) respects --no-color' '
217
- git -c color.ui=always log --format=$AUTO_COLOR -1 --no-color >actual &&
218
- has_no_color actual
219
-'
216
+ test_expect_success "$desc enables colors for color.ui" '
217
+ git -c color.ui=always log --format=$color -1 >actual &&
218
+ has_color actual
219
+ '
220
221
-test_expect_success TTY '%C(auto,...) respects --color=auto (stdout is tty)' '
222
- test_terminal env TERM=vt100 \
223
- git log --format=$AUTO_COLOR -1 --color=auto >actual &&
224
- has_color actual
225
-'
221
+ test_expect_success "$desc respects --color" '
222
+ git log --format=$color -1 --color >actual &&
223
+ has_color actual
224
+ '
225
227
-test_expect_success '%C(auto,...) respects --color=auto (stdout not tty)' '
228
- (
229
- TERM=vt100 && export TERM &&
230
- git log --format=$AUTO_COLOR -1 --color=auto >actual &&
226
+ test_expect_success "$desc respects --no-color" '
227
+ git -c color.ui=always log --format=$color -1 --no-color >actual &&
228
has_no_color actual
232
- )
229
+ '
230
+
231
+ test_expect_success TTY "$desc respects --color=auto (stdout is tty)" '
232
+ test_terminal env TERM=vt100 \
233
+ git log --format=$color -1 --color=auto >actual &&
234
+ has_color actual
235
+ '
236
+
237
+ test_expect_success "$desc respects --color=auto (stdout not tty)" '
238
+ (
239
+ TERM=vt100 && export TERM &&
240
+ git log --format=$color -1 --color=auto >actual &&
241
+ has_no_color actual
242
+ )
243
+ '
244
+done
245
+
246
+test_expect_success '%C(always,...) enables color even without tty' '
247
+ git log --format=$ALWAYS_COLOR -1 >actual &&
248
+ has_color actual
249
'
250
251
test_expect_success '%C(auto) respects --color' '