summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2025-09-23 11:53:40 -0700
committerJunio C Hamano <gitster@pobox.com>2025-09-23 11:53:40 -0700
commit2e8d7569eae06a7e5052d08c2697b0f1281be9da (patch)
treea700bcbb594b7a791319c6a776d00fa93ca82abf /t
parent2be606a3bd1c916fcc14435556a807c6f5b5ce14 (diff)
parent1092cd6435642808c3e921f0c3c4a7588cc455e6 (diff)
Merge branch 'jk/add-i-color'
Some among "git add -p" and friends ignored color.diff and/or color.ui configuration variables, which is an old regression, which has been corrected. * jk/add-i-color: contrib/diff-highlight: mention interactive.diffFilter add-interactive: manually fall back color config to color.ui add-interactive: respect color.diff for diff coloring stash: pass --no-color to diff plumbing child processes
Diffstat (limited to 't')
-rwxr-xr-xt/t3701-add-interactive.sh53
-rwxr-xr-xt/t3904-stash-patch.sh19
2 files changed, 72 insertions, 0 deletions
diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
index 04d2a19835..d9fe289a7a 100755
--- a/t/t3701-add-interactive.sh
+++ b/t/t3701-add-interactive.sh
@@ -866,6 +866,44 @@ test_expect_success 'colorized diffs respect diff.wsErrorHighlight' '
test_grep "old<" output
'
+test_expect_success 'diff color respects color.diff' '
+ git reset --hard &&
+
+ echo old >test &&
+ git add test &&
+ echo new >test &&
+
+ printf n >n &&
+ force_color git \
+ -c color.interactive=auto \
+ -c color.interactive.prompt=blue \
+ -c color.diff=false \
+ -c color.diff.old=red \
+ add -p >output.raw 2>&1 <n &&
+ test_decode_color <output.raw >output &&
+ test_grep "BLUE.*Stage this hunk" output &&
+ test_grep ! "RED" output
+'
+
+test_expect_success 're-coloring diff without color.interactive' '
+ git reset --hard &&
+
+ test_write_lines 1 2 3 >test &&
+ git add test &&
+ test_write_lines one 2 three >test &&
+
+ test_write_lines s n n |
+ force_color git \
+ -c color.interactive=false \
+ -c color.interactive.prompt=blue \
+ -c color.diff=true \
+ -c color.diff.frag="bold magenta" \
+ add -p >output.raw 2>&1 &&
+ test_decode_color <output.raw >output &&
+ test_grep "<BOLD;MAGENTA>@@" output &&
+ test_grep ! "BLUE" output
+'
+
test_expect_success 'diffFilter filters diff' '
git reset --hard &&
@@ -1283,6 +1321,12 @@ test_expect_success 'stash accepts -U and --inter-hunk-context' '
test_grep "@@ -2,20 +2,20 @@" actual
'
+test_expect_success 'set up base for -p color tests' '
+ echo commit >file &&
+ git commit -am "commit state" &&
+ git tag patch-base
+'
+
for cmd in add checkout commit reset restore "stash save" "stash push"
do
test_expect_success "$cmd rejects invalid context options" '
@@ -1299,6 +1343,15 @@ do
test_must_fail git $cmd --inter-hunk-context 2 2>actual &&
test_grep -E ".--inter-hunk-context. requires .(--interactive/)?--patch." actual
'
+
+ test_expect_success "$cmd falls back to color.ui" '
+ git reset --hard patch-base &&
+ echo working-tree >file &&
+ test_write_lines y |
+ force_color git -c color.ui=false $cmd -p >output.raw 2>&1 &&
+ test_decode_color <output.raw >output &&
+ test_cmp output.raw output
+ '
done
test_done
diff --git a/t/t3904-stash-patch.sh b/t/t3904-stash-patch.sh
index ae313e3c70..90a4ff2c10 100755
--- a/t/t3904-stash-patch.sh
+++ b/t/t3904-stash-patch.sh
@@ -107,4 +107,23 @@ test_expect_success 'stash -p with split hunk' '
! grep "added line 2" test
'
+test_expect_success 'stash -p not confused by GIT_PAGER_IN_USE' '
+ echo to-stash >test &&
+ # Set both GIT_PAGER_IN_USE and TERM. Our goal is to entice any
+ # diff subprocesses into thinking that they could output
+ # color, even though their stdout is not going into a tty.
+ echo y |
+ GIT_PAGER_IN_USE=1 TERM=vt100 git stash -p &&
+ git diff --exit-code
+'
+
+test_expect_success 'index push not confused by GIT_PAGER_IN_USE' '
+ echo index >test &&
+ git add test &&
+ echo working-tree >test &&
+ # As above, we try to entice the child diff into using color.
+ GIT_PAGER_IN_USE=1 TERM=vt100 git stash push test &&
+ git diff --exit-code
+'
+
test_done