Skip to content

Commit 6a2e93f

Browse files
committed
Merge branch 'jk/no-textconv-symlink'
* jk/no-textconv-symlink: diff: don't use pathname-based diff drivers for symlinks
2 parents fbfe5de + d391c0f commit 6a2e93f

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

diff.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,8 +1771,14 @@ static void emit_binary_diff(FILE *file, mmfile_t *one, mmfile_t *two, char *pre
17711771

17721772
static void diff_filespec_load_driver(struct diff_filespec *one)
17731773
{
1774-
if (!one->driver)
1774+
/* Use already-loaded driver */
1775+
if (one->driver)
1776+
return;
1777+
1778+
if (S_ISREG(one->mode))
17751779
one->driver = userdiff_find_by_path(one->path);
1780+
1781+
/* Fallback to default settings */
17761782
if (!one->driver)
17771783
one->driver = userdiff_find_by_name("default");
17781784
}
@@ -1820,8 +1826,7 @@ struct userdiff_driver *get_textconv(struct diff_filespec *one)
18201826
{
18211827
if (!DIFF_FILE_VALID(one))
18221828
return NULL;
1823-
if (!S_ISREG(one->mode))
1824-
return NULL;
1829+
18251830
diff_filespec_load_driver(one);
18261831
if (!one->driver->textconv)
18271832
return NULL;

t/t4011-diff-symlink.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,30 @@ test_expect_success SYMLINKS \
8888
test_must_fail git diff --no-index pinky brain > output 2> output.err &&
8989
grep narf output &&
9090
! grep error output.err'
91+
92+
test_expect_success SYMLINKS 'setup symlinks with attributes' '
93+
echo "*.bin diff=bin" >>.gitattributes &&
94+
echo content >file.bin &&
95+
ln -s file.bin link.bin &&
96+
git add -N file.bin link.bin
97+
'
98+
99+
cat >expect <<'EOF'
100+
diff --git a/file.bin b/file.bin
101+
index e69de29..d95f3ad 100644
102+
Binary files a/file.bin and b/file.bin differ
103+
diff --git a/link.bin b/link.bin
104+
index e69de29..dce41ec 120000
105+
--- a/link.bin
106+
+++ b/link.bin
107+
@@ -0,0 +1 @@
108+
+file.bin
109+
\ No newline at end of file
110+
EOF
111+
test_expect_success SYMLINKS 'symlinks do not respect userdiff config by path' '
112+
git config diff.bin.binary true &&
113+
git diff file.bin link.bin >actual &&
114+
test_cmp expect actual
115+
'
116+
91117
test_done

0 commit comments

Comments
 (0)