Skip to content

Commit 61af494

Browse files
committed
Teach "git diff" to honour --[no-]ext-diff
The original intention of 72909be (Add diff-option --ext-diff, 2007-06-30) was to optionally allow the use of external diff viewer in "git log" family (while keeping them disabled by default). It exposed the "allow external diff" bit to the UI, but forgot to adjust the "git diff" codepath that was set up to always allow use of the external diff viewer. Noticed by Nazri Ramliy; tests by René Scharfe squashed in. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 37a7744 commit 61af494

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

builtin-diff.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,9 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
290290
/* Otherwise, we are doing the usual "git" diff */
291291
rev.diffopt.skip_stat_unmatch = !!diff_auto_refresh_index;
292292

293+
/* Default to let external be used */
294+
DIFF_OPT_SET(&rev.diffopt, ALLOW_EXTERNAL);
295+
293296
if (nongit)
294297
die("Not a git repository");
295298
argc = setup_revisions(argc, argv, &rev, NULL);
@@ -298,7 +301,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
298301
if (diff_setup_done(&rev.diffopt) < 0)
299302
die("diff_setup_done failed");
300303
}
301-
DIFF_OPT_SET(&rev.diffopt, ALLOW_EXTERNAL);
304+
302305
DIFF_OPT_SET(&rev.diffopt, RECURSIVE);
303306

304307
/*

t/t4020-diff-external.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ test_expect_success 'GIT_EXTERNAL_DIFF environment should apply only to diff' '
4343
4444
'
4545

46+
test_expect_success 'GIT_EXTERNAL_DIFF environment and --no-ext-diff' '
47+
48+
GIT_EXTERNAL_DIFF=echo git diff --no-ext-diff |
49+
grep "^diff --git a/file b/file"
50+
51+
'
52+
4653
test_expect_success 'diff attribute' '
4754
4855
git config diff.parrot.command echo &&
@@ -68,6 +75,13 @@ test_expect_success 'diff attribute should apply only to diff' '
6875
6976
'
7077

78+
test_expect_success 'diff attribute and --no-ext-diff' '
79+
80+
git diff --no-ext-diff |
81+
grep "^diff --git a/file b/file"
82+
83+
'
84+
7185
test_expect_success 'diff attribute' '
7286
7387
git config --unset diff.parrot.command &&
@@ -94,6 +108,13 @@ test_expect_success 'diff attribute should apply only to diff' '
94108
95109
'
96110

111+
test_expect_success 'diff attribute and --no-ext-diff' '
112+
113+
git diff --no-ext-diff |
114+
grep "^diff --git a/file b/file"
115+
116+
'
117+
97118
test_expect_success 'no diff with -diff' '
98119
echo >.gitattributes "file -diff" &&
99120
git diff | grep Binary

0 commit comments

Comments
 (0)