]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4011-diff-symlink.sh
Sync with Git 2.45.1
[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'
16d4bd4f
ÆAB
9
10TEST_PASSES_SANITIZE_LEAK=true
975b31dc 11. ./test-lib.sh
ebd73f50 12. "$TEST_DIRECTORY"/lib-diff.sh
975b31dc 13
840624ff 14# Print the short OID of a symlink with the given name.
15symlink_oid () {
7f9f230b 16 local oid="$(printf "%s" "$1" | git hash-object --stdin)" &&
840624ff 17 git rev-parse --short "$oid"
18}
19
20# Print the short OID of the given file.
21short_oid () {
7f9f230b 22 local oid="$(git hash-object "$1")" &&
840624ff 23 git rev-parse --short "$oid"
24}
25
70836a6f 26test_expect_success 'diff new symlink and file' '
840624ff 27 symlink=$(symlink_oid xyzzy) &&
28 cat >expected <<-EOF &&
13a48998
JH
29 diff --git a/frotz b/frotz
30 new file mode 120000
840624ff 31 index 0000000..$symlink
13a48998
JH
32 --- /dev/null
33 +++ b/frotz
34 @@ -0,0 +1 @@
35 +xyzzy
36 \ No newline at end of file
5597e84b
JH
37 diff --git a/nitfol b/nitfol
38 new file mode 100644
840624ff 39 index 0000000..$symlink
5597e84b
JH
40 --- /dev/null
41 +++ b/nitfol
42 @@ -0,0 +1 @@
43 +xyzzy
13a48998 44 EOF
70836a6f
JS
45
46 # the empty tree
13a48998
JH
47 git update-index &&
48 tree=$(git write-tree) &&
70836a6f
JS
49
50 test_ln_s_add xyzzy frotz &&
51 echo xyzzy >nitfol &&
52 git update-index --add nitfol &&
13a48998
JH
53 GIT_DIFF_OPTS=--unified=0 git diff-index -M -p $tree >current &&
54 compare_diff_patch expected current
55'
975b31dc 56
70836a6f 57test_expect_success 'diff unchanged symlink and file' '
13a48998 58 tree=$(git write-tree) &&
5597e84b 59 git update-index frotz nitfol &&
13a48998
JH
60 test -z "$(git diff-index --name-only $tree)"
61'
975b31dc 62
70836a6f 63test_expect_success 'diff removed symlink and file' '
840624ff 64 cat >expected <<-EOF &&
13a48998
JH
65 diff --git a/frotz b/frotz
66 deleted file mode 120000
840624ff 67 index $symlink..0000000
13a48998
JH
68 --- a/frotz
69 +++ /dev/null
70 @@ -1 +0,0 @@
71 -xyzzy
72 \ No newline at end of file
5597e84b
JH
73 diff --git a/nitfol b/nitfol
74 deleted file mode 100644
840624ff 75 index $symlink..0000000
5597e84b
JH
76 --- a/nitfol
77 +++ /dev/null
78 @@ -1 +0,0 @@
79 -xyzzy
13a48998
JH
80 EOF
81 mv frotz frotz2 &&
5597e84b 82 mv nitfol nitfol2 &&
13a48998
JH
83 git diff-index -M -p $tree >current &&
84 compare_diff_patch expected current
85'
975b31dc 86
70836a6f 87test_expect_success 'diff identical, but newly created symlink and file' '
b3f01ff2 88 >expected &&
5597e84b
JH
89 rm -f frotz nitfol &&
90 echo xyzzy >nitfol &&
0e496492 91 test-tool chmtime +10 nitfol &&
70836a6f
JS
92 if test_have_prereq SYMLINKS
93 then
94 ln -s xyzzy frotz
95 else
96 printf xyzzy >frotz
97 # the symlink property propagates from the index
98 fi &&
13a48998 99 git diff-index -M -p $tree >current &&
5597e84b
JH
100 compare_diff_patch expected current &&
101
102 >expected &&
103 git diff-index -M -p -w $tree >current &&
13a48998
JH
104 compare_diff_patch expected current
105'
975b31dc 106
70836a6f 107test_expect_success 'diff different symlink and file' '
840624ff 108 new=$(symlink_oid yxyyz) &&
109 cat >expected <<-EOF &&
13a48998 110 diff --git a/frotz b/frotz
840624ff 111 index $symlink..$new 120000
13a48998
JH
112 --- a/frotz
113 +++ b/frotz
114 @@ -1 +1 @@
115 -xyzzy
116 \ No newline at end of file
117 +yxyyz
118 \ No newline at end of file
5597e84b 119 diff --git a/nitfol b/nitfol
840624ff 120 index $symlink..$new 100644
5597e84b
JH
121 --- a/nitfol
122 +++ b/nitfol
123 @@ -1 +1 @@
124 -xyzzy
125 +yxyyz
13a48998
JH
126 EOF
127 rm -f frotz &&
70836a6f
JS
128 if test_have_prereq SYMLINKS
129 then
130 ln -s yxyyz frotz
131 else
132 printf yxyyz >frotz
133 # the symlink property propagates from the index
134 fi &&
5597e84b 135 echo yxyyz >nitfol &&
13a48998
JH
136 git diff-index -M -p $tree >current &&
137 compare_diff_patch expected current
138'
975b31dc 139
13a48998
JH
140test_expect_success SYMLINKS 'diff symlinks with non-existing targets' '
141 ln -s narf pinky &&
142 ln -s take\ over brain &&
143 test_must_fail git diff --no-index pinky brain >output 2>output.err &&
144 grep narf output &&
ec10b018 145 test_must_be_empty output.err
13a48998 146'
d391c0ff
JK
147
148test_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
153'
154
d391c0ff 155test_expect_success SYMLINKS 'symlinks do not respect userdiff config by path' '
840624ff 156 file=$(short_oid file.bin) &&
157 link=$(symlink_oid file.bin) &&
158 cat >expect <<-EOF &&
13a48998 159 diff --git a/file.bin b/file.bin
0231ae71 160 new file mode 100644
840624ff 161 index 0000000..$file
0231ae71 162 Binary files /dev/null and b/file.bin differ
13a48998 163 diff --git a/link.bin b/link.bin
0231ae71 164 new file mode 120000
840624ff 165 index 0000000..$link
0231ae71 166 --- /dev/null
13a48998
JH
167 +++ b/link.bin
168 @@ -0,0 +1 @@
169 +file.bin
170 \ No newline at end of file
171 EOF
d391c0ff
JK
172 git config diff.bin.binary true &&
173 git diff file.bin link.bin >actual &&
174 test_cmp expect actual
175'
176
975b31dc 177test_done