]>
Commit | Line | Data |
---|---|---|
975b31dc JS |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2005 Johannes Schindelin | |
4 | # | |
5 | ||
6 | test_description='Test diff of symlinks. | |
7 | ||
8 | ' | |
9 | . ./test-lib.sh | |
bfdbee98 | 10 | . "$TEST_DIRECTORY"/diff-lib.sh |
975b31dc | 11 | |
70836a6f | 12 | test_expect_success 'diff new symlink and file' ' |
13a48998 JH |
13 | cat >expected <<-\EOF && |
14 | diff --git a/frotz b/frotz | |
15 | new file mode 120000 | |
16 | index 0000000..7c465af | |
17 | --- /dev/null | |
18 | +++ b/frotz | |
19 | @@ -0,0 +1 @@ | |
20 | +xyzzy | |
21 | \ No newline at end of file | |
5597e84b JH |
22 | diff --git a/nitfol b/nitfol |
23 | new file mode 100644 | |
24 | index 0000000..7c465af | |
25 | --- /dev/null | |
26 | +++ b/nitfol | |
27 | @@ -0,0 +1 @@ | |
28 | +xyzzy | |
13a48998 | 29 | EOF |
70836a6f JS |
30 | |
31 | # the empty tree | |
13a48998 JH |
32 | git update-index && |
33 | tree=$(git write-tree) && | |
70836a6f JS |
34 | |
35 | test_ln_s_add xyzzy frotz && | |
36 | echo xyzzy >nitfol && | |
37 | git update-index --add nitfol && | |
13a48998 JH |
38 | GIT_DIFF_OPTS=--unified=0 git diff-index -M -p $tree >current && |
39 | compare_diff_patch expected current | |
40 | ' | |
975b31dc | 41 | |
70836a6f | 42 | test_expect_success 'diff unchanged symlink and file' ' |
13a48998 | 43 | tree=$(git write-tree) && |
5597e84b | 44 | git update-index frotz nitfol && |
13a48998 JH |
45 | test -z "$(git diff-index --name-only $tree)" |
46 | ' | |
975b31dc | 47 | |
70836a6f | 48 | test_expect_success 'diff removed symlink and file' ' |
13a48998 JH |
49 | cat >expected <<-\EOF && |
50 | diff --git a/frotz b/frotz | |
51 | deleted file mode 120000 | |
52 | index 7c465af..0000000 | |
53 | --- a/frotz | |
54 | +++ /dev/null | |
55 | @@ -1 +0,0 @@ | |
56 | -xyzzy | |
57 | \ No newline at end of file | |
5597e84b JH |
58 | diff --git a/nitfol b/nitfol |
59 | deleted file mode 100644 | |
60 | index 7c465af..0000000 | |
61 | --- a/nitfol | |
62 | +++ /dev/null | |
63 | @@ -1 +0,0 @@ | |
64 | -xyzzy | |
13a48998 JH |
65 | EOF |
66 | mv frotz frotz2 && | |
5597e84b | 67 | mv nitfol nitfol2 && |
13a48998 JH |
68 | git diff-index -M -p $tree >current && |
69 | compare_diff_patch expected current | |
70 | ' | |
975b31dc | 71 | |
70836a6f | 72 | test_expect_success 'diff identical, but newly created symlink and file' ' |
b3f01ff2 | 73 | >expected && |
5597e84b JH |
74 | rm -f frotz nitfol && |
75 | echo xyzzy >nitfol && | |
0e496492 | 76 | test-tool chmtime +10 nitfol && |
70836a6f JS |
77 | if test_have_prereq SYMLINKS |
78 | then | |
79 | ln -s xyzzy frotz | |
80 | else | |
81 | printf xyzzy >frotz | |
82 | # the symlink property propagates from the index | |
83 | fi && | |
13a48998 | 84 | git diff-index -M -p $tree >current && |
5597e84b JH |
85 | compare_diff_patch expected current && |
86 | ||
87 | >expected && | |
88 | git diff-index -M -p -w $tree >current && | |
13a48998 JH |
89 | compare_diff_patch expected current |
90 | ' | |
975b31dc | 91 | |
70836a6f | 92 | test_expect_success 'diff different symlink and file' ' |
13a48998 JH |
93 | cat >expected <<-\EOF && |
94 | diff --git a/frotz b/frotz | |
95 | index 7c465af..df1db54 120000 | |
96 | --- a/frotz | |
97 | +++ b/frotz | |
98 | @@ -1 +1 @@ | |
99 | -xyzzy | |
100 | \ No newline at end of file | |
101 | +yxyyz | |
102 | \ No newline at end of file | |
5597e84b JH |
103 | diff --git a/nitfol b/nitfol |
104 | index 7c465af..df1db54 100644 | |
105 | --- a/nitfol | |
106 | +++ b/nitfol | |
107 | @@ -1 +1 @@ | |
108 | -xyzzy | |
109 | +yxyyz | |
13a48998 JH |
110 | EOF |
111 | rm -f frotz && | |
70836a6f JS |
112 | if test_have_prereq SYMLINKS |
113 | then | |
114 | ln -s yxyyz frotz | |
115 | else | |
116 | printf yxyyz >frotz | |
117 | # the symlink property propagates from the index | |
118 | fi && | |
5597e84b | 119 | echo yxyyz >nitfol && |
13a48998 JH |
120 | git diff-index -M -p $tree >current && |
121 | compare_diff_patch expected current | |
122 | ' | |
975b31dc | 123 | |
13a48998 JH |
124 | test_expect_success SYMLINKS 'diff symlinks with non-existing targets' ' |
125 | ln -s narf pinky && | |
126 | ln -s take\ over brain && | |
127 | test_must_fail git diff --no-index pinky brain >output 2>output.err && | |
128 | grep narf output && | |
ec10b018 | 129 | test_must_be_empty output.err |
13a48998 | 130 | ' |
d391c0ff JK |
131 | |
132 | test_expect_success SYMLINKS 'setup symlinks with attributes' ' | |
133 | echo "*.bin diff=bin" >>.gitattributes && | |
134 | echo content >file.bin && | |
135 | ln -s file.bin link.bin && | |
136 | git add -N file.bin link.bin | |
137 | ' | |
138 | ||
d391c0ff | 139 | test_expect_success SYMLINKS 'symlinks do not respect userdiff config by path' ' |
13a48998 JH |
140 | cat >expect <<-\EOF && |
141 | diff --git a/file.bin b/file.bin | |
0231ae71 NTND |
142 | new file mode 100644 |
143 | index 0000000..d95f3ad | |
144 | Binary files /dev/null and b/file.bin differ | |
13a48998 | 145 | diff --git a/link.bin b/link.bin |
0231ae71 NTND |
146 | new file mode 120000 |
147 | index 0000000..dce41ec | |
148 | --- /dev/null | |
13a48998 JH |
149 | +++ b/link.bin |
150 | @@ -0,0 +1 @@ | |
151 | +file.bin | |
152 | \ No newline at end of file | |
153 | EOF | |
d391c0ff JK |
154 | git config diff.bin.binary true && |
155 | git diff file.bin link.bin >actual && | |
156 | test_cmp expect actual | |
157 | ' | |
158 | ||
975b31dc | 159 | test_done |