Merge branch 'ps/pack-refs-auto' into jt/reftable-geometric-compaction
[git.git] / t / t7800-difftool.sh
blob96ae5d5880d6a597d0c553c4535081c2e51356df
1 #!/bin/sh
3 # Copyright (c) 2009, 2010, 2012, 2013 David Aguilar
6 test_description='git-difftool
8 Testing basic diff tool invocation
11 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
12 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
14 . ./test-lib.sh
16 difftool_test_setup ()
18 test_config diff.tool test-tool &&
19 test_config difftool.test-tool.cmd 'cat "$LOCAL"' &&
20 test_config difftool.bogus-tool.cmd false
23 prompt_given ()
25 prompt="$1"
26 test "$prompt" = "Launch 'test-tool' [Y/n]? branch"
29 test_expect_success 'basic usage requires no repo' '
30 test_expect_code 129 git difftool -h >output &&
31 test_grep ^usage: output &&
32 # create a ceiling directory to prevent Git from finding a repo
33 mkdir -p not/repo &&
34 test_when_finished rm -r not &&
35 test_expect_code 129 \
36 env GIT_CEILING_DIRECTORIES="$(pwd)/not" \
37 git -C not/repo difftool -h >output &&
38 test_grep ^usage: output
41 # Create a file on main and change it on branch
42 test_expect_success 'setup' '
43 echo main >file &&
44 git add file &&
45 git commit -m "added file" &&
47 git checkout -b branch main &&
48 echo branch >file &&
49 git commit -a -m "branch changed file" &&
50 git checkout main
53 # Configure a custom difftool.<tool>.cmd and use it
54 test_expect_success 'custom commands' '
55 difftool_test_setup &&
56 test_config difftool.test-tool.cmd "cat \"\$REMOTE\"" &&
57 echo main >expect &&
58 git difftool --no-prompt branch >actual &&
59 test_cmp expect actual &&
61 test_config difftool.test-tool.cmd "cat \"\$LOCAL\"" &&
62 echo branch >expect &&
63 git difftool --no-prompt branch >actual &&
64 test_cmp expect actual
67 test_expect_success 'custom tool commands override built-ins' '
68 test_config difftool.vimdiff.cmd "cat \"\$REMOTE\"" &&
69 echo main >expect &&
70 git difftool --tool vimdiff --no-prompt branch >actual &&
71 test_cmp expect actual
74 test_expect_success 'difftool ignores bad --tool values' '
75 : >expect &&
76 test_must_fail \
77 git difftool --no-prompt --tool=bad-tool branch >actual &&
78 test_cmp expect actual
81 test_expect_success 'difftool forwards arguments to diff' '
82 difftool_test_setup &&
83 >for-diff &&
84 git add for-diff &&
85 echo changes>for-diff &&
86 git add for-diff &&
87 : >expect &&
88 git difftool --cached --no-prompt -- for-diff >actual &&
89 test_cmp expect actual &&
90 git reset -- for-diff &&
91 rm for-diff
94 for opt in '' '--dir-diff'
96 test_expect_success "difftool ${opt} ignores exit code" "
97 test_config difftool.error.cmd false &&
98 git difftool ${opt} -y -t error branch
101 test_expect_success "difftool ${opt} forwards exit code with --trust-exit-code" "
102 test_config difftool.error.cmd false &&
103 test_must_fail git difftool ${opt} -y --trust-exit-code -t error branch
106 test_expect_success "difftool ${opt} forwards exit code with --trust-exit-code for built-ins" "
107 test_config difftool.vimdiff.path false &&
108 test_must_fail git difftool ${opt} -y --trust-exit-code -t vimdiff branch
111 test_expect_success "difftool ${opt} honors difftool.trustExitCode = true" "
112 test_config difftool.error.cmd false &&
113 test_config difftool.trustExitCode true &&
114 test_must_fail git difftool ${opt} -y -t error branch
117 test_expect_success "difftool ${opt} honors difftool.trustExitCode = false" "
118 test_config difftool.error.cmd false &&
119 test_config difftool.trustExitCode false &&
120 git difftool ${opt} -y -t error branch
123 test_expect_success "difftool ${opt} ignores exit code with --no-trust-exit-code" "
124 test_config difftool.error.cmd false &&
125 test_config difftool.trustExitCode true &&
126 git difftool ${opt} -y --no-trust-exit-code -t error branch
129 test_expect_success "difftool ${opt} stops on error with --trust-exit-code" "
130 test_when_finished 'rm -f for-diff .git/fail-right-file' &&
131 test_when_finished 'git reset -- for-diff' &&
132 write_script .git/fail-right-file <<-\EOF &&
133 echo failed
134 exit 1
136 >for-diff &&
137 git add for-diff &&
138 test_must_fail git difftool ${opt} -y --trust-exit-code \
139 --extcmd .git/fail-right-file branch >actual &&
140 test_line_count = 1 actual
143 test_expect_success "difftool ${opt} honors exit status if command not found" "
144 test_config difftool.nonexistent.cmd i-dont-exist &&
145 test_config difftool.trustExitCode false &&
146 if test "${opt}" = '--dir-diff'
147 then
148 expected_code=127
149 else
150 expected_code=128
151 fi &&
152 test_expect_code \${expected_code} git difftool ${opt} -y -t nonexistent branch
154 done
156 test_expect_success 'difftool honors --gui' '
157 difftool_test_setup &&
158 test_config merge.tool bogus-tool &&
159 test_config diff.tool bogus-tool &&
160 test_config diff.guitool test-tool &&
162 echo branch >expect &&
163 git difftool --no-prompt --gui branch >actual &&
164 test_cmp expect actual
167 test_expect_success 'difftool with guiDefault auto selects gui tool when there is DISPLAY' '
168 difftool_test_setup &&
169 test_config merge.tool bogus-tool &&
170 test_config diff.tool bogus-tool &&
171 test_config diff.guitool test-tool &&
172 test_config difftool.guiDefault auto &&
173 DISPLAY=SOMETHING && export DISPLAY &&
175 echo branch >expect &&
176 git difftool --no-prompt branch >actual &&
177 test_cmp expect actual
179 test_expect_success 'difftool with guiDefault auto selects regular tool when no DISPLAY' '
180 difftool_test_setup &&
181 test_config diff.guitool bogus-tool &&
182 test_config diff.tool test-tool &&
183 test_config difftool.guiDefault Auto &&
184 DISPLAY= && export DISPLAY &&
186 echo branch >expect &&
187 git difftool --no-prompt branch >actual &&
188 test_cmp expect actual
191 test_expect_success 'difftool with guiDefault true selects gui tool' '
192 difftool_test_setup &&
193 test_config diff.tool bogus-tool &&
194 test_config diff.guitool test-tool &&
195 test_config difftool.guiDefault true &&
197 DISPLAY= && export DISPLAY &&
198 echo branch >expect &&
199 git difftool --no-prompt branch >actual &&
200 test_cmp expect actual &&
202 DISPLAY=Something && export DISPLAY &&
203 echo branch >expect &&
204 git difftool --no-prompt branch >actual &&
205 test_cmp expect actual
208 test_expect_success 'difftool --no-gui trumps config guiDefault' '
209 difftool_test_setup &&
210 test_config diff.guitool bogus-tool &&
211 test_config diff.tool test-tool &&
212 test_config difftool.guiDefault true &&
214 echo branch >expect &&
215 git difftool --no-prompt --no-gui branch >actual &&
216 test_cmp expect actual
219 test_expect_success 'difftool --gui last setting wins' '
220 difftool_test_setup &&
221 : >expect &&
222 git difftool --no-prompt --gui --no-gui >actual &&
223 test_cmp expect actual &&
225 test_config merge.tool bogus-tool &&
226 test_config diff.tool bogus-tool &&
227 test_config diff.guitool test-tool &&
228 echo branch >expect &&
229 git difftool --no-prompt --no-gui --gui branch >actual &&
230 test_cmp expect actual
233 test_expect_success 'difftool --gui works without configured diff.guitool' '
234 difftool_test_setup &&
235 echo branch >expect &&
236 git difftool --no-prompt --gui branch >actual &&
237 test_cmp expect actual
240 # Specify the diff tool using $GIT_DIFF_TOOL
241 test_expect_success 'GIT_DIFF_TOOL variable' '
242 difftool_test_setup &&
243 git config --unset diff.tool &&
244 echo branch >expect &&
245 GIT_DIFF_TOOL=test-tool git difftool --no-prompt branch >actual &&
246 test_cmp expect actual
249 # Test the $GIT_*_TOOL variables and ensure
250 # that $GIT_DIFF_TOOL always wins unless --tool is specified
251 test_expect_success 'GIT_DIFF_TOOL overrides' '
252 difftool_test_setup &&
253 test_config diff.tool bogus-tool &&
254 test_config merge.tool bogus-tool &&
256 echo branch >expect &&
257 GIT_DIFF_TOOL=test-tool git difftool --no-prompt branch >actual &&
258 test_cmp expect actual &&
260 test_config diff.tool bogus-tool &&
261 test_config merge.tool bogus-tool &&
262 GIT_DIFF_TOOL=bogus-tool \
263 git difftool --no-prompt --tool=test-tool branch >actual &&
264 test_cmp expect actual
267 # Test that we don't have to pass --no-prompt to difftool
268 # when $GIT_DIFFTOOL_NO_PROMPT is true
269 test_expect_success 'GIT_DIFFTOOL_NO_PROMPT variable' '
270 difftool_test_setup &&
271 echo branch >expect &&
272 GIT_DIFFTOOL_NO_PROMPT=true git difftool branch >actual &&
273 test_cmp expect actual
276 # git-difftool supports the difftool.prompt variable.
277 # Test that GIT_DIFFTOOL_PROMPT can override difftool.prompt = false
278 test_expect_success 'GIT_DIFFTOOL_PROMPT variable' '
279 difftool_test_setup &&
280 test_config difftool.prompt false &&
281 echo >input &&
282 GIT_DIFFTOOL_PROMPT=true git difftool branch <input >output &&
283 prompt=$(tail -1 <output) &&
284 prompt_given "$prompt"
287 # Test that we don't have to pass --no-prompt when difftool.prompt is false
288 test_expect_success 'difftool.prompt config variable is false' '
289 difftool_test_setup &&
290 test_config difftool.prompt false &&
291 echo branch >expect &&
292 git difftool branch >actual &&
293 test_cmp expect actual
296 # Test that we don't have to pass --no-prompt when mergetool.prompt is false
297 test_expect_success 'difftool merge.prompt = false' '
298 difftool_test_setup &&
299 test_might_fail git config --unset difftool.prompt &&
300 test_config mergetool.prompt false &&
301 echo branch >expect &&
302 git difftool branch >actual &&
303 test_cmp expect actual
306 # Test that the -y flag can override difftool.prompt = true
307 test_expect_success 'difftool.prompt can overridden with -y' '
308 difftool_test_setup &&
309 test_config difftool.prompt true &&
310 echo branch >expect &&
311 git difftool -y branch >actual &&
312 test_cmp expect actual
315 # Test that the --prompt flag can override difftool.prompt = false
316 test_expect_success 'difftool.prompt can overridden with --prompt' '
317 difftool_test_setup &&
318 test_config difftool.prompt false &&
319 echo >input &&
320 git difftool --prompt branch <input >output &&
321 prompt=$(tail -1 <output) &&
322 prompt_given "$prompt"
325 # Test that the last flag passed on the command-line wins
326 test_expect_success 'difftool last flag wins' '
327 difftool_test_setup &&
328 echo branch >expect &&
329 git difftool --prompt --no-prompt branch >actual &&
330 test_cmp expect actual &&
331 echo >input &&
332 git difftool --no-prompt --prompt branch <input >output &&
333 prompt=$(tail -1 <output) &&
334 prompt_given "$prompt"
337 # git-difftool falls back to git-mergetool config variables
338 # so test that behavior here
339 test_expect_success 'difftool + mergetool config variables' '
340 test_config merge.tool test-tool &&
341 test_config mergetool.test-tool.cmd "cat \$LOCAL" &&
342 echo branch >expect &&
343 git difftool --no-prompt branch >actual &&
344 test_cmp expect actual &&
345 git difftool --gui --no-prompt branch >actual &&
346 test_cmp expect actual &&
348 # set merge.tool to something bogus, diff.tool to test-tool
349 test_config merge.tool bogus-tool &&
350 test_config diff.tool test-tool &&
351 git difftool --no-prompt branch >actual &&
352 test_cmp expect actual &&
353 git difftool --gui --no-prompt branch >actual &&
354 test_cmp expect actual &&
356 # set merge.tool, diff.tool to something bogus, merge.guitool to test-tool
357 test_config diff.tool bogus-tool &&
358 test_config merge.guitool test-tool &&
359 git difftool --gui --no-prompt branch >actual &&
360 test_cmp expect actual &&
362 # set merge.tool, diff.tool, merge.guitool to something bogus, diff.guitool to test-tool
363 test_config merge.guitool bogus-tool &&
364 test_config diff.guitool test-tool &&
365 git difftool --gui --no-prompt branch >actual &&
366 test_cmp expect actual
369 test_expect_success 'difftool.<tool>.path' '
370 test_config difftool.tkdiff.path echo &&
371 git difftool --tool=tkdiff --no-prompt branch >output &&
372 grep file output >grep-output &&
373 test_line_count = 1 grep-output
376 test_expect_success 'difftool --extcmd=cat' '
377 echo branch >expect &&
378 echo main >>expect &&
379 git difftool --no-prompt --extcmd=cat branch >actual &&
380 test_cmp expect actual
383 test_expect_success 'difftool --extcmd cat' '
384 echo branch >expect &&
385 echo main >>expect &&
386 git difftool --no-prompt --extcmd=cat branch >actual &&
387 test_cmp expect actual
390 test_expect_success 'difftool -x cat' '
391 echo branch >expect &&
392 echo main >>expect &&
393 git difftool --no-prompt -x cat branch >actual &&
394 test_cmp expect actual
397 test_expect_success 'difftool --extcmd echo arg1' '
398 echo file >expect &&
399 git difftool --no-prompt \
400 --extcmd sh\ -c\ \"echo\ \$1\" branch >actual &&
401 test_cmp expect actual
404 test_expect_success 'difftool --extcmd cat arg1' '
405 echo main >expect &&
406 git difftool --no-prompt \
407 --extcmd sh\ -c\ \"cat\ \$1\" branch >actual &&
408 test_cmp expect actual
411 test_expect_success 'difftool --extcmd cat arg2' '
412 echo branch >expect &&
413 git difftool --no-prompt \
414 --extcmd sh\ -c\ \"cat\ \\\"\$2\\\"\" branch >actual &&
415 test_cmp expect actual
418 # Create a second file on main and a different version on branch
419 test_expect_success 'setup with 2 files different' '
420 echo m2 >file2 &&
421 git add file2 &&
422 git commit -m "added file2" &&
424 git checkout branch &&
425 echo br2 >file2 &&
426 git add file2 &&
427 git commit -a -m "branch changed file2" &&
428 git checkout main
431 test_expect_success 'say no to the first file' '
432 (echo n && echo) >input &&
433 git difftool -x cat branch <input >output &&
434 grep m2 output &&
435 grep br2 output &&
436 ! grep main output &&
437 ! grep branch output
440 test_expect_success 'say no to the second file' '
441 (echo && echo n) >input &&
442 git difftool -x cat branch <input >output &&
443 grep main output &&
444 grep branch output &&
445 ! grep m2 output &&
446 ! grep br2 output
449 test_expect_success 'ending prompt input with EOF' '
450 git difftool -x cat branch </dev/null >output &&
451 ! grep main output &&
452 ! grep branch output &&
453 ! grep m2 output &&
454 ! grep br2 output
457 test_expect_success 'difftool --tool-help' '
458 git difftool --tool-help >output &&
459 grep tool output
462 test_expect_success 'setup change in subdirectory' '
463 git checkout main &&
464 mkdir sub &&
465 echo main >sub/sub &&
466 git add sub/sub &&
467 git commit -m "added sub/sub" &&
468 git tag v1 &&
469 echo test >>file &&
470 echo test >>sub/sub &&
471 git add file sub/sub &&
472 git commit -m "modified both"
475 test_expect_success 'difftool -d with growing paths' '
476 a=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
477 git init growing &&
479 cd growing &&
480 echo "test -f \"\$2/b\"" | write_script .git/test-for-b.sh &&
481 one=$(printf 1 | git hash-object -w --stdin) &&
482 two=$(printf 2 | git hash-object -w --stdin) &&
483 git update-index --add \
484 --cacheinfo 100644,$one,$a --cacheinfo 100644,$two,b &&
485 tree1=$(git write-tree) &&
486 git update-index --add \
487 --cacheinfo 100644,$two,$a --cacheinfo 100644,$one,b &&
488 tree2=$(git write-tree) &&
489 git checkout -- $a &&
490 git difftool -d --extcmd .git/test-for-b.sh $tree1 $tree2
494 run_dir_diff_test () {
495 test_expect_success "$1 --no-symlinks" "
496 symlinks=--no-symlinks &&
499 test_expect_success SYMLINKS "$1 --symlinks" "
500 symlinks=--symlinks &&
505 run_dir_diff_test 'difftool -d' '
506 git difftool -d $symlinks --extcmd ls branch >output &&
507 grep "^sub$" output &&
508 grep "^file$" output
511 run_dir_diff_test 'difftool --dir-diff' '
512 git difftool --dir-diff $symlinks --extcmd ls branch >output &&
513 grep "^sub$" output &&
514 grep "^file$" output
517 run_dir_diff_test 'difftool --dir-diff avoids repeated slashes in TMPDIR' '
518 TMPDIR="${TMPDIR:-/tmp}////" \
519 git difftool --dir-diff $symlinks --extcmd echo branch >output &&
520 grep -v // output >actual &&
521 test_line_count = 1 actual
524 run_dir_diff_test 'difftool --dir-diff ignores --prompt' '
525 git difftool --dir-diff $symlinks --prompt --extcmd ls branch >output &&
526 grep "^sub$" output &&
527 grep "^file$" output
530 run_dir_diff_test 'difftool --dir-diff branch from subdirectory' '
532 cd sub &&
533 git difftool --dir-diff $symlinks --extcmd ls branch >output &&
534 # "sub" must only exist in "right"
535 # "file" and "file2" must be listed in both "left" and "right"
536 grep "^sub$" output >sub-output &&
537 test_line_count = 1 sub-output &&
538 grep "^file$" output >file-output &&
539 test_line_count = 2 file-output &&
540 grep "^file2$" output >file2-output &&
541 test_line_count = 2 file2-output
545 run_dir_diff_test 'difftool --dir-diff v1 from subdirectory' '
547 cd sub &&
548 git difftool --dir-diff $symlinks --extcmd ls v1 >output &&
549 # "sub" and "file" exist in both v1 and HEAD.
550 # "file2" is unchanged.
551 grep "^sub$" output >sub-output &&
552 test_line_count = 2 sub-output &&
553 grep "^file$" output >file-output &&
554 test_line_count = 2 file-output &&
555 ! grep "^file2$" output
559 run_dir_diff_test 'difftool --dir-diff branch from subdirectory w/ pathspec' '
561 cd sub &&
562 git difftool --dir-diff $symlinks --extcmd ls branch -- .>output &&
563 # "sub" only exists in "right"
564 # "file" and "file2" must not be listed
565 grep "^sub$" output >sub-output &&
566 test_line_count = 1 sub-output &&
567 ! grep "^file$" output
571 run_dir_diff_test 'difftool --dir-diff v1 from subdirectory w/ pathspec' '
573 cd sub &&
574 git difftool --dir-diff $symlinks --extcmd ls v1 -- .>output &&
575 # "sub" exists in v1 and HEAD
576 # "file" is filtered out by the pathspec
577 grep "^sub$" output >sub-output &&
578 test_line_count = 2 sub-output &&
579 ! grep "^file$" output
583 run_dir_diff_test 'difftool --dir-diff from subdirectory with GIT_DIR set' '
585 GIT_DIR=$(pwd)/.git &&
586 export GIT_DIR &&
587 GIT_WORK_TREE=$(pwd) &&
588 export GIT_WORK_TREE &&
589 cd sub &&
590 git difftool --dir-diff $symlinks --extcmd ls \
591 branch -- sub >output &&
592 grep "^sub$" output &&
593 ! grep "^file$" output
597 run_dir_diff_test 'difftool --dir-diff when worktree file is missing' '
598 test_when_finished git reset --hard &&
599 rm file2 &&
600 git difftool --dir-diff $symlinks --extcmd ls branch main >output &&
601 grep "^file2$" output
604 run_dir_diff_test 'difftool --dir-diff with unmerged files' '
605 test_when_finished git reset --hard &&
606 test_config difftool.echo.cmd "echo ok" &&
607 git checkout -B conflict-a &&
608 git checkout -B conflict-b &&
609 git checkout conflict-a &&
610 echo a >>file &&
611 git add file &&
612 git commit -m conflict-a &&
613 git checkout conflict-b &&
614 echo b >>file &&
615 git add file &&
616 git commit -m conflict-b &&
617 git checkout main &&
618 git merge conflict-a &&
619 test_must_fail git merge conflict-b &&
620 cat >expect <<-EOF &&
623 git difftool --dir-diff $symlinks -t echo >actual &&
624 test_cmp expect actual
627 write_script .git/CHECK_SYMLINKS <<\EOF
628 for f in file file2 sub/sub
630 echo "$f"
631 ls -ld "$2/$f" | sed -e 's/.* -> //'
632 done >actual
635 test_expect_success SYMLINKS 'difftool --dir-diff --symlinks without unstaged changes' '
636 cat >expect <<-EOF &&
637 file
638 $PWD/file
639 file2
640 $PWD/file2
641 sub/sub
642 $PWD/sub/sub
644 git difftool --dir-diff --symlinks \
645 --extcmd "./.git/CHECK_SYMLINKS" branch HEAD &&
646 test_cmp expect actual
649 write_script modify-right-file <<\EOF
650 echo "new content" >"$2/file"
653 run_dir_diff_test 'difftool --dir-diff syncs worktree with unstaged change' '
654 test_when_finished git reset --hard &&
655 echo "orig content" >file &&
656 git difftool -d $symlinks --extcmd "$PWD/modify-right-file" branch &&
657 echo "new content" >expect &&
658 test_cmp expect file
661 run_dir_diff_test 'difftool --dir-diff syncs worktree without unstaged change' '
662 test_when_finished git reset --hard &&
663 git difftool -d $symlinks --extcmd "$PWD/modify-right-file" branch &&
664 echo "new content" >expect &&
665 test_cmp expect file
668 write_script modify-file <<\EOF
669 echo "new content" >file
672 test_expect_success 'difftool --no-symlinks does not overwrite working tree file ' '
673 echo "orig content" >file &&
674 git difftool --dir-diff --no-symlinks --extcmd "$PWD/modify-file" branch &&
675 echo "new content" >expect &&
676 test_cmp expect file
679 write_script modify-both-files <<\EOF
680 echo "wt content" >file &&
681 echo "tmp content" >"$2/file" &&
682 echo "$2" >tmpdir
685 test_expect_success 'difftool --no-symlinks detects conflict ' '
687 TMPDIR=$TRASH_DIRECTORY &&
688 export TMPDIR &&
689 echo "orig content" >file &&
690 test_must_fail git difftool --dir-diff --no-symlinks --extcmd "$PWD/modify-both-files" branch &&
691 echo "wt content" >expect &&
692 test_cmp expect file &&
693 echo "tmp content" >expect &&
694 test_cmp expect "$(cat tmpdir)/file"
698 test_expect_success 'difftool properly honors gitlink and core.worktree' '
699 test_when_finished rm -rf submod/ule &&
700 test_config_global protocol.file.allow always &&
701 git submodule add ./. submod/ule &&
702 test_config -C submod/ule diff.tool checktrees &&
703 test_config -C submod/ule difftool.checktrees.cmd '\''
704 test -d "$LOCAL" && test -d "$REMOTE" && echo good
705 '\'' &&
707 cd submod/ule &&
708 echo good >expect &&
709 git difftool --tool=checktrees --dir-diff HEAD~ >actual &&
710 test_cmp expect actual &&
711 rm -f expect actual
715 test_expect_success SYMLINKS 'difftool --dir-diff symlinked directories' '
716 test_when_finished git reset --hard &&
717 git init dirlinks &&
719 cd dirlinks &&
720 git config diff.tool checktrees &&
721 git config difftool.checktrees.cmd "echo good" &&
722 mkdir foo &&
723 : >foo/bar &&
724 git add foo/bar &&
725 test_commit symlink-one &&
726 ln -s foo link &&
727 git add link &&
728 test_commit symlink-two &&
729 echo good >expect &&
730 git difftool --tool=checktrees --dir-diff HEAD~ >actual &&
731 test_cmp expect actual
735 test_expect_success SYMLINKS 'difftool --dir-diff handles modified symlinks' '
736 test_when_finished git reset --hard &&
737 touch b &&
738 ln -s b c &&
739 git add b c &&
740 test_tick &&
741 git commit -m initial &&
742 touch d &&
743 rm c &&
744 ln -s d c &&
745 cat >expect <<-EOF &&
750 git difftool --symlinks --dir-diff --extcmd ls >output &&
751 grep -v ^/ output >actual &&
752 test_cmp expect actual &&
754 git difftool --no-symlinks --dir-diff --extcmd ls >output &&
755 grep -v ^/ output >actual &&
756 test_cmp expect actual &&
758 # The left side contains symlink "c" that points to "b"
759 test_config difftool.cat.cmd "cat \$LOCAL/c" &&
760 printf "%s\n" b >expect &&
762 git difftool --symlinks --dir-diff --tool cat >actual &&
763 test_cmp expect actual &&
765 git difftool --symlinks --no-symlinks --dir-diff --tool cat >actual &&
766 test_cmp expect actual &&
768 # The right side contains symlink "c" that points to "d"
769 test_config difftool.cat.cmd "cat \$REMOTE/c" &&
770 printf "%s\n" d >expect &&
772 git difftool --symlinks --dir-diff --tool cat >actual &&
773 test_cmp expect actual &&
775 git difftool --no-symlinks --dir-diff --tool cat >actual &&
776 test_cmp expect actual &&
778 # Deleted symlinks
779 rm -f c &&
780 cat >expect <<-EOF &&
784 git difftool --symlinks --dir-diff --extcmd ls >output &&
785 grep -v ^/ output >actual &&
786 test_cmp expect actual &&
788 git difftool --no-symlinks --dir-diff --extcmd ls >output &&
789 grep -v ^/ output >actual &&
790 test_cmp expect actual
793 test_expect_success SYMLINKS 'difftool --dir-diff writes symlinks as raw text' '
794 # Start out on a branch called "branch-init".
795 git init -b branch-init symlink-files &&
797 cd symlink-files &&
798 # This test ensures that symlinks are written as raw text.
799 # The "cat" tools output link and file contents.
800 git config difftool.cat-left-link.cmd "cat \"\$LOCAL/link\"" &&
801 git config difftool.cat-left-a.cmd "cat \"\$LOCAL/file-a\"" &&
802 git config difftool.cat-right-link.cmd "cat \"\$REMOTE/link\"" &&
803 git config difftool.cat-right-b.cmd "cat \"\$REMOTE/file-b\"" &&
805 # Record the empty initial state so that we can come back here
806 # later and not have to consider the any cases where difftool
807 # will create symlinks back into the worktree.
808 test_tick &&
809 git commit --allow-empty -m init &&
811 # Create a file called "file-a" with a symlink pointing to it.
812 git switch -c branch-a &&
813 echo a >file-a &&
814 ln -s file-a link &&
815 git add file-a link &&
816 test_tick &&
817 git commit -m link-to-file-a &&
819 # Create a file called "file-b" and point the symlink to it.
820 git switch -c branch-b &&
821 echo b >file-b &&
822 rm link &&
823 ln -s file-b link &&
824 git add file-b link &&
825 git rm file-a &&
826 test_tick &&
827 git commit -m link-to-file-b &&
829 # Checkout the initial branch so that the --symlinks behavior is
830 # not activated. The two directories should be completely
831 # independent with no symlinks pointing back here.
832 git switch branch-init &&
834 # The left link must be "file-a" and "file-a" must contain "a".
835 echo file-a >expect &&
836 git difftool --symlinks --dir-diff --tool cat-left-link \
837 branch-a branch-b >actual &&
838 test_cmp expect actual &&
840 echo a >expect &&
841 git difftool --symlinks --dir-diff --tool cat-left-a \
842 branch-a branch-b >actual &&
843 test_cmp expect actual &&
845 # The right link must be "file-b" and "file-b" must contain "b".
846 echo file-b >expect &&
847 git difftool --symlinks --dir-diff --tool cat-right-link \
848 branch-a branch-b >actual &&
849 test_cmp expect actual &&
851 echo b >expect &&
852 git difftool --symlinks --dir-diff --tool cat-right-b \
853 branch-a branch-b >actual &&
854 test_cmp expect actual
858 test_expect_success 'add -N and difftool -d' '
859 test_when_finished git reset --hard &&
861 test_write_lines A B C >intent-to-add &&
862 git add -N intent-to-add &&
863 git difftool --dir-diff --extcmd ls
866 test_expect_success 'difftool --cached with unmerged files' '
867 test_when_finished git reset --hard &&
869 test_commit conflicting &&
870 test_commit conflict-a conflict.t a &&
871 git reset --hard conflicting &&
872 test_commit conflict-b conflict.t b &&
873 test_must_fail git merge conflict-a &&
875 git difftool --cached --no-prompt >output &&
876 test_must_be_empty output
879 test_expect_success 'outside worktree' '
880 echo 1 >1 &&
881 echo 2 >2 &&
882 test_expect_code 1 nongit git \
883 -c diff.tool=echo -c difftool.echo.cmd="echo \$LOCAL \$REMOTE" \
884 difftool --no-prompt --no-index ../1 ../2 >actual &&
885 echo "../1 ../2" >expect &&
886 test_cmp expect actual
889 test_expect_success 'difftool --gui, --tool and --extcmd are mutually exclusive' '
890 difftool_test_setup &&
891 test_must_fail git difftool --gui --tool=test-tool &&
892 test_must_fail git difftool --gui --extcmd=cat &&
893 test_must_fail git difftool --tool=test-tool --extcmd=cat &&
894 test_must_fail git difftool --gui --tool=test-tool --extcmd=cat
897 test_expect_success 'difftool --rotate-to' '
898 difftool_test_setup &&
899 test_when_finished git reset --hard &&
900 echo 1 >1 &&
901 echo 2 >2 &&
902 echo 4 >4 &&
903 git add 1 2 4 &&
904 git commit -a -m "124" &&
905 git difftool --no-prompt --extcmd=cat --rotate-to="2" HEAD^ >output &&
906 cat >expect <<-\EOF &&
911 test_cmp output expect
914 test_expect_success 'difftool --skip-to' '
915 difftool_test_setup &&
916 test_when_finished git reset --hard &&
917 git difftool --no-prompt --extcmd=cat --skip-to="2" HEAD^ >output &&
918 cat >expect <<-\EOF &&
922 test_cmp output expect
925 test_expect_success 'difftool --rotate/skip-to error condition' '
926 test_must_fail git difftool --no-prompt --extcmd=cat --rotate-to="3" HEAD^ &&
927 test_must_fail git difftool --no-prompt --extcmd=cat --skip-to="3" HEAD^
929 test_done