Skip to content

Commit da80635

Browse files
peffgitster
authored andcommitted
diff: move diff.wsErrorHighlight to "basic" config
We parse diff.wsErrorHighlight in git_diff_ui_config(), meaning that it doesn't take effect for plumbing commands, only for porcelains like git-diff itself. This is mildly annoying as it means scripts like add--interactive, which produce a user-visible diff with color, don't respect the option. We could teach that script to parse the config and pass it along as --ws-error-highlight to the diff plumbing. But there's a simpler solution. It should be reasonably safe for plumbing to respect this option, as it only kicks in when color is otherwise enabled. And anybody parsing colorized output must already deal with the fact that color.diff.* may change the exact output they see; those options have been part of git_diff_basic_config() since its inception in 9a1805a (add a "basic" diff config callback, 2008-01-04). So we can just move it to the "basic" config, which fixes add--interactive, along with any other script in the same boat, with a very low risk of hurting any plumbing users. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d0654dc commit da80635

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

diff.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -414,14 +414,6 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)
414414
return 0;
415415
}
416416

417-
if (!strcmp(var, "diff.wserrorhighlight")) {
418-
int val = parse_ws_error_highlight(value);
419-
if (val < 0)
420-
return -1;
421-
ws_error_highlight_default = val;
422-
return 0;
423-
}
424-
425417
if (git_color_config(var, value, cb) < 0)
426418
return -1;
427419

@@ -450,6 +442,14 @@ int git_diff_basic_config(const char *var, const char *value, void *cb)
450442
return color_parse(value, diff_colors[slot]);
451443
}
452444

445+
if (!strcmp(var, "diff.wserrorhighlight")) {
446+
int val = parse_ws_error_highlight(value);
447+
if (val < 0)
448+
return -1;
449+
ws_error_highlight_default = val;
450+
return 0;
451+
}
452+
453453
/* like GNU diff's --suppress-blank-empty option */
454454
if (!strcmp(var, "diff.suppressblankempty") ||
455455
/* for backwards compatibility */

t/t3701-add-interactive.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,19 @@ test_expect_success 'diffs can be colorized' '
544544
grep "$(printf "\\033")" output
545545
'
546546

547+
test_expect_success 'colorized diffs respect diff.wsErrorHighlight' '
548+
git reset --hard &&
549+
550+
echo "old " >test &&
551+
git add test &&
552+
echo "new " >test &&
553+
554+
printf y >y &&
555+
force_color git -c diff.wsErrorHighlight=all add -p >output.raw 2>&1 <y &&
556+
test_decode_color <output.raw >output &&
557+
grep "old<" output
558+
'
559+
547560
test_expect_success 'diffFilter filters diff' '
548561
git reset --hard &&
549562

0 commit comments

Comments
 (0)