Merge branch 'nd/fix-sparse-checkout'
[git/jnareb-git.git] / t / t7610-mergetool.sh
blobf5a7bf47e9c563139676dd0a4ce1ab7098d89011
1 #!/bin/sh
3 # Copyright (c) 2008 Charles Bailey
6 test_description='git mergetool
8 Testing basic merge tool invocation'
10 . ./test-lib.sh
12 # All the mergetool test work by checking out a temporary branch based
13 # off 'branch1' and then merging in master and checking the results of
14 # running mergetool
16 test_expect_success 'setup' '
17 git config rerere.enabled true &&
18 echo master >file1 &&
19 mkdir subdir &&
20 echo master sub >subdir/file3 &&
21 git add file1 subdir/file3 &&
22 git commit -m "added file1" &&
24 git checkout -b branch1 master &&
25 echo branch1 change >file1 &&
26 echo branch1 newfile >file2 &&
27 echo branch1 sub >subdir/file3 &&
28 git add file1 file2 subdir/file3 &&
29 git commit -m "branch1 changes" &&
31 git checkout master &&
32 echo master updated >file1 &&
33 echo master new >file2 &&
34 echo master new sub >subdir/file3 &&
35 git add file1 file2 subdir/file3 &&
36 git commit -m "master updates" &&
38 git config merge.tool mytool &&
39 git config mergetool.mytool.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" &&
40 git config mergetool.mytool.trustExitCode true
43 test_expect_success 'custom mergetool' '
44 git checkout -b test1 branch1 &&
45 test_must_fail git merge master >/dev/null 2>&1 &&
46 ( yes "" | git mergetool file1 >/dev/null 2>&1 ) &&
47 ( yes "" | git mergetool file2 >/dev/null 2>&1 ) &&
48 ( yes "" | git mergetool subdir/file3 >/dev/null 2>&1 ) &&
49 test "$(cat file1)" = "master updated" &&
50 test "$(cat file2)" = "master new" &&
51 test "$(cat subdir/file3)" = "master new sub" &&
52 git commit -m "branch1 resolved with mergetool"
55 test_expect_success 'mergetool crlf' '
56 git config core.autocrlf true &&
57 git checkout -b test2 branch1
58 test_must_fail git merge master >/dev/null 2>&1 &&
59 ( yes "" | git mergetool file1 >/dev/null 2>&1 ) &&
60 ( yes "" | git mergetool file2 >/dev/null 2>&1 ) &&
61 ( yes "" | git mergetool subdir/file3 >/dev/null 2>&1 ) &&
62 test "$(printf x | cat file1 -)" = "$(printf "master updated\r\nx")" &&
63 test "$(printf x | cat file2 -)" = "$(printf "master new\r\nx")" &&
64 test "$(printf x | cat subdir/file3 -)" = "$(printf "master new sub\r\nx")" &&
65 git commit -m "branch1 resolved with mergetool - autocrlf" &&
66 git config core.autocrlf false &&
67 git reset --hard
70 test_expect_success 'mergetool in subdir' '
71 git checkout -b test3 branch1
72 cd subdir && (
73 test_must_fail git merge master >/dev/null 2>&1 &&
74 ( yes "" | git mergetool file3 >/dev/null 2>&1 ) &&
75 test "$(cat file3)" = "master new sub") &&
76 cd ..
79 test_expect_success 'mergetool on file in parent dir' '
80 cd subdir && (
81 ( yes "" | git mergetool ../file1 >/dev/null 2>&1 ) &&
82 ( yes "" | git mergetool ../file2 >/dev/null 2>&1 ) &&
83 test "$(cat ../file1)" = "master updated" &&
84 test "$(cat ../file2)" = "master new" &&
85 git commit -m "branch1 resolved with mergetool - subdir") &&
86 cd ..
89 test_expect_success 'mergetool skips autoresolved' '
90 git checkout -b test4 branch1 &&
91 test_must_fail git merge master &&
92 test -n "$(git ls-files -u)" &&
93 output="$(git mergetool --no-prompt)" &&
94 test "$output" = "No files need merging" &&
95 git reset --hard
98 test_expect_success 'mergetool merges all from subdir' '
99 cd subdir && (
100 git config rerere.enabled false &&
101 test_must_fail git merge master &&
102 git mergetool --no-prompt &&
103 test "$(cat ../file1)" = "master updated" &&
104 test "$(cat ../file2)" = "master new" &&
105 test "$(cat file3)" = "master new sub" &&
106 git add ../file1 ../file2 file3 &&
107 git commit -m "branch2 resolved by mergetool from subdir") &&
108 cd ..
111 test_done