23
test_cmp "$1.filtered" "$2.filtered"
24
}
25
26
+# This function uses a trick to manipulate the interactive add to use color:
27
+# the `want_color()` function special-cases the situation where a pager was
28
+# spawned and Git now wants to output colored text: to detect that situation,
29
+# the environment variable `GIT_PAGER_IN_USE` is set. However, color is
30
+# suppressed despite that environment variable if the `TERM` variable
31
+# indicates a dumb terminal, so we set that variable, too.
32
+
33
+force_color () {
34
+ env GIT_PAGER_IN_USE=true TERM=vt100 "$@"
35
+}
36
+
37
test_expect_success 'setup (initial)' '
38
echo content >file &&
39
git add file &&
462
diff_cmp expected diff
463
'
464
454
-test_expect_success TTY 'diffs can be colorized' '
465
+test_expect_success 'diffs can be colorized' '
466
git reset --hard &&
467
468
echo content >test &&
458
- printf y | test_terminal git add -p >output 2>&1 &&
469
+ printf y >y &&
470
+ force_color git add -p >output 2>&1 <y &&
471
472
# We do not want to depend on the exact coloring scheme
473
# git uses for diffs, so just check that we saw some kind of color.
474
grep "$(printf "\\033")" output
475
'
476
465
-test_expect_success TTY 'diffFilter filters diff' '
477
+test_expect_success 'diffFilter filters diff' '
478
git reset --hard &&
479
480
echo content >test &&
481
test_config interactive.diffFilter "sed s/^/foo:/" &&
470
- printf y | test_terminal git add -p >output 2>&1 &&
482
+ printf y >y &&
483
+ force_color git add -p >output 2>&1 <y &&
484
485
# avoid depending on the exact coloring or content of the prompts,
486
# and just make sure we saw our diff prefixed
487
grep foo:.*content output
488
'
489
477
-test_expect_success TTY 'detect bogus diffFilter output' '
490
+test_expect_success 'detect bogus diffFilter output' '
491
git reset --hard &&
492
493
echo content >test &&
494
test_config interactive.diffFilter "echo too-short" &&
482
- printf y | test_must_fail test_terminal git add -p
495
+ printf y >y &&
496
+ test_must_fail force_color git add -p <y
497
'
498
499
test_expect_success 'patch-mode via -i prompts for files' '
703
<BOLD;BLUE>What now<RESET>>$SP
704
Bye.
705
EOF
692
- test_write_lines h | GIT_PAGER_IN_USE=true TERM=vt100 git add -i >actual.colored &&
706
+ test_write_lines h | force_color git add -i >actual.colored &&
707
test_decode_color <actual.colored >actual &&
708
test_i18ncmp expect actual
709
'