blob: 13e7f621ab79f95cc7c3057d9de5710813049102 [file] [log] [blame]
Johannes Schindelin975b31d2005-12-26 22:31:42 +01001#!/bin/sh
2#
3# Copyright (c) 2005 Johannes Schindelin
4#
5
6test_description='Test diff of symlinks.
7
8'
9. ./test-lib.sh
Junio C Hamanobfdbee92008-08-08 02:26:28 -070010. "$TEST_DIRECTORY"/diff-lib.sh
Johannes Schindelin975b31d2005-12-26 22:31:42 +010011
Johannes Sixt70836a62013-06-07 22:53:34 +020012test_expect_success 'diff new symlink and file' '
Junio C Hamano13a48992012-02-29 18:14:14 -080013 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
Junio C Hamano5597e842012-02-29 18:14:15 -080022 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
Junio C Hamano13a48992012-02-29 18:14:14 -080029 EOF
Johannes Sixt70836a62013-06-07 22:53:34 +020030
31 # the empty tree
Junio C Hamano13a48992012-02-29 18:14:14 -080032 git update-index &&
33 tree=$(git write-tree) &&
Johannes Sixt70836a62013-06-07 22:53:34 +020034
35 test_ln_s_add xyzzy frotz &&
36 echo xyzzy >nitfol &&
37 git update-index --add nitfol &&
Junio C Hamano13a48992012-02-29 18:14:14 -080038 GIT_DIFF_OPTS=--unified=0 git diff-index -M -p $tree >current &&
39 compare_diff_patch expected current
40'
Johannes Schindelin975b31d2005-12-26 22:31:42 +010041
Johannes Sixt70836a62013-06-07 22:53:34 +020042test_expect_success 'diff unchanged symlink and file' '
Junio C Hamano13a48992012-02-29 18:14:14 -080043 tree=$(git write-tree) &&
Junio C Hamano5597e842012-02-29 18:14:15 -080044 git update-index frotz nitfol &&
Junio C Hamano13a48992012-02-29 18:14:14 -080045 test -z "$(git diff-index --name-only $tree)"
46'
Johannes Schindelin975b31d2005-12-26 22:31:42 +010047
Johannes Sixt70836a62013-06-07 22:53:34 +020048test_expect_success 'diff removed symlink and file' '
Junio C Hamano13a48992012-02-29 18:14:14 -080049 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
Junio C Hamano5597e842012-02-29 18:14:15 -080058 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
Junio C Hamano13a48992012-02-29 18:14:14 -080065 EOF
66 mv frotz frotz2 &&
Junio C Hamano5597e842012-02-29 18:14:15 -080067 mv nitfol nitfol2 &&
Junio C Hamano13a48992012-02-29 18:14:14 -080068 git diff-index -M -p $tree >current &&
69 compare_diff_patch expected current
70'
Johannes Schindelin975b31d2005-12-26 22:31:42 +010071
Johannes Sixt70836a62013-06-07 22:53:34 +020072test_expect_success 'diff identical, but newly created symlink and file' '
Junio C Hamanob3f01ff2012-02-29 18:14:16 -080073 >expected &&
Junio C Hamano5597e842012-02-29 18:14:15 -080074 rm -f frotz nitfol &&
75 echo xyzzy >nitfol &&
76 test-chmtime +10 nitfol &&
Johannes Sixt70836a62013-06-07 22:53:34 +020077 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 &&
Junio C Hamano13a48992012-02-29 18:14:14 -080084 git diff-index -M -p $tree >current &&
Junio C Hamano5597e842012-02-29 18:14:15 -080085 compare_diff_patch expected current &&
86
87 >expected &&
88 git diff-index -M -p -w $tree >current &&
Junio C Hamano13a48992012-02-29 18:14:14 -080089 compare_diff_patch expected current
90'
Johannes Schindelin975b31d2005-12-26 22:31:42 +010091
Johannes Sixt70836a62013-06-07 22:53:34 +020092test_expect_success 'diff different symlink and file' '
Junio C Hamano13a48992012-02-29 18:14:14 -080093 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
Junio C Hamano5597e842012-02-29 18:14:15 -0800103 diff --git a/nitfol b/nitfol
104 index 7c465af..df1db54 100644
105 --- a/nitfol
106 +++ b/nitfol
107 @@ -1 +1 @@
108 -xyzzy
109 +yxyyz
Junio C Hamano13a48992012-02-29 18:14:14 -0800110 EOF
111 rm -f frotz &&
Johannes Sixt70836a62013-06-07 22:53:34 +0200112 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 &&
Junio C Hamano5597e842012-02-29 18:14:15 -0800119 echo yxyyz >nitfol &&
Junio C Hamano13a48992012-02-29 18:14:14 -0800120 git diff-index -M -p $tree >current &&
121 compare_diff_patch expected current
122'
Johannes Schindelin975b31d2005-12-26 22:31:42 +0100123
Junio C Hamano13a48992012-02-29 18:14:14 -0800124test_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
130'
Jeff Kingd391c0f2010-09-21 17:01:24 -0400131
132test_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
Jeff Kingd391c0f2010-09-21 17:01:24 -0400139test_expect_success SYMLINKS 'symlinks do not respect userdiff config by path' '
Junio C Hamano13a48992012-02-29 18:14:14 -0800140 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
151 EOF
Jeff Kingd391c0f2010-09-21 17:01:24 -0400152 git config diff.bin.binary true &&
153 git diff file.bin link.bin >actual &&
154 test_cmp expect actual
155'
156
Johannes Schindelin975b31d2005-12-26 22:31:42 +0100157test_done