status: document the -v/--verbose option
[alt-git.git] / t / t4020-diff-external.sh
blob044620186d135fe5caeb9376665305af1c8acbe5
1 #!/bin/sh
3 test_description='external diff interface test'
5 . ./test-lib.sh
7 test_expect_success setup '
9 test_tick &&
10 echo initial >file &&
11 git add file &&
12 git commit -m initial &&
14 test_tick &&
15 echo second >file &&
16 git add file &&
17 git commit -m second &&
19 test_tick &&
20 echo third >file
23 test_expect_success 'GIT_EXTERNAL_DIFF environment' '
25 GIT_EXTERNAL_DIFF=echo git diff | {
26 read path oldfile oldhex oldmode newfile newhex newmode &&
27 test "z$path" = zfile &&
28 test "z$oldmode" = z100644 &&
29 test "z$newhex" = "z$_z40" &&
30 test "z$newmode" = z100644 &&
31 oh=$(git rev-parse --verify HEAD:file) &&
32 test "z$oh" = "z$oldhex"
37 test_expect_success 'GIT_EXTERNAL_DIFF environment should apply only to diff' '
39 GIT_EXTERNAL_DIFF=echo git log -p -1 HEAD |
40 grep "^diff --git a/file b/file"
44 test_expect_success 'GIT_EXTERNAL_DIFF environment and --no-ext-diff' '
46 GIT_EXTERNAL_DIFF=echo git diff --no-ext-diff |
47 grep "^diff --git a/file b/file"
51 test_expect_success SYMLINKS 'typechange diff' '
52 rm -f file &&
53 ln -s elif file &&
54 GIT_EXTERNAL_DIFF=echo git diff | {
55 read path oldfile oldhex oldmode newfile newhex newmode &&
56 test "z$path" = zfile &&
57 test "z$oldmode" = z100644 &&
58 test "z$newhex" = "z$_z40" &&
59 test "z$newmode" = z120000 &&
60 oh=$(git rev-parse --verify HEAD:file) &&
61 test "z$oh" = "z$oldhex"
62 } &&
63 GIT_EXTERNAL_DIFF=echo git diff --no-ext-diff >actual &&
64 git diff >expect &&
65 test_cmp expect actual
68 test_expect_success 'diff.external' '
69 git reset --hard &&
70 echo third >file &&
71 test_config diff.external echo &&
72 git diff | {
73 read path oldfile oldhex oldmode newfile newhex newmode &&
74 test "z$path" = zfile &&
75 test "z$oldmode" = z100644 &&
76 test "z$newhex" = "z$_z40" &&
77 test "z$newmode" = z100644 &&
78 oh=$(git rev-parse --verify HEAD:file) &&
79 test "z$oh" = "z$oldhex"
83 test_expect_success 'diff.external should apply only to diff' '
84 test_config diff.external echo &&
85 git log -p -1 HEAD |
86 grep "^diff --git a/file b/file"
89 test_expect_success 'diff.external and --no-ext-diff' '
90 test_config diff.external echo &&
91 git diff --no-ext-diff |
92 grep "^diff --git a/file b/file"
95 test_expect_success 'diff attribute' '
96 git reset --hard &&
97 echo third >file &&
99 git config diff.parrot.command echo &&
101 echo >.gitattributes "file diff=parrot" &&
103 git diff | {
104 read path oldfile oldhex oldmode newfile newhex newmode &&
105 test "z$path" = zfile &&
106 test "z$oldmode" = z100644 &&
107 test "z$newhex" = "z$_z40" &&
108 test "z$newmode" = z100644 &&
109 oh=$(git rev-parse --verify HEAD:file) &&
110 test "z$oh" = "z$oldhex"
115 test_expect_success 'diff attribute should apply only to diff' '
117 git log -p -1 HEAD |
118 grep "^diff --git a/file b/file"
122 test_expect_success 'diff attribute and --no-ext-diff' '
124 git diff --no-ext-diff |
125 grep "^diff --git a/file b/file"
129 test_expect_success 'diff attribute' '
131 git config --unset diff.parrot.command &&
132 git config diff.color.command echo &&
134 echo >.gitattributes "file diff=color" &&
136 git diff | {
137 read path oldfile oldhex oldmode newfile newhex newmode &&
138 test "z$path" = zfile &&
139 test "z$oldmode" = z100644 &&
140 test "z$newhex" = "z$_z40" &&
141 test "z$newmode" = z100644 &&
142 oh=$(git rev-parse --verify HEAD:file) &&
143 test "z$oh" = "z$oldhex"
148 test_expect_success 'diff attribute should apply only to diff' '
150 git log -p -1 HEAD |
151 grep "^diff --git a/file b/file"
155 test_expect_success 'diff attribute and --no-ext-diff' '
157 git diff --no-ext-diff |
158 grep "^diff --git a/file b/file"
162 test_expect_success 'GIT_EXTERNAL_DIFF trumps diff.external' '
163 >.gitattributes &&
164 test_config diff.external "echo ext-global" &&
165 GIT_EXTERNAL_DIFF="echo ext-env" git diff | grep ext-env
168 test_expect_success 'attributes trump GIT_EXTERNAL_DIFF and diff.external' '
169 test_config diff.foo.command "echo ext-attribute" &&
170 test_config diff.external "echo ext-global" &&
171 echo "file diff=foo" >.gitattributes &&
172 GIT_EXTERNAL_DIFF="echo ext-env" git diff | grep ext-attribute
175 test_expect_success 'no diff with -diff' '
176 echo >.gitattributes "file -diff" &&
177 git diff | grep Binary
180 echo NULZbetweenZwords | perl -pe 'y/Z/\000/' > file
182 test_expect_success 'force diff with "diff"' '
183 echo >.gitattributes "file diff" &&
184 git diff >actual &&
185 test_cmp "$TEST_DIRECTORY"/t4020/diff.NUL actual
188 test_expect_success 'GIT_EXTERNAL_DIFF with more than one changed files' '
189 echo anotherfile > file2 &&
190 git add file2 &&
191 git commit -m "added 2nd file" &&
192 echo modified >file2 &&
193 GIT_EXTERNAL_DIFF=echo git diff
196 test_expect_success 'GIT_EXTERNAL_DIFF path counter/total' '
197 write_script external-diff.sh <<-\EOF &&
198 echo $GIT_DIFF_PATH_COUNTER of $GIT_DIFF_PATH_TOTAL >>counter.txt
200 >counter.txt &&
201 cat >expect <<-\EOF &&
202 1 of 2
203 2 of 2
205 GIT_EXTERNAL_DIFF=./external-diff.sh git diff &&
206 test_cmp expect counter.txt
209 test_expect_success 'GIT_EXTERNAL_DIFF generates pretty paths' '
210 touch file.ext &&
211 git add file.ext &&
212 echo with extension > file.ext &&
213 GIT_EXTERNAL_DIFF=echo git diff file.ext | grep ......_file\.ext &&
214 git update-index --force-remove file.ext &&
215 rm file.ext
218 echo "#!$SHELL_PATH" >fake-diff.sh
219 cat >> fake-diff.sh <<\EOF
220 cat $2 >> crlfed.txt
222 chmod a+x fake-diff.sh
224 keep_only_cr () {
225 tr -dc '\015'
228 test_expect_success 'external diff with autocrlf = true' '
229 test_config core.autocrlf true &&
230 GIT_EXTERNAL_DIFF=./fake-diff.sh git diff &&
231 test $(wc -l < crlfed.txt) = $(cat crlfed.txt | keep_only_cr | wc -c)
234 test_expect_success 'diff --cached' '
235 test_config core.autocrlf true &&
236 git add file &&
237 git update-index --assume-unchanged file &&
238 echo second >file &&
239 git diff --cached >actual &&
240 test_cmp "$TEST_DIRECTORY"/t4020/diff.NUL actual
243 test_expect_success 'clean up crlf leftovers' '
244 git update-index --no-assume-unchanged file &&
245 rm -f file* &&
246 git reset --hard
249 test_expect_success 'submodule diff' '
250 git init sub &&
251 ( cd sub && test_commit sub1 ) &&
252 git add sub &&
253 test_tick &&
254 git commit -m "add submodule" &&
255 ( cd sub && test_commit sub2 ) &&
256 write_script gather_pre_post.sh <<-\EOF &&
257 echo "$1 $4" # path, mode
258 cat "$2" # old file
259 cat "$5" # new file
261 GIT_EXTERNAL_DIFF=./gather_pre_post.sh git diff >actual &&
262 cat >expected <<-EOF &&
263 sub 160000
264 Subproject commit $(git rev-parse HEAD:sub)
265 Subproject commit $(cd sub && git rev-parse HEAD)
267 test_cmp expected actual
270 test_done