Merge branch 'js/xread-in-full'
[git/mingw.git] / t / t4011-diff-symlink.sh
blob13e7f621ab79f95cc7c3057d9de5710813049102
1 #!/bin/sh
3 # Copyright (c) 2005 Johannes Schindelin
6 test_description='Test diff of symlinks.
9 . ./test-lib.sh
10 . "$TEST_DIRECTORY"/diff-lib.sh
12 test_expect_success 'diff new symlink and file' '
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
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
29 EOF
31 # the empty tree
32 git update-index &&
33 tree=$(git write-tree) &&
35 test_ln_s_add xyzzy frotz &&
36 echo xyzzy >nitfol &&
37 git update-index --add nitfol &&
38 GIT_DIFF_OPTS=--unified=0 git diff-index -M -p $tree >current &&
39 compare_diff_patch expected current
42 test_expect_success 'diff unchanged symlink and file' '
43 tree=$(git write-tree) &&
44 git update-index frotz nitfol &&
45 test -z "$(git diff-index --name-only $tree)"
48 test_expect_success 'diff removed symlink and file' '
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
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
65 EOF
66 mv frotz frotz2 &&
67 mv nitfol nitfol2 &&
68 git diff-index -M -p $tree >current &&
69 compare_diff_patch expected current
72 test_expect_success 'diff identical, but newly created symlink and file' '
73 >expected &&
74 rm -f frotz nitfol &&
75 echo xyzzy >nitfol &&
76 test-chmtime +10 nitfol &&
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 &&
84 git diff-index -M -p $tree >current &&
85 compare_diff_patch expected current &&
87 >expected &&
88 git diff-index -M -p -w $tree >current &&
89 compare_diff_patch expected current
92 test_expect_success 'diff different symlink and file' '
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
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
111 rm -f frotz &&
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 &&
119 echo yxyyz >nitfol &&
120 git diff-index -M -p $tree >current &&
121 compare_diff_patch expected current
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 &&
129 ! test -s output.err
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
139 test_expect_success SYMLINKS 'symlinks do not respect userdiff config by path' '
140 cat >expect <<-\EOF &&
141 diff --git a/file.bin b/file.bin
142 index e69de29..d95f3ad 100644
143 Binary files a/file.bin and b/file.bin differ
144 diff --git a/link.bin b/link.bin
145 index e69de29..dce41ec 120000
146 --- a/link.bin
147 +++ b/link.bin
148 @@ -0,0 +1 @@
149 +file.bin
150 \ No newline at end of file
152 git config diff.bin.binary true &&
153 git diff file.bin link.bin >actual &&
154 test_cmp expect actual
157 test_done