]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4011-diff-symlink.sh
t4011: illustrate "diff-index -p" on stat-dirty paths
[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
5597e84b 12test_expect_success SYMLINKS '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
JH
29 EOF
30 ln -s xyzzy frotz &&
5597e84b 31 echo xyzzy >nitfol &&
13a48998
JH
32 git update-index &&
33 tree=$(git write-tree) &&
5597e84b 34 git update-index --add frotz nitfol &&
13a48998
JH
35 GIT_DIFF_OPTS=--unified=0 git diff-index -M -p $tree >current &&
36 compare_diff_patch expected current
37'
975b31dc 38
5597e84b 39test_expect_success SYMLINKS 'diff unchanged symlink and file' '
13a48998 40 tree=$(git write-tree) &&
5597e84b 41 git update-index frotz nitfol &&
13a48998
JH
42 test -z "$(git diff-index --name-only $tree)"
43'
975b31dc 44
5597e84b 45test_expect_success SYMLINKS 'diff removed symlink and file' '
13a48998
JH
46 cat >expected <<-\EOF &&
47 diff --git a/frotz b/frotz
48 deleted file mode 120000
49 index 7c465af..0000000
50 --- a/frotz
51 +++ /dev/null
52 @@ -1 +0,0 @@
53 -xyzzy
54 \ No newline at end of file
5597e84b
JH
55 diff --git a/nitfol b/nitfol
56 deleted file mode 100644
57 index 7c465af..0000000
58 --- a/nitfol
59 +++ /dev/null
60 @@ -1 +0,0 @@
61 -xyzzy
13a48998
JH
62 EOF
63 mv frotz frotz2 &&
5597e84b 64 mv nitfol nitfol2 &&
13a48998
JH
65 git diff-index -M -p $tree >current &&
66 compare_diff_patch expected current
67'
975b31dc 68
5597e84b 69test_expect_success SYMLINKS 'diff identical, but newly created symlink and file' '
13a48998
JH
70 cat >expected <<-\EOF &&
71 diff --git a/frotz b/frotz
5597e84b 72 diff --git a/nitfol b/nitfol
13a48998 73 EOF
5597e84b
JH
74 rm -f frotz nitfol &&
75 echo xyzzy >nitfol &&
76 test-chmtime +10 nitfol &&
13a48998
JH
77 ln -s xyzzy frotz &&
78 git diff-index -M -p $tree >current &&
5597e84b
JH
79 compare_diff_patch expected current &&
80
81 >expected &&
82 git diff-index -M -p -w $tree >current &&
13a48998
JH
83 compare_diff_patch expected current
84'
975b31dc 85
5597e84b 86test_expect_success SYMLINKS 'diff different symlink and file' '
13a48998
JH
87 cat >expected <<-\EOF &&
88 diff --git a/frotz b/frotz
89 index 7c465af..df1db54 120000
90 --- a/frotz
91 +++ b/frotz
92 @@ -1 +1 @@
93 -xyzzy
94 \ No newline at end of file
95 +yxyyz
96 \ No newline at end of file
5597e84b
JH
97 diff --git a/nitfol b/nitfol
98 index 7c465af..df1db54 100644
99 --- a/nitfol
100 +++ b/nitfol
101 @@ -1 +1 @@
102 -xyzzy
103 +yxyyz
13a48998
JH
104 EOF
105 rm -f frotz &&
106 ln -s yxyyz frotz &&
5597e84b 107 echo yxyyz >nitfol &&
13a48998
JH
108 git diff-index -M -p $tree >current &&
109 compare_diff_patch expected current
110'
975b31dc 111
13a48998
JH
112test_expect_success SYMLINKS 'diff symlinks with non-existing targets' '
113 ln -s narf pinky &&
114 ln -s take\ over brain &&
115 test_must_fail git diff --no-index pinky brain >output 2>output.err &&
116 grep narf output &&
117 ! test -s output.err
118'
d391c0ff
JK
119
120test_expect_success SYMLINKS 'setup symlinks with attributes' '
121 echo "*.bin diff=bin" >>.gitattributes &&
122 echo content >file.bin &&
123 ln -s file.bin link.bin &&
124 git add -N file.bin link.bin
125'
126
d391c0ff 127test_expect_success SYMLINKS 'symlinks do not respect userdiff config by path' '
13a48998
JH
128 cat >expect <<-\EOF &&
129 diff --git a/file.bin b/file.bin
130 index e69de29..d95f3ad 100644
131 Binary files a/file.bin and b/file.bin differ
132 diff --git a/link.bin b/link.bin
133 index e69de29..dce41ec 120000
134 --- a/link.bin
135 +++ b/link.bin
136 @@ -0,0 +1 @@
137 +file.bin
138 \ No newline at end of file
139 EOF
d391c0ff
JK
140 git config diff.bin.binary true &&
141 git diff file.bin link.bin >actual &&
142 test_cmp expect actual
143'
144
975b31dc 145test_done