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