Skip to content

Commit bd8c1a9

Browse files
committed
diff: correctly disable external_diff with --no-ext-diff
Upon seeing a type-change filepair, "diff --no-ext-diff" does not show the usual "deletion followed by addition" split patch and does not run the external diff driver either. This is because the logic to disable external diff was placed at a wrong level in the callchain. run_diff_cmd() decides to show the split patch only when external diff driver is not configured or specified via GIT_EXTERNAL_DIFF environment, but this is done before checking if --no-ext-diff was given. To make things worse, run_diff_cmd() checks --no-ext-diff and disables the output for such a filepair completely, as the callchain below it (e.g. builtin_diff) does not want to handle typechange filepairs. Signed-off-by: Junio C Hamano <[email protected]>
1 parent d0f1ea6 commit bd8c1a9

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

diff.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2913,9 +2913,8 @@ static void run_diff_cmd(const char *pgm,
29132913
int complete_rewrite = (p->status == DIFF_STATUS_MODIFIED) && p->score;
29142914
int must_show_header = 0;
29152915

2916-
if (!DIFF_OPT_TST(o, ALLOW_EXTERNAL))
2917-
pgm = NULL;
2918-
else {
2916+
2917+
if (DIFF_OPT_TST(o, ALLOW_EXTERNAL)) {
29192918
struct userdiff_driver *drv = userdiff_find_by_path(attr_path);
29202919
if (drv && drv->external)
29212920
pgm = drv->external;
@@ -2995,6 +2994,9 @@ static void run_diff(struct diff_filepair *p, struct diff_options *o)
29952994
if (o->prefix_length)
29962995
strip_prefix(o->prefix_length, &name, &other);
29972996

2997+
if (!DIFF_OPT_TST(o, ALLOW_EXTERNAL))
2998+
pgm = NULL;
2999+
29983000
if (DIFF_PAIR_UNMERGED(p)) {
29993001
run_diff_cmd(pgm, name, NULL, attr_path,
30003002
NULL, NULL, NULL, o, p);

t/t4020-diff-external.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,26 @@ test_expect_success 'GIT_EXTERNAL_DIFF environment and --no-ext-diff' '
4848
4949
'
5050

51+
test_expect_success SYMLINKS 'typechange diff' '
52+
rm -f file &&
53+
ln -s elif file &&
54+
GIT_EXTERNAL_DIFF=echo git diff | {
55+
read path oldfile oldhex oldmode newfile newhex newmode &&
56+
test "z$path" = zfile &&
57+
test "z$oldmode" = z100644 &&
58+
test "z$newhex" = "z$_z40" &&
59+
test "z$newmode" = z120000 &&
60+
oh=$(git rev-parse --verify HEAD:file) &&
61+
test "z$oh" = "z$oldhex"
62+
} &&
63+
GIT_EXTERNAL_DIFF=echo git diff --no-ext-diff >actual &&
64+
git diff >expect &&
65+
test_cmp expect actual
66+
'
67+
5168
test_expect_success 'diff attribute' '
69+
git reset --hard &&
70+
echo third >file &&
5271
5372
git config diff.parrot.command echo &&
5473

0 commit comments

Comments
 (0)