pack-objects: simplify --filter handling
[git/debian.git] / t / t4020-diff-external.sh
blobc1ac09ecc7140a3dcfcdf906bb4533ba131881de
1 #!/bin/sh
3 test_description='external diff interface test'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 test_expect_success setup '
10 test_tick &&
11 echo initial >file &&
12 git add file &&
13 git commit -m initial &&
15 test_tick &&
16 echo second >file &&
17 before=$(git hash-object file) &&
18 before=$(git rev-parse --short $before) &&
19 git add file &&
20 git commit -m second &&
22 test_tick &&
23 echo third >file
26 test_expect_success 'GIT_EXTERNAL_DIFF environment' '
27 cat >expect <<-EOF &&
28 file $(git rev-parse --verify HEAD:file) 100644 file $(test_oid zero) 100644
29 EOF
30 GIT_EXTERNAL_DIFF=echo git diff >out &&
31 cut -d" " -f1,3- <out >actual &&
32 test_cmp expect actual
36 test_expect_success 'GIT_EXTERNAL_DIFF environment should apply only to diff' '
37 GIT_EXTERNAL_DIFF=echo git log -p -1 HEAD >out &&
38 grep "^diff --git a/file b/file" out
42 test_expect_success 'GIT_EXTERNAL_DIFF environment and --no-ext-diff' '
43 GIT_EXTERNAL_DIFF=echo git diff --no-ext-diff >out &&
44 grep "^diff --git a/file b/file" out
48 test_expect_success SYMLINKS 'typechange diff' '
49 rm -f file &&
50 ln -s elif file &&
52 cat >expect <<-EOF &&
53 file $(git rev-parse --verify HEAD:file) 100644 $(test_oid zero) 120000
54 EOF
55 GIT_EXTERNAL_DIFF=echo git diff >out &&
56 cut -d" " -f1,3-4,6- <out >actual &&
57 test_cmp expect actual &&
59 GIT_EXTERNAL_DIFF=echo git diff --no-ext-diff >actual &&
60 git diff >expect &&
61 test_cmp expect actual
64 test_expect_success 'diff.external' '
65 git reset --hard &&
66 echo third >file &&
67 test_config diff.external echo &&
69 cat >expect <<-EOF &&
70 file $(git rev-parse --verify HEAD:file) 100644 $(test_oid zero) 100644
71 EOF
72 git diff >out &&
73 cut -d" " -f1,3-4,6- <out >actual &&
74 test_cmp expect actual
77 test_expect_success 'diff.external should apply only to diff' '
78 test_config diff.external echo &&
79 git log -p -1 HEAD >out &&
80 grep "^diff --git a/file b/file" out
83 test_expect_success 'diff.external and --no-ext-diff' '
84 test_config diff.external echo &&
85 git diff --no-ext-diff >out &&
86 grep "^diff --git a/file b/file" out
89 test_expect_success 'diff attribute' '
90 git reset --hard &&
91 echo third >file &&
93 git config diff.parrot.command echo &&
95 echo >.gitattributes "file diff=parrot" &&
97 cat >expect <<-EOF &&
98 file $(git rev-parse --verify HEAD:file) 100644 $(test_oid zero) 100644
99 EOF
100 git diff >out &&
101 cut -d" " -f1,3-4,6- <out >actual &&
102 test_cmp expect actual
105 test_expect_success !SANITIZE_LEAK 'diff attribute should apply only to diff' '
106 git log -p -1 HEAD >out &&
107 grep "^diff --git a/file b/file" out
111 test_expect_success 'diff attribute and --no-ext-diff' '
112 git diff --no-ext-diff >out &&
113 grep "^diff --git a/file b/file" out
117 test_expect_success 'diff attribute' '
119 git config --unset diff.parrot.command &&
120 git config diff.color.command echo &&
122 echo >.gitattributes "file diff=color" &&
124 cat >expect <<-EOF &&
125 file $(git rev-parse --verify HEAD:file) 100644 $(test_oid zero) 100644
127 git diff >out &&
128 cut -d" " -f1,3-4,6- <out >actual &&
129 test_cmp expect actual
132 test_expect_success !SANITIZE_LEAK 'diff attribute should apply only to diff' '
133 git log -p -1 HEAD >out &&
134 grep "^diff --git a/file b/file" out
138 test_expect_success 'diff attribute and --no-ext-diff' '
139 git diff --no-ext-diff >out &&
140 grep "^diff --git a/file b/file" out
144 test_expect_success 'GIT_EXTERNAL_DIFF trumps diff.external' '
145 >.gitattributes &&
146 test_config diff.external "echo ext-global" &&
148 cat >expect <<-EOF &&
149 ext-env file $(git rev-parse --verify HEAD:file) 100644 file $(test_oid zero) 100644
151 GIT_EXTERNAL_DIFF="echo ext-env" git diff >out &&
152 cut -d" " -f1-2,4- <out >actual &&
153 test_cmp expect actual
156 test_expect_success 'attributes trump GIT_EXTERNAL_DIFF and diff.external' '
157 test_config diff.foo.command "echo ext-attribute" &&
158 test_config diff.external "echo ext-global" &&
159 echo "file diff=foo" >.gitattributes &&
161 cat >expect <<-EOF &&
162 ext-attribute file $(git rev-parse --verify HEAD:file) 100644 file $(test_oid zero) 100644
164 GIT_EXTERNAL_DIFF="echo ext-env" git diff >out &&
165 cut -d" " -f1-2,4- <out >actual &&
166 test_cmp expect actual
169 test_expect_success 'no diff with -diff' '
170 echo >.gitattributes "file -diff" &&
171 git diff >out &&
172 grep Binary out
175 echo NULZbetweenZwords | perl -pe 'y/Z/\000/' > file
177 test_expect_success 'force diff with "diff"' '
178 after=$(git hash-object file) &&
179 after=$(git rev-parse --short $after) &&
180 echo >.gitattributes "file diff" &&
181 git diff >actual &&
182 sed -e "s/^index .*/index $before..$after 100644/" \
183 "$TEST_DIRECTORY"/t4020/diff.NUL >expected-diff &&
184 test_cmp expected-diff actual
187 test_expect_success 'GIT_EXTERNAL_DIFF with more than one changed files' '
188 echo anotherfile > file2 &&
189 git add file2 &&
190 git commit -m "added 2nd file" &&
191 echo modified >file2 &&
192 GIT_EXTERNAL_DIFF=echo git diff
195 test_expect_success 'GIT_EXTERNAL_DIFF path counter/total' '
196 write_script external-diff.sh <<-\EOF &&
197 echo $GIT_DIFF_PATH_COUNTER of $GIT_DIFF_PATH_TOTAL >>counter.txt
199 >counter.txt &&
200 cat >expect <<-\EOF &&
201 1 of 2
202 2 of 2
204 GIT_EXTERNAL_DIFF=./external-diff.sh git diff &&
205 test_cmp expect counter.txt
208 test_expect_success 'GIT_EXTERNAL_DIFF generates pretty paths' '
209 test_when_finished "git rm -f file.ext" &&
210 touch file.ext &&
211 git add file.ext &&
212 echo with extension > file.ext &&
214 cat >expect <<-EOF &&
215 file.ext
217 GIT_EXTERNAL_DIFF=echo git diff file.ext >out &&
218 basename $(cut -d" " -f2 <out) >actual &&
219 test_cmp expect actual
222 echo "#!$SHELL_PATH" >fake-diff.sh
223 cat >> fake-diff.sh <<\EOF
224 cat $2 >> crlfed.txt
226 chmod a+x fake-diff.sh
228 keep_only_cr () {
229 tr -dc '\015'
232 test_expect_success 'external diff with autocrlf = true' '
233 test_config core.autocrlf true &&
234 GIT_EXTERNAL_DIFF=./fake-diff.sh git diff &&
235 test $(wc -l < crlfed.txt) = $(cat crlfed.txt | keep_only_cr | wc -c)
238 test_expect_success 'diff --cached' '
239 test_config core.autocrlf true &&
240 git add file &&
241 git update-index --assume-unchanged file &&
242 echo second >file &&
243 git diff --cached >actual &&
244 test_cmp expected-diff actual
247 test_expect_success 'clean up crlf leftovers' '
248 git update-index --no-assume-unchanged file &&
249 rm -f file* &&
250 git reset --hard
253 test_expect_success 'submodule diff' '
254 git init sub &&
255 ( cd sub && test_commit sub1 ) &&
256 git add sub &&
257 test_tick &&
258 git commit -m "add submodule" &&
259 ( cd sub && test_commit sub2 ) &&
260 write_script gather_pre_post.sh <<-\EOF &&
261 echo "$1 $4" # path, mode
262 cat "$2" # old file
263 cat "$5" # new file
265 GIT_EXTERNAL_DIFF=./gather_pre_post.sh git diff >actual &&
266 cat >expected <<-EOF &&
267 sub 160000
268 Subproject commit $(git rev-parse HEAD:sub)
269 Subproject commit $(cd sub && git rev-parse HEAD)
271 test_cmp expected actual
274 test_done