Code

t4011: modernise style
[git.git] / t / t4011-diff-symlink.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2005 Johannes Schindelin
4 #
6 test_description='Test diff of symlinks.
8 '
9 . ./test-lib.sh
10 . "$TEST_DIRECTORY"/diff-lib.sh
12 test_expect_success SYMLINKS 'diff new symlink' '
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         EOF
23         ln -s xyzzy frotz &&
24         git update-index &&
25         tree=$(git write-tree) &&
26         git update-index --add frotz &&
27         GIT_DIFF_OPTS=--unified=0 git diff-index -M -p $tree >current &&
28         compare_diff_patch expected current
29 '
31 test_expect_success SYMLINKS 'diff unchanged symlink'  '
32         tree=$(git write-tree) &&
33         git update-index frotz &&
34         test -z "$(git diff-index --name-only $tree)"
35 '
37 test_expect_success SYMLINKS 'diff removed symlink' '
38         cat >expected <<-\EOF &&
39         diff --git a/frotz b/frotz
40         deleted file mode 120000
41         index 7c465af..0000000
42         --- a/frotz
43         +++ /dev/null
44         @@ -1 +0,0 @@
45         -xyzzy
46         \ No newline at end of file
47         EOF
48         mv frotz frotz2 &&
49         git diff-index -M -p $tree >current &&
50         compare_diff_patch expected current
51 '
53 test_expect_success SYMLINKS 'diff identical, but newly created symlink' '
54         cat >expected <<-\EOF &&
55         diff --git a/frotz b/frotz
56         EOF
57         ln -s xyzzy frotz &&
58         git diff-index -M -p $tree >current &&
59         compare_diff_patch expected current
60 '
62 test_expect_success SYMLINKS 'diff different symlink' '
63         cat >expected <<-\EOF &&
64         diff --git a/frotz b/frotz
65         index 7c465af..df1db54 120000
66         --- a/frotz
67         +++ b/frotz
68         @@ -1 +1 @@
69         -xyzzy
70         \ No newline at end of file
71         +yxyyz
72         \ No newline at end of file
73         EOF
74         rm -f frotz &&
75         ln -s yxyyz frotz &&
76         git diff-index -M -p $tree >current &&
77         compare_diff_patch expected current
78 '
80 test_expect_success SYMLINKS 'diff symlinks with non-existing targets' '
81         ln -s narf pinky &&
82         ln -s take\ over brain &&
83         test_must_fail git diff --no-index pinky brain >output 2>output.err &&
84         grep narf output &&
85         ! test -s output.err
86 '
88 test_expect_success SYMLINKS 'setup symlinks with attributes' '
89         echo "*.bin diff=bin" >>.gitattributes &&
90         echo content >file.bin &&
91         ln -s file.bin link.bin &&
92         git add -N file.bin link.bin
93 '
95 test_expect_success SYMLINKS 'symlinks do not respect userdiff config by path' '
96         cat >expect <<-\EOF &&
97         diff --git a/file.bin b/file.bin
98         index e69de29..d95f3ad 100644
99         Binary files a/file.bin and b/file.bin differ
100         diff --git a/link.bin b/link.bin
101         index e69de29..dce41ec 120000
102         --- a/link.bin
103         +++ b/link.bin
104         @@ -0,0 +1 @@
105         +file.bin
106         \ No newline at end of file
107         EOF
108         git config diff.bin.binary true &&
109         git diff file.bin link.bin >actual &&
110         test_cmp expect actual
113 test_done