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
This commit is contained in:
Junio C Hamano
2025-09-23 11:53:40 -07:00
7 changed files with 148 additions and 40 deletions

View File

@@ -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

View File

@@ -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