]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4011-diff-symlink.sh
The sixth batch
[thirdparty/git.git] / t / t4011-diff-symlink.sh
CommitLineData
975b31dc
JS
1#!/bin/sh
2#
3# Copyright (c) 2005 Johannes Schindelin
4#
5
6test_description='Test diff of symlinks.
7
8'
9. ./test-lib.sh
bfdbee98 10. "$TEST_DIRECTORY"/diff-lib.sh
975b31dc 11
840624ff 12# Print the short OID of a symlink with the given name.
13symlink_oid () {
14 local oid=$(printf "%s" "$1" | git hash-object --stdin) &&
15 git rev-parse --short "$oid"
16}
17
18# Print the short OID of the given file.
19short_oid () {
20 local oid=$(git hash-object "$1") &&
21 git rev-parse --short "$oid"
22}
23
70836a6f 24test_expect_success 'diff new symlink and file' '
840624ff 25 symlink=$(symlink_oid xyzzy) &&
26 cat >expected <<-EOF &&
13a48998
JH
27 diff --git a/frotz b/frotz
28 new file mode 120000
840624ff 29 index 0000000..$symlink
13a48998
JH
30 --- /dev/null
31 +++ b/frotz
32 @@ -0,0 +1 @@
33 +xyzzy
34 \ No newline at end of file
5597e84b
JH
35 diff --git a/nitfol b/nitfol
36 new file mode 100644
840624ff 37 index 0000000..$symlink
5597e84b
JH
38 --- /dev/null
39 +++ b/nitfol
40 @@ -0,0 +1 @@
41 +xyzzy
13a48998 42 EOF
70836a6f
JS
43
44 # the empty tree
13a48998
JH
45 git update-index &&
46 tree=$(git write-tree) &&
70836a6f
JS
47
48 test_ln_s_add xyzzy frotz &&
49 echo xyzzy >nitfol &&
50 git update-index --add nitfol &&
13a48998
JH
51 GIT_DIFF_OPTS=--unified=0 git diff-index -M -p $tree >current &&
52 compare_diff_patch expected current
53'
975b31dc 54
70836a6f 55test_expect_success 'diff unchanged symlink and file' '
13a48998 56 tree=$(git write-tree) &&
5597e84b 57 git update-index frotz nitfol &&
13a48998
JH
58 test -z "$(git diff-index --name-only $tree)"
59'
975b31dc 60
70836a6f 61test_expect_success 'diff removed symlink and file' '
840624ff 62 cat >expected <<-EOF &&
13a48998
JH
63 diff --git a/frotz b/frotz
64 deleted file mode 120000
840624ff 65 index $symlink..0000000
13a48998
JH
66 --- a/frotz
67 +++ /dev/null
68 @@ -1 +0,0 @@
69 -xyzzy
70 \ No newline at end of file
5597e84b
JH
71 diff --git a/nitfol b/nitfol
72 deleted file mode 100644
840624ff 73 index $symlink..0000000
5597e84b
JH
74 --- a/nitfol
75 +++ /dev/null
76 @@ -1 +0,0 @@
77 -xyzzy
13a48998
JH
78 EOF
79 mv frotz frotz2 &&
5597e84b 80 mv nitfol nitfol2 &&
13a48998
JH
81 git diff-index -M -p $tree >current &&
82 compare_diff_patch expected current
83'
975b31dc 84
70836a6f 85test_expect_success 'diff identical, but newly created symlink and file' '
b3f01ff2 86 >expected &&
5597e84b
JH
87 rm -f frotz nitfol &&
88 echo xyzzy >nitfol &&
0e496492 89 test-tool chmtime +10 nitfol &&
70836a6f
JS
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 &&
13a48998 97 git diff-index -M -p $tree >current &&
5597e84b
JH
98 compare_diff_patch expected current &&
99
100 >expected &&
101 git diff-index -M -p -w $tree >current &&
13a48998
JH
102 compare_diff_patch expected current
103'
975b31dc 104
70836a6f 105test_expect_success 'diff different symlink and file' '
840624ff 106 new=$(symlink_oid yxyyz) &&
107 cat >expected <<-EOF &&
13a48998 108 diff --git a/frotz b/frotz
840624ff 109 index $symlink..$new 120000
13a48998
JH
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
5597e84b 117 diff --git a/nitfol b/nitfol
840624ff 118 index $symlink..$new 100644
5597e84b
JH
119 --- a/nitfol
120 +++ b/nitfol
121 @@ -1 +1 @@
122 -xyzzy
123 +yxyyz
13a48998
JH
124 EOF
125 rm -f frotz &&
70836a6f
JS
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 &&
5597e84b 133 echo yxyyz >nitfol &&
13a48998
JH
134 git diff-index -M -p $tree >current &&
135 compare_diff_patch expected current
136'
975b31dc 137
13a48998
JH
138test_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 &&
ec10b018 143 test_must_be_empty output.err
13a48998 144'
d391c0ff
JK
145
146test_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
151'
152
d391c0ff 153test_expect_success SYMLINKS 'symlinks do not respect userdiff config by path' '
840624ff 154 file=$(short_oid file.bin) &&
155 link=$(symlink_oid file.bin) &&
156 cat >expect <<-EOF &&
13a48998 157 diff --git a/file.bin b/file.bin
0231ae71 158 new file mode 100644
840624ff 159 index 0000000..$file
0231ae71 160 Binary files /dev/null and b/file.bin differ
13a48998 161 diff --git a/link.bin b/link.bin
0231ae71 162 new file mode 120000
840624ff 163 index 0000000..$link
0231ae71 164 --- /dev/null
13a48998
JH
165 +++ b/link.bin
166 @@ -0,0 +1 @@
167 +file.bin
168 \ No newline at end of file
169 EOF
d391c0ff
JK
170 git config diff.bin.binary true &&
171 git diff file.bin link.bin >actual &&
172 test_cmp expect actual
173'
174
975b31dc 175test_done