3 # Copyright (c) 2005 Johannes Schindelin
6 test_description
='Test diff of symlinks.
10 TEST_PASSES_SANITIZE_LEAK
=true
12 .
"$TEST_DIRECTORY"/lib-diff.sh
14 # Print the short OID of a symlink with the given name.
16 local oid
=$
(printf "%s" "$1" | git hash-object
--stdin) &&
17 git rev-parse
--short "$oid"
20 # Print the short OID of the given file.
22 local oid
=$
(git hash-object
"$1") &&
23 git rev-parse
--short "$oid"
26 test_expect_success
'diff new symlink and file' '
27 symlink=$(symlink_oid xyzzy) &&
28 cat >expected <<-EOF &&
29 diff --git a/frotz b/frotz
31 index 0000000..$symlink
36 \ No newline at end of file
37 diff --git a/nitfol b/nitfol
39 index 0000000..$symlink
48 tree=$(git write-tree) &&
50 test_ln_s_add xyzzy frotz &&
52 git update-index --add nitfol &&
53 GIT_DIFF_OPTS=--unified=0 git diff-index -M -p $tree >current &&
54 compare_diff_patch expected current
57 test_expect_success
'diff unchanged symlink and file' '
58 tree=$(git write-tree) &&
59 git update-index frotz nitfol &&
60 test -z "$(git diff-index --name-only $tree)"
63 test_expect_success
'diff removed symlink and file' '
64 cat >expected <<-EOF &&
65 diff --git a/frotz b/frotz
66 deleted file mode 120000
67 index $symlink..0000000
72 \ No newline at end of file
73 diff --git a/nitfol b/nitfol
74 deleted file mode 100644
75 index $symlink..0000000
83 git diff-index -M -p $tree >current &&
84 compare_diff_patch expected current
87 test_expect_success
'diff identical, but newly created symlink and file' '
91 test-tool chmtime +10 nitfol &&
92 if test_have_prereq SYMLINKS
97 # the symlink property propagates from the index
99 git diff-index -M -p $tree >current &&
100 compare_diff_patch expected current &&
103 git diff-index -M -p -w $tree >current &&
104 compare_diff_patch expected current
107 test_expect_success
'diff different symlink and file' '
108 new=$(symlink_oid yxyyz) &&
109 cat >expected <<-EOF &&
110 diff --git a/frotz b/frotz
111 index $symlink..$new 120000
116 \ No newline at end of file
118 \ No newline at end of file
119 diff --git a/nitfol b/nitfol
120 index $symlink..$new 100644
128 if test_have_prereq SYMLINKS
133 # the symlink property propagates from the index
135 echo yxyyz >nitfol &&
136 git diff-index -M -p $tree >current &&
137 compare_diff_patch expected current
140 test_expect_success SYMLINKS
'diff symlinks with non-existing targets' '
142 ln -s take\ over brain &&
143 test_must_fail git diff --no-index pinky brain >output 2>output.err &&
145 test_must_be_empty output.err
148 test_expect_success SYMLINKS
'setup symlinks with attributes' '
149 echo "*.bin diff=bin" >>.gitattributes &&
150 echo content >file.bin &&
151 ln -s file.bin link.bin &&
152 git add -N file.bin link.bin
155 test_expect_success SYMLINKS
'symlinks do not respect userdiff config by path' '
156 file=$(short_oid file.bin) &&
157 link=$(symlink_oid file.bin) &&
158 cat >expect <<-EOF &&
159 diff --git a/file.bin b/file.bin
162 Binary files /dev/null and b/file.bin differ
163 diff --git a/link.bin b/link.bin
170 \ No newline at end of file
172 git config diff.bin.binary true &&
173 git diff file.bin link.bin >actual &&
174 test_cmp expect actual