3 # Copyright (c) 2005 Johannes Schindelin
6 test_description='Test diff of symlinks.
10 . "$TEST_DIRECTORY"/diff-lib.sh
12 # Print the short OID of a symlink with the given name.
14 local oid=$(printf "%s" "$1" | git hash-object --stdin) &&
15 git rev-parse --short "$oid"
18 # Print the short OID of the given file.
20 local oid=$(git hash-object "$1") &&
21 git rev-parse --short "$oid"
24 test_expect_success 'diff new symlink and file' '
25 symlink=$(symlink_oid xyzzy) &&
26 cat >expected <<-EOF &&
27 diff --git a/frotz b/frotz
29 index 0000000..$symlink
34 \ No newline at end of file
35 diff --git a/nitfol b/nitfol
37 index 0000000..$symlink
46 tree=$(git write-tree) &&
48 test_ln_s_add xyzzy frotz &&
50 git update-index --add nitfol &&
51 GIT_DIFF_OPTS=--unified=0 git diff-index -M -p $tree >current &&
52 compare_diff_patch expected current
55 test_expect_success 'diff unchanged symlink and file' '
56 tree=$(git write-tree) &&
57 git update-index frotz nitfol &&
58 test -z "$(git diff-index --name-only $tree)"
61 test_expect_success 'diff removed symlink and file' '
62 cat >expected <<-EOF &&
63 diff --git a/frotz b/frotz
64 deleted file mode 120000
65 index $symlink..0000000
70 \ No newline at end of file
71 diff --git a/nitfol b/nitfol
72 deleted file mode 100644
73 index $symlink..0000000
81 git diff-index -M -p $tree >current &&
82 compare_diff_patch expected current
85 test_expect_success 'diff identical, but newly created symlink and file' '
89 test-tool chmtime +10 nitfol &&
90 if test_have_prereq SYMLINKS
95 # the symlink property propagates from the index
97 git diff-index -M -p $tree >current &&
98 compare_diff_patch expected current &&
101 git diff-index -M -p -w $tree >current &&
102 compare_diff_patch expected current
105 test_expect_success 'diff different symlink and file' '
106 new=$(symlink_oid yxyyz) &&
107 cat >expected <<-EOF &&
108 diff --git a/frotz b/frotz
109 index $symlink..$new 120000
114 \ No newline at end of file
116 \ No newline at end of file
117 diff --git a/nitfol b/nitfol
118 index $symlink..$new 100644
126 if test_have_prereq SYMLINKS
131 # the symlink property propagates from the index
133 echo yxyyz >nitfol &&
134 git diff-index -M -p $tree >current &&
135 compare_diff_patch expected current
138 test_expect_success SYMLINKS 'diff symlinks with non-existing targets' '
140 ln -s take\ over brain &&
141 test_must_fail git diff --no-index pinky brain >output 2>output.err &&
143 test_must_be_empty output.err
146 test_expect_success SYMLINKS 'setup symlinks with attributes' '
147 echo "*.bin diff=bin" >>.gitattributes &&
148 echo content >file.bin &&
149 ln -s file.bin link.bin &&
150 git add -N file.bin link.bin
153 test_expect_success SYMLINKS 'symlinks do not respect userdiff config by path' '
154 file=$(short_oid file.bin) &&
155 link=$(symlink_oid file.bin) &&
156 cat >expect <<-EOF &&
157 diff --git a/file.bin b/file.bin
160 Binary files /dev/null and b/file.bin differ
161 diff --git a/link.bin b/link.bin
168 \ No newline at end of file
170 git config diff.bin.binary true &&
171 git diff file.bin link.bin >actual &&
172 test_cmp expect actual