Skip to content

Commit 70f6be7

Browse files
committed
Merge branch 'jv/maint-no-ext-diff' into maint
"git diff --no-ext-diff" did not output anything for a typechange filepair when GIT_EXTERNAL_DIFF is in effect. * jv/maint-no-ext-diff: diff: test precedence of external diff drivers diff: correctly disable external_diff with --no-ext-diff
2 parents 9b67f56 + c12f82a commit 70f6be7

File tree

2 files changed

+64
-3
lines changed

2 files changed

+64
-3
lines changed

diff.c

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

2995-
if (!DIFF_OPT_TST(o, ALLOW_EXTERNAL))
2996-
pgm = NULL;
2997-
else {
2995+
2996+
if (DIFF_OPT_TST(o, ALLOW_EXTERNAL)) {
29982997
struct userdiff_driver *drv = userdiff_find_by_path(attr_path);
29992998
if (drv && drv->external)
30002999
pgm = drv->external;
@@ -3074,6 +3073,9 @@ static void run_diff(struct diff_filepair *p, struct diff_options *o)
30743073
if (o->prefix_length)
30753074
strip_prefix(o->prefix_length, &name, &other);
30763075

3076+
if (!DIFF_OPT_TST(o, ALLOW_EXTERNAL))
3077+
pgm = NULL;
3078+
30773079
if (DIFF_PAIR_UNMERGED(p)) {
30783080
run_diff_cmd(pgm, name, NULL, attr_path,
30793081
NULL, NULL, NULL, o, p);

t/t4020-diff-external.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,53 @@ 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+
68+
test_expect_success 'diff.external' '
69+
git reset --hard &&
70+
echo third >file &&
71+
test_config diff.external echo &&
72+
git diff | {
73+
read path oldfile oldhex oldmode newfile newhex newmode &&
74+
test "z$path" = zfile &&
75+
test "z$oldmode" = z100644 &&
76+
test "z$newhex" = "z$_z40" &&
77+
test "z$newmode" = z100644 &&
78+
oh=$(git rev-parse --verify HEAD:file) &&
79+
test "z$oh" = "z$oldhex"
80+
}
81+
'
82+
83+
test_expect_success 'diff.external should apply only to diff' '
84+
test_config diff.external echo &&
85+
git log -p -1 HEAD |
86+
grep "^diff --git a/file b/file"
87+
'
88+
89+
test_expect_success 'diff.external and --no-ext-diff' '
90+
test_config diff.external echo &&
91+
git diff --no-ext-diff |
92+
grep "^diff --git a/file b/file"
93+
'
94+
5195
test_expect_success 'diff attribute' '
96+
git reset --hard &&
97+
echo third >file &&
5298
5399
git config diff.parrot.command echo &&
54100
@@ -113,6 +159,19 @@ test_expect_success 'diff attribute and --no-ext-diff' '
113159
114160
'
115161

162+
test_expect_success 'GIT_EXTERNAL_DIFF trumps diff.external' '
163+
>.gitattributes &&
164+
test_config diff.external "echo ext-global" &&
165+
GIT_EXTERNAL_DIFF="echo ext-env" git diff | grep ext-env
166+
'
167+
168+
test_expect_success 'attributes trump GIT_EXTERNAL_DIFF and diff.external' '
169+
test_config diff.foo.command "echo ext-attribute" &&
170+
test_config diff.external "echo ext-global" &&
171+
echo "file diff=foo" >.gitattributes &&
172+
GIT_EXTERNAL_DIFF="echo ext-env" git diff | grep ext-attribute
173+
'
174+
116175
test_expect_success 'no diff with -diff' '
117176
echo >.gitattributes "file -diff" &&
118177
git diff | grep Binary

0 commit comments

Comments
 (0)