unpack-trees: resolve sparse-directory/file conflicts
[git/debian.git] / t / t4011-diff-symlink.sh
blob5a25c259fe333912ba1614c2e645e03e5bdd6e02
1 #!/bin/sh
3 # Copyright (c) 2005 Johannes Schindelin
6 test_description='Test diff of symlinks.
9 . ./test-lib.sh
10 . "$TEST_DIRECTORY"/lib-diff.sh
12 # Print the short OID of a symlink with the given name.
13 symlink_oid () {
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.
19 short_oid () {
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
28 new file mode 120000
29 index 0000000..$symlink
30 --- /dev/null
31 +++ b/frotz
32 @@ -0,0 +1 @@
33 +xyzzy
34 \ No newline at end of file
35 diff --git a/nitfol b/nitfol
36 new file mode 100644
37 index 0000000..$symlink
38 --- /dev/null
39 +++ b/nitfol
40 @@ -0,0 +1 @@
41 +xyzzy
42 EOF
44 # the empty tree
45 git update-index &&
46 tree=$(git write-tree) &&
48 test_ln_s_add xyzzy frotz &&
49 echo xyzzy >nitfol &&
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
66 --- a/frotz
67 +++ /dev/null
68 @@ -1 +0,0 @@
69 -xyzzy
70 \ No newline at end of file
71 diff --git a/nitfol b/nitfol
72 deleted file mode 100644
73 index $symlink..0000000
74 --- a/nitfol
75 +++ /dev/null
76 @@ -1 +0,0 @@
77 -xyzzy
78 EOF
79 mv frotz frotz2 &&
80 mv nitfol nitfol2 &&
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' '
86 >expected &&
87 rm -f frotz nitfol &&
88 echo xyzzy >nitfol &&
89 test-tool chmtime +10 nitfol &&
90 if test_have_prereq SYMLINKS
91 then
92 ln -s xyzzy frotz
93 else
94 printf xyzzy >frotz
95 # the symlink property propagates from the index
96 fi &&
97 git diff-index -M -p $tree >current &&
98 compare_diff_patch expected current &&
100 >expected &&
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
110 --- a/frotz
111 +++ b/frotz
112 @@ -1 +1 @@
113 -xyzzy
114 \ No newline at end of file
115 +yxyyz
116 \ No newline at end of file
117 diff --git a/nitfol b/nitfol
118 index $symlink..$new 100644
119 --- a/nitfol
120 +++ b/nitfol
121 @@ -1 +1 @@
122 -xyzzy
123 +yxyyz
125 rm -f frotz &&
126 if test_have_prereq SYMLINKS
127 then
128 ln -s yxyyz frotz
129 else
130 printf yxyyz >frotz
131 # the symlink property propagates from the index
132 fi &&
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' '
139 ln -s narf pinky &&
140 ln -s take\ over brain &&
141 test_must_fail git diff --no-index pinky brain >output 2>output.err &&
142 grep narf output &&
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
158 new file mode 100644
159 index 0000000..$file
160 Binary files /dev/null and b/file.bin differ
161 diff --git a/link.bin b/link.bin
162 new file mode 120000
163 index 0000000..$link
164 --- /dev/null
165 +++ b/link.bin
166 @@ -0,0 +1 @@
167 +file.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
175 test_done