]>
Commit | Line | Data |
---|---|---|
f92f2038 DA |
1 | #!/bin/sh |
2 | # | |
9e5a86f2 | 3 | # Copyright (c) 2009, 2010, 2012, 2013 David Aguilar |
f92f2038 DA |
4 | # |
5 | ||
6 | test_description='git-difftool | |
7 | ||
8 | Testing basic diff tool invocation | |
9 | ' | |
10 | ||
11 | . ./test-lib.sh | |
12 | ||
e42360c4 | 13 | difftool_test_setup () |
f92f2038 | 14 | { |
e42360c4 DA |
15 | test_config diff.tool test-tool && |
16 | test_config difftool.test-tool.cmd 'cat "$LOCAL"' && | |
17 | test_config difftool.bogus-tool.cmd false | |
f92f2038 DA |
18 | } |
19 | ||
e42360c4 | 20 | prompt_given () |
a904392e DA |
21 | { |
22 | prompt="$1" | |
cce076e3 | 23 | test "$prompt" = "Launch 'test-tool' [Y/n]? branch" |
ba959de1 SC |
24 | } |
25 | ||
d81345ce | 26 | test_expect_success 'basic usage requires no repo' ' |
e66adcad | 27 | test_expect_code 129 git difftool -h >output && |
0d75bfe6 | 28 | test_i18ngrep ^usage: output && |
d81345ce DA |
29 | # create a ceiling directory to prevent Git from finding a repo |
30 | mkdir -p not/repo && | |
e66adcad DA |
31 | test_when_finished rm -r not && |
32 | test_expect_code 129 \ | |
33 | env GIT_CEILING_DIRECTORIES="$(pwd)/not" \ | |
34 | git -C not/repo difftool -h >output && | |
0d75bfe6 | 35 | test_i18ngrep ^usage: output |
d81345ce DA |
36 | ' |
37 | ||
f92f2038 | 38 | # Create a file on master and change it on branch |
019678d6 | 39 | test_expect_success 'setup' ' |
f92f2038 DA |
40 | echo master >file && |
41 | git add file && | |
42 | git commit -m "added file" && | |
43 | ||
44 | git checkout -b branch master && | |
45 | echo branch >file && | |
46 | git commit -a -m "branch changed file" && | |
47 | git checkout master | |
48 | ' | |
49 | ||
50 | # Configure a custom difftool.<tool>.cmd and use it | |
019678d6 | 51 | test_expect_success 'custom commands' ' |
e42360c4 DA |
52 | difftool_test_setup && |
53 | test_config difftool.test-tool.cmd "cat \"\$REMOTE\"" && | |
54 | echo master >expect && | |
55 | git difftool --no-prompt branch >actual && | |
56 | test_cmp expect actual && | |
f92f2038 | 57 | |
e42360c4 DA |
58 | test_config difftool.test-tool.cmd "cat \"\$LOCAL\"" && |
59 | echo branch >expect && | |
60 | git difftool --no-prompt branch >actual && | |
61 | test_cmp expect actual | |
f92f2038 DA |
62 | ' |
63 | ||
019678d6 | 64 | test_expect_success 'custom tool commands override built-ins' ' |
f469e840 | 65 | test_config difftool.vimdiff.cmd "cat \"\$REMOTE\"" && |
e42360c4 | 66 | echo master >expect && |
f469e840 | 67 | git difftool --tool vimdiff --no-prompt branch >actual && |
e42360c4 | 68 | test_cmp expect actual |
a427ef7a DA |
69 | ' |
70 | ||
019678d6 | 71 | test_expect_success 'difftool ignores bad --tool values' ' |
e42360c4 | 72 | : >expect && |
89294d14 | 73 | test_must_fail \ |
e42360c4 DA |
74 | git difftool --no-prompt --tool=bad-tool branch >actual && |
75 | test_cmp expect actual | |
f92f2038 DA |
76 | ' |
77 | ||
019678d6 | 78 | test_expect_success 'difftool forwards arguments to diff' ' |
e42360c4 | 79 | difftool_test_setup && |
d50b2c73 DA |
80 | >for-diff && |
81 | git add for-diff && | |
82 | echo changes>for-diff && | |
83 | git add for-diff && | |
e42360c4 DA |
84 | : >expect && |
85 | git difftool --cached --no-prompt -- for-diff >actual && | |
86 | test_cmp expect actual && | |
d50b2c73 DA |
87 | git reset -- for-diff && |
88 | rm for-diff | |
89 | ' | |
90 | ||
019678d6 | 91 | test_expect_success 'difftool ignores exit code' ' |
2b52123f DA |
92 | test_config difftool.error.cmd false && |
93 | git difftool -y -t error branch | |
94 | ' | |
95 | ||
019678d6 | 96 | test_expect_success 'difftool forwards exit code with --trust-exit-code' ' |
2b52123f DA |
97 | test_config difftool.error.cmd false && |
98 | test_must_fail git difftool -y --trust-exit-code -t error branch | |
99 | ' | |
100 | ||
019678d6 | 101 | test_expect_success 'difftool forwards exit code with --trust-exit-code for built-ins' ' |
99474b63 DA |
102 | test_config difftool.vimdiff.path false && |
103 | test_must_fail git difftool -y --trust-exit-code -t vimdiff branch | |
104 | ' | |
105 | ||
019678d6 | 106 | test_expect_success 'difftool honors difftool.trustExitCode = true' ' |
2b52123f DA |
107 | test_config difftool.error.cmd false && |
108 | test_config difftool.trustExitCode true && | |
109 | test_must_fail git difftool -y -t error branch | |
110 | ' | |
111 | ||
019678d6 | 112 | test_expect_success 'difftool honors difftool.trustExitCode = false' ' |
2b52123f DA |
113 | test_config difftool.error.cmd false && |
114 | test_config difftool.trustExitCode false && | |
115 | git difftool -y -t error branch | |
116 | ' | |
117 | ||
019678d6 | 118 | test_expect_success 'difftool ignores exit code with --no-trust-exit-code' ' |
2b52123f DA |
119 | test_config difftool.error.cmd false && |
120 | test_config difftool.trustExitCode true && | |
121 | git difftool -y --no-trust-exit-code -t error branch | |
122 | ' | |
123 | ||
019678d6 | 124 | test_expect_success 'difftool stops on error with --trust-exit-code' ' |
2b52123f DA |
125 | test_when_finished "rm -f for-diff .git/fail-right-file" && |
126 | test_when_finished "git reset -- for-diff" && | |
127 | write_script .git/fail-right-file <<-\EOF && | |
e4837b44 | 128 | echo failed |
2b52123f DA |
129 | exit 1 |
130 | EOF | |
131 | >for-diff && | |
132 | git add for-diff && | |
2b52123f DA |
133 | test_must_fail git difftool -y --trust-exit-code \ |
134 | --extcmd .git/fail-right-file branch >actual && | |
e4837b44 | 135 | test_line_count = 1 actual |
2b52123f DA |
136 | ' |
137 | ||
019678d6 | 138 | test_expect_success 'difftool honors exit status if command not found' ' |
45a4f5d9 JK |
139 | test_config difftool.nonexistent.cmd i-dont-exist && |
140 | test_config difftool.trustExitCode false && | |
141 | test_must_fail git difftool -y -t nonexistent branch | |
142 | ' | |
143 | ||
019678d6 | 144 | test_expect_success 'difftool honors --gui' ' |
e42360c4 DA |
145 | difftool_test_setup && |
146 | test_config merge.tool bogus-tool && | |
147 | test_config diff.tool bogus-tool && | |
148 | test_config diff.guitool test-tool && | |
4cefa495 | 149 | |
e42360c4 DA |
150 | echo branch >expect && |
151 | git difftool --no-prompt --gui branch >actual && | |
152 | test_cmp expect actual | |
4cefa495 DA |
153 | ' |
154 | ||
019678d6 | 155 | test_expect_success 'difftool --gui last setting wins' ' |
e42360c4 DA |
156 | difftool_test_setup && |
157 | : >expect && | |
158 | git difftool --no-prompt --gui --no-gui >actual && | |
159 | test_cmp expect actual && | |
85089604 | 160 | |
e42360c4 DA |
161 | test_config merge.tool bogus-tool && |
162 | test_config diff.tool bogus-tool && | |
163 | test_config diff.guitool test-tool && | |
164 | echo branch >expect && | |
165 | git difftool --no-prompt --no-gui --gui branch >actual && | |
166 | test_cmp expect actual | |
85089604 TH |
167 | ' |
168 | ||
019678d6 | 169 | test_expect_success 'difftool --gui works without configured diff.guitool' ' |
e42360c4 DA |
170 | difftool_test_setup && |
171 | echo branch >expect && | |
172 | git difftool --no-prompt --gui branch >actual && | |
173 | test_cmp expect actual | |
42accaec DA |
174 | ' |
175 | ||
f92f2038 | 176 | # Specify the diff tool using $GIT_DIFF_TOOL |
019678d6 | 177 | test_expect_success 'GIT_DIFF_TOOL variable' ' |
e42360c4 DA |
178 | difftool_test_setup && |
179 | git config --unset diff.tool && | |
180 | echo branch >expect && | |
181 | GIT_DIFF_TOOL=test-tool git difftool --no-prompt branch >actual && | |
182 | test_cmp expect actual | |
f92f2038 DA |
183 | ' |
184 | ||
185 | # Test the $GIT_*_TOOL variables and ensure | |
186 | # that $GIT_DIFF_TOOL always wins unless --tool is specified | |
019678d6 | 187 | test_expect_success 'GIT_DIFF_TOOL overrides' ' |
e42360c4 DA |
188 | difftool_test_setup && |
189 | test_config diff.tool bogus-tool && | |
190 | test_config merge.tool bogus-tool && | |
f92f2038 | 191 | |
e42360c4 DA |
192 | echo branch >expect && |
193 | GIT_DIFF_TOOL=test-tool git difftool --no-prompt branch >actual && | |
194 | test_cmp expect actual && | |
f92f2038 | 195 | |
e42360c4 DA |
196 | test_config diff.tool bogus-tool && |
197 | test_config merge.tool bogus-tool && | |
198 | GIT_DIFF_TOOL=bogus-tool \ | |
199 | git difftool --no-prompt --tool=test-tool branch >actual && | |
200 | test_cmp expect actual | |
f92f2038 DA |
201 | ' |
202 | ||
203 | # Test that we don't have to pass --no-prompt to difftool | |
204 | # when $GIT_DIFFTOOL_NO_PROMPT is true | |
019678d6 | 205 | test_expect_success 'GIT_DIFFTOOL_NO_PROMPT variable' ' |
e42360c4 DA |
206 | difftool_test_setup && |
207 | echo branch >expect && | |
208 | GIT_DIFFTOOL_NO_PROMPT=true git difftool branch >actual && | |
209 | test_cmp expect actual | |
f92f2038 DA |
210 | ' |
211 | ||
a904392e DA |
212 | # git-difftool supports the difftool.prompt variable. |
213 | # Test that GIT_DIFFTOOL_PROMPT can override difftool.prompt = false | |
019678d6 | 214 | test_expect_success 'GIT_DIFFTOOL_PROMPT variable' ' |
e42360c4 DA |
215 | difftool_test_setup && |
216 | test_config difftool.prompt false && | |
217 | echo >input && | |
218 | GIT_DIFFTOOL_PROMPT=true git difftool branch <input >output && | |
219 | prompt=$(tail -1 <output) && | |
220 | prompt_given "$prompt" | |
a904392e DA |
221 | ' |
222 | ||
223 | # Test that we don't have to pass --no-prompt when difftool.prompt is false | |
019678d6 | 224 | test_expect_success 'difftool.prompt config variable is false' ' |
e42360c4 DA |
225 | difftool_test_setup && |
226 | test_config difftool.prompt false && | |
227 | echo branch >expect && | |
228 | git difftool branch >actual && | |
229 | test_cmp expect actual | |
a904392e DA |
230 | ' |
231 | ||
a88183f1 | 232 | # Test that we don't have to pass --no-prompt when mergetool.prompt is false |
019678d6 | 233 | test_expect_success 'difftool merge.prompt = false' ' |
e42360c4 | 234 | difftool_test_setup && |
bc0f35ca | 235 | test_might_fail git config --unset difftool.prompt && |
e42360c4 DA |
236 | test_config mergetool.prompt false && |
237 | echo branch >expect && | |
238 | git difftool branch >actual && | |
239 | test_cmp expect actual | |
a88183f1 DA |
240 | ' |
241 | ||
a904392e | 242 | # Test that the -y flag can override difftool.prompt = true |
019678d6 | 243 | test_expect_success 'difftool.prompt can overridden with -y' ' |
e42360c4 DA |
244 | difftool_test_setup && |
245 | test_config difftool.prompt true && | |
246 | echo branch >expect && | |
247 | git difftool -y branch >actual && | |
248 | test_cmp expect actual | |
a904392e DA |
249 | ' |
250 | ||
251 | # Test that the --prompt flag can override difftool.prompt = false | |
019678d6 | 252 | test_expect_success 'difftool.prompt can overridden with --prompt' ' |
e42360c4 DA |
253 | difftool_test_setup && |
254 | test_config difftool.prompt false && | |
255 | echo >input && | |
256 | git difftool --prompt branch <input >output && | |
257 | prompt=$(tail -1 <output) && | |
258 | prompt_given "$prompt" | |
a904392e DA |
259 | ' |
260 | ||
261 | # Test that the last flag passed on the command-line wins | |
019678d6 | 262 | test_expect_success 'difftool last flag wins' ' |
e42360c4 DA |
263 | difftool_test_setup && |
264 | echo branch >expect && | |
265 | git difftool --prompt --no-prompt branch >actual && | |
266 | test_cmp expect actual && | |
267 | echo >input && | |
268 | git difftool --no-prompt --prompt branch <input >output && | |
269 | prompt=$(tail -1 <output) && | |
270 | prompt_given "$prompt" | |
a904392e DA |
271 | ' |
272 | ||
f92f2038 DA |
273 | # git-difftool falls back to git-mergetool config variables |
274 | # so test that behavior here | |
019678d6 | 275 | test_expect_success 'difftool + mergetool config variables' ' |
e42360c4 DA |
276 | test_config merge.tool test-tool && |
277 | test_config mergetool.test-tool.cmd "cat \$LOCAL" && | |
278 | echo branch >expect && | |
279 | git difftool --no-prompt branch >actual && | |
280 | test_cmp expect actual && | |
6c22d715 DL |
281 | git difftool --gui --no-prompt branch >actual && |
282 | test_cmp expect actual && | |
f92f2038 DA |
283 | |
284 | # set merge.tool to something bogus, diff.tool to test-tool | |
e42360c4 DA |
285 | test_config merge.tool bogus-tool && |
286 | test_config diff.tool test-tool && | |
287 | git difftool --no-prompt branch >actual && | |
6c22d715 DL |
288 | test_cmp expect actual && |
289 | git difftool --gui --no-prompt branch >actual && | |
290 | test_cmp expect actual && | |
291 | ||
292 | # set merge.tool, diff.tool to something bogus, merge.guitool to test-tool | |
293 | test_config diff.tool bogus-tool && | |
294 | test_config merge.guitool test-tool && | |
295 | git difftool --gui --no-prompt branch >actual && | |
296 | test_cmp expect actual && | |
297 | ||
298 | # set merge.tool, diff.tool, merge.guitool to something bogus, diff.guitool to test-tool | |
299 | test_config merge.guitool bogus-tool && | |
300 | test_config diff.guitool test-tool && | |
301 | git difftool --gui --no-prompt branch >actual && | |
e42360c4 | 302 | test_cmp expect actual |
f92f2038 DA |
303 | ' |
304 | ||
019678d6 | 305 | test_expect_success 'difftool.<tool>.path' ' |
e42360c4 DA |
306 | test_config difftool.tkdiff.path echo && |
307 | git difftool --tool=tkdiff --no-prompt branch >output && | |
1ce515f0 DA |
308 | grep file output >grep-output && |
309 | test_line_count = 1 grep-output | |
1c6f5b52 DA |
310 | ' |
311 | ||
019678d6 | 312 | test_expect_success 'difftool --extcmd=cat' ' |
e42360c4 DA |
313 | echo branch >expect && |
314 | echo master >>expect && | |
315 | git difftool --no-prompt --extcmd=cat branch >actual && | |
316 | test_cmp expect actual | |
f47f1e2c | 317 | ' |
1c6f5b52 | 318 | |
019678d6 | 319 | test_expect_success 'difftool --extcmd cat' ' |
e42360c4 DA |
320 | echo branch >expect && |
321 | echo master >>expect && | |
322 | git difftool --no-prompt --extcmd=cat branch >actual && | |
323 | test_cmp expect actual | |
f47f1e2c | 324 | ' |
1c6f5b52 | 325 | |
019678d6 | 326 | test_expect_success 'difftool -x cat' ' |
e42360c4 DA |
327 | echo branch >expect && |
328 | echo master >>expect && | |
329 | git difftool --no-prompt -x cat branch >actual && | |
330 | test_cmp expect actual | |
9f3d54d1 DA |
331 | ' |
332 | ||
019678d6 | 333 | test_expect_success 'difftool --extcmd echo arg1' ' |
e42360c4 DA |
334 | echo file >expect && |
335 | git difftool --no-prompt \ | |
336 | --extcmd sh\ -c\ \"echo\ \$1\" branch >actual && | |
337 | test_cmp expect actual | |
9f3d54d1 | 338 | ' |
1c6f5b52 | 339 | |
019678d6 | 340 | test_expect_success 'difftool --extcmd cat arg1' ' |
e42360c4 DA |
341 | echo master >expect && |
342 | git difftool --no-prompt \ | |
343 | --extcmd sh\ -c\ \"cat\ \$1\" branch >actual && | |
344 | test_cmp expect actual | |
9f3d54d1 | 345 | ' |
1c6f5b52 | 346 | |
019678d6 | 347 | test_expect_success 'difftool --extcmd cat arg2' ' |
e42360c4 DA |
348 | echo branch >expect && |
349 | git difftool --no-prompt \ | |
665177eb | 350 | --extcmd sh\ -c\ \"cat\ \\\"\$2\\\"\" branch >actual && |
e42360c4 | 351 | test_cmp expect actual |
f92f2038 DA |
352 | ' |
353 | ||
ba959de1 | 354 | # Create a second file on master and a different version on branch |
019678d6 | 355 | test_expect_success 'setup with 2 files different' ' |
ba959de1 SC |
356 | echo m2 >file2 && |
357 | git add file2 && | |
358 | git commit -m "added file2" && | |
359 | ||
360 | git checkout branch && | |
361 | echo br2 >file2 && | |
362 | git add file2 && | |
363 | git commit -a -m "branch changed file2" && | |
364 | git checkout master | |
365 | ' | |
366 | ||
019678d6 | 367 | test_expect_success 'say no to the first file' ' |
e42360c4 DA |
368 | (echo n && echo) >input && |
369 | git difftool -x cat branch <input >output && | |
472353a5 JK |
370 | grep m2 output && |
371 | grep br2 output && | |
372 | ! grep master output && | |
373 | ! grep branch output | |
ba959de1 SC |
374 | ' |
375 | ||
019678d6 | 376 | test_expect_success 'say no to the second file' ' |
e42360c4 DA |
377 | (echo && echo n) >input && |
378 | git difftool -x cat branch <input >output && | |
472353a5 JK |
379 | grep master output && |
380 | grep branch output && | |
381 | ! grep m2 output && | |
382 | ! grep br2 output | |
ba959de1 SC |
383 | ' |
384 | ||
019678d6 | 385 | test_expect_success 'ending prompt input with EOF' ' |
25098690 JS |
386 | git difftool -x cat branch </dev/null >output && |
387 | ! grep master output && | |
388 | ! grep branch output && | |
389 | ! grep m2 output && | |
390 | ! grep br2 output | |
391 | ' | |
392 | ||
019678d6 | 393 | test_expect_success 'difftool --tool-help' ' |
e42360c4 | 394 | git difftool --tool-help >output && |
472353a5 | 395 | grep tool output |
bf73fc21 TH |
396 | ' |
397 | ||
019678d6 | 398 | test_expect_success 'setup change in subdirectory' ' |
7e0abcec TH |
399 | git checkout master && |
400 | mkdir sub && | |
401 | echo master >sub/sub && | |
402 | git add sub/sub && | |
403 | git commit -m "added sub/sub" && | |
853e10c1 | 404 | git tag v1 && |
7e0abcec TH |
405 | echo test >>file && |
406 | echo test >>sub/sub && | |
3caf5a93 | 407 | git add file sub/sub && |
7e0abcec TH |
408 | git commit -m "modified both" |
409 | ' | |
410 | ||
882add13 JS |
411 | test_expect_success 'difftool -d with growing paths' ' |
412 | a=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa && | |
413 | git init growing && | |
414 | ( | |
415 | cd growing && | |
416 | echo "test -f \"\$2/b\"" | write_script .git/test-for-b.sh && | |
417 | one=$(printf 1 | git hash-object -w --stdin) && | |
418 | two=$(printf 2 | git hash-object -w --stdin) && | |
419 | git update-index --add \ | |
420 | --cacheinfo 100644,$one,$a --cacheinfo 100644,$two,b && | |
421 | tree1=$(git write-tree) && | |
422 | git update-index --add \ | |
423 | --cacheinfo 100644,$two,$a --cacheinfo 100644,$one,b && | |
424 | tree2=$(git write-tree) && | |
425 | git checkout -- $a && | |
426 | git difftool -d --extcmd .git/test-for-b.sh $tree1 $tree2 | |
427 | ) | |
428 | ' | |
429 | ||
e01afdb7 | 430 | run_dir_diff_test () { |
019678d6 | 431 | test_expect_success "$1 --no-symlinks" " |
e01afdb7 JK |
432 | symlinks=--no-symlinks && |
433 | $2 | |
434 | " | |
019678d6 | 435 | test_expect_success SYMLINKS "$1 --symlinks" " |
e01afdb7 JK |
436 | symlinks=--symlinks && |
437 | $2 | |
438 | " | |
439 | } | |
440 | ||
441 | run_dir_diff_test 'difftool -d' ' | |
442 | git difftool -d $symlinks --extcmd ls branch >output && | |
472353a5 JK |
443 | grep sub output && |
444 | grep file output | |
7e0abcec TH |
445 | ' |
446 | ||
e01afdb7 JK |
447 | run_dir_diff_test 'difftool --dir-diff' ' |
448 | git difftool --dir-diff $symlinks --extcmd ls branch >output && | |
472353a5 JK |
449 | grep sub output && |
450 | grep file output | |
7e0abcec TH |
451 | ' |
452 | ||
e01afdb7 JK |
453 | run_dir_diff_test 'difftool --dir-diff ignores --prompt' ' |
454 | git difftool --dir-diff $symlinks --prompt --extcmd ls branch >output && | |
472353a5 JK |
455 | grep sub output && |
456 | grep file output | |
bf341b90 JK |
457 | ' |
458 | ||
853e10c1 | 459 | run_dir_diff_test 'difftool --dir-diff branch from subdirectory' ' |
bf341b90 JK |
460 | ( |
461 | cd sub && | |
e01afdb7 | 462 | git difftool --dir-diff $symlinks --extcmd ls branch >output && |
853e10c1 DA |
463 | # "sub" must only exist in "right" |
464 | # "file" and "file2" must be listed in both "left" and "right" | |
8d8061d6 | 465 | grep sub output >sub-output && |
1ce515f0 DA |
466 | test_line_count = 1 sub-output && |
467 | grep file"$" output >file-output && | |
468 | test_line_count = 2 file-output && | |
469 | grep file2 output >file2-output && | |
470 | test_line_count = 2 file2-output | |
853e10c1 DA |
471 | ) |
472 | ' | |
473 | ||
474 | run_dir_diff_test 'difftool --dir-diff v1 from subdirectory' ' | |
475 | ( | |
476 | cd sub && | |
477 | git difftool --dir-diff $symlinks --extcmd ls v1 >output && | |
478 | # "sub" and "file" exist in both v1 and HEAD. | |
479 | # "file2" is unchanged. | |
1ce515f0 DA |
480 | grep sub output >sub-output && |
481 | test_line_count = 2 sub-output && | |
482 | grep file output >file-output && | |
483 | test_line_count = 2 file-output && | |
484 | ! grep file2 output | |
853e10c1 DA |
485 | ) |
486 | ' | |
487 | ||
488 | run_dir_diff_test 'difftool --dir-diff branch from subdirectory w/ pathspec' ' | |
489 | ( | |
490 | cd sub && | |
491 | git difftool --dir-diff $symlinks --extcmd ls branch -- .>output && | |
492 | # "sub" only exists in "right" | |
493 | # "file" and "file2" must not be listed | |
1ce515f0 DA |
494 | grep sub output >sub-output && |
495 | test_line_count = 1 sub-output && | |
496 | ! grep file output | |
853e10c1 DA |
497 | ) |
498 | ' | |
499 | ||
500 | run_dir_diff_test 'difftool --dir-diff v1 from subdirectory w/ pathspec' ' | |
501 | ( | |
502 | cd sub && | |
503 | git difftool --dir-diff $symlinks --extcmd ls v1 -- .>output && | |
504 | # "sub" exists in v1 and HEAD | |
505 | # "file" is filtered out by the pathspec | |
1ce515f0 DA |
506 | grep sub output >sub-output && |
507 | test_line_count = 2 sub-output && | |
508 | ! grep file output | |
bf341b90 JK |
509 | ) |
510 | ' | |
511 | ||
98f917ed DA |
512 | run_dir_diff_test 'difftool --dir-diff from subdirectory with GIT_DIR set' ' |
513 | ( | |
514 | GIT_DIR=$(pwd)/.git && | |
515 | export GIT_DIR && | |
516 | GIT_WORK_TREE=$(pwd) && | |
517 | export GIT_WORK_TREE && | |
518 | cd sub && | |
519 | git difftool --dir-diff $symlinks --extcmd ls \ | |
520 | branch -- sub >output && | |
521 | grep sub output && | |
522 | ! grep file output | |
523 | ) | |
524 | ' | |
525 | ||
1f197a1d JK |
526 | run_dir_diff_test 'difftool --dir-diff when worktree file is missing' ' |
527 | test_when_finished git reset --hard && | |
528 | rm file2 && | |
529 | git difftool --dir-diff $symlinks --extcmd ls branch master >output && | |
530 | grep file2 output | |
531 | ' | |
532 | ||
366f9cea DA |
533 | run_dir_diff_test 'difftool --dir-diff with unmerged files' ' |
534 | test_when_finished git reset --hard && | |
535 | test_config difftool.echo.cmd "echo ok" && | |
536 | git checkout -B conflict-a && | |
537 | git checkout -B conflict-b && | |
538 | git checkout conflict-a && | |
539 | echo a >>file && | |
540 | git add file && | |
541 | git commit -m conflict-a && | |
542 | git checkout conflict-b && | |
543 | echo b >>file && | |
544 | git add file && | |
545 | git commit -m conflict-b && | |
546 | git checkout master && | |
547 | git merge conflict-a && | |
548 | test_must_fail git merge conflict-b && | |
549 | cat >expect <<-EOF && | |
550 | ok | |
551 | EOF | |
552 | git difftool --dir-diff $symlinks -t echo >actual && | |
553 | test_cmp expect actual | |
554 | ' | |
555 | ||
02c56314 JK |
556 | write_script .git/CHECK_SYMLINKS <<\EOF |
557 | for f in file file2 sub/sub | |
558 | do | |
559 | echo "$f" | |
d2addc3b | 560 | ls -ld "$2/$f" | sed -e 's/.* -> //' |
02c56314 JK |
561 | done >actual |
562 | EOF | |
563 | ||
baa4adc6 | 564 | test_expect_success SYMLINKS 'difftool --dir-diff --symlinks without unstaged changes' ' |
02c56314 JK |
565 | cat >expect <<-EOF && |
566 | file | |
fd318a94 | 567 | $PWD/file |
02c56314 | 568 | file2 |
fd318a94 | 569 | $PWD/file2 |
02c56314 | 570 | sub/sub |
fd318a94 | 571 | $PWD/sub/sub |
02c56314 | 572 | EOF |
baa4adc6 | 573 | git difftool --dir-diff --symlinks \ |
02c56314 | 574 | --extcmd "./.git/CHECK_SYMLINKS" branch HEAD && |
dcbaa0b3 | 575 | test_cmp expect actual |
02c56314 JK |
576 | ' |
577 | ||
32eaf1de KS |
578 | write_script modify-right-file <<\EOF |
579 | echo "new content" >"$2/file" | |
580 | EOF | |
581 | ||
582 | run_dir_diff_test 'difftool --dir-diff syncs worktree with unstaged change' ' | |
583 | test_when_finished git reset --hard && | |
584 | echo "orig content" >file && | |
fd318a94 | 585 | git difftool -d $symlinks --extcmd "$PWD/modify-right-file" branch && |
32eaf1de KS |
586 | echo "new content" >expect && |
587 | test_cmp expect file | |
588 | ' | |
589 | ||
590 | run_dir_diff_test 'difftool --dir-diff syncs worktree without unstaged change' ' | |
591 | test_when_finished git reset --hard && | |
fd318a94 | 592 | git difftool -d $symlinks --extcmd "$PWD/modify-right-file" branch && |
32eaf1de KS |
593 | echo "new content" >expect && |
594 | test_cmp expect file | |
595 | ' | |
596 | ||
67aa147a JK |
597 | write_script modify-file <<\EOF |
598 | echo "new content" >file | |
599 | EOF | |
600 | ||
019678d6 | 601 | test_expect_success 'difftool --no-symlinks does not overwrite working tree file ' ' |
67aa147a | 602 | echo "orig content" >file && |
fd318a94 | 603 | git difftool --dir-diff --no-symlinks --extcmd "$PWD/modify-file" branch && |
67aa147a JK |
604 | echo "new content" >expect && |
605 | test_cmp expect file | |
606 | ' | |
607 | ||
608 | write_script modify-both-files <<\EOF | |
609 | echo "wt content" >file && | |
610 | echo "tmp content" >"$2/file" && | |
611 | echo "$2" >tmpdir | |
612 | EOF | |
613 | ||
019678d6 | 614 | test_expect_success 'difftool --no-symlinks detects conflict ' ' |
67aa147a JK |
615 | ( |
616 | TMPDIR=$TRASH_DIRECTORY && | |
617 | export TMPDIR && | |
618 | echo "orig content" >file && | |
fd318a94 | 619 | test_must_fail git difftool --dir-diff --no-symlinks --extcmd "$PWD/modify-both-files" branch && |
67aa147a JK |
620 | echo "wt content" >expect && |
621 | test_cmp expect file && | |
622 | echo "tmp content" >expect && | |
623 | test_cmp expect "$(cat tmpdir)/file" | |
624 | ) | |
625 | ' | |
626 | ||
019678d6 | 627 | test_expect_success 'difftool properly honors gitlink and core.worktree' ' |
98fde5e4 | 628 | test_when_finished rm -rf submod/ule && |
fcfec8bd | 629 | git submodule add ./. submod/ule && |
da568b66 JK |
630 | test_config -C submod/ule diff.tool checktrees && |
631 | test_config -C submod/ule difftool.checktrees.cmd '\'' | |
632 | test -d "$LOCAL" && test -d "$REMOTE" && echo good | |
633 | '\'' && | |
fcfec8bd JH |
634 | ( |
635 | cd submod/ule && | |
fcfec8bd JH |
636 | echo good >expect && |
637 | git difftool --tool=checktrees --dir-diff HEAD~ >actual && | |
98fde5e4 DA |
638 | test_cmp expect actual && |
639 | rm -f expect actual | |
fcfec8bd JH |
640 | ) |
641 | ' | |
642 | ||
019678d6 | 643 | test_expect_success SYMLINKS 'difftool --dir-diff symlinked directories' ' |
98fde5e4 | 644 | test_when_finished git reset --hard && |
cfe2d4be DA |
645 | git init dirlinks && |
646 | ( | |
647 | cd dirlinks && | |
648 | git config diff.tool checktrees && | |
649 | git config difftool.checktrees.cmd "echo good" && | |
650 | mkdir foo && | |
651 | : >foo/bar && | |
652 | git add foo/bar && | |
653 | test_commit symlink-one && | |
654 | ln -s foo link && | |
655 | git add link && | |
656 | test_commit symlink-two && | |
657 | echo good >expect && | |
658 | git difftool --tool=checktrees --dir-diff HEAD~ >actual && | |
659 | test_cmp expect actual | |
660 | ) | |
661 | ' | |
662 | ||
18ec8005 DA |
663 | test_expect_success SYMLINKS 'difftool --dir-diff handles modified symlinks' ' |
664 | test_when_finished git reset --hard && | |
665 | touch b && | |
666 | ln -s b c && | |
667 | git add b c && | |
668 | test_tick && | |
669 | git commit -m initial && | |
670 | touch d && | |
671 | rm c && | |
672 | ln -s d c && | |
673 | cat >expect <<-EOF && | |
674 | b | |
675 | c | |
676 | ||
677 | c | |
678 | EOF | |
679 | git difftool --symlinks --dir-diff --extcmd ls >output && | |
680 | grep -v ^/ output >actual && | |
681 | test_cmp expect actual && | |
682 | ||
683 | git difftool --no-symlinks --dir-diff --extcmd ls >output && | |
684 | grep -v ^/ output >actual && | |
685 | test_cmp expect actual && | |
686 | ||
687 | # The left side contains symlink "c" that points to "b" | |
688 | test_config difftool.cat.cmd "cat \$LOCAL/c" && | |
689 | printf "%s\n" b >expect && | |
690 | ||
691 | git difftool --symlinks --dir-diff --tool cat >actual && | |
692 | test_cmp expect actual && | |
693 | ||
694 | git difftool --symlinks --no-symlinks --dir-diff --tool cat >actual && | |
695 | test_cmp expect actual && | |
696 | ||
697 | # The right side contains symlink "c" that points to "d" | |
698 | test_config difftool.cat.cmd "cat \$REMOTE/c" && | |
699 | printf "%s\n" d >expect && | |
700 | ||
701 | git difftool --symlinks --dir-diff --tool cat >actual && | |
702 | test_cmp expect actual && | |
703 | ||
704 | git difftool --no-symlinks --dir-diff --tool cat >actual && | |
705 | test_cmp expect actual && | |
706 | ||
707 | # Deleted symlinks | |
708 | rm -f c && | |
709 | cat >expect <<-EOF && | |
710 | b | |
711 | c | |
712 | ||
713 | EOF | |
714 | git difftool --symlinks --dir-diff --extcmd ls >output && | |
715 | grep -v ^/ output >actual && | |
716 | test_cmp expect actual && | |
717 | ||
718 | git difftool --no-symlinks --dir-diff --extcmd ls >output && | |
719 | grep -v ^/ output >actual && | |
720 | test_cmp expect actual | |
721 | ' | |
722 | ||
3080c509 JS |
723 | test_expect_success 'add -N and difftool -d' ' |
724 | test_when_finished git reset --hard && | |
725 | ||
726 | test_write_lines A B C >intent-to-add && | |
727 | git add -N intent-to-add && | |
728 | git difftool --dir-diff --extcmd ls | |
729 | ' | |
730 | ||
20de316e JS |
731 | test_expect_success 'outside worktree' ' |
732 | echo 1 >1 && | |
733 | echo 2 >2 && | |
734 | test_expect_code 1 nongit git \ | |
735 | -c diff.tool=echo -c difftool.echo.cmd="echo \$LOCAL \$REMOTE" \ | |
736 | difftool --no-prompt --no-index ../1 ../2 >actual && | |
737 | echo "../1 ../2" >expect && | |
738 | test_cmp expect actual | |
739 | ' | |
740 | ||
7f978d7d DL |
741 | test_expect_success 'difftool --gui, --tool and --extcmd are mutually exclusive' ' |
742 | difftool_test_setup && | |
743 | test_must_fail git difftool --gui --tool=test-tool && | |
744 | test_must_fail git difftool --gui --extcmd=cat && | |
745 | test_must_fail git difftool --tool=test-tool --extcmd=cat && | |
746 | test_must_fail git difftool --gui --tool=test-tool --extcmd=cat | |
747 | ' | |
748 | ||
f92f2038 | 749 | test_done |