1#!/bin/sh
2#
3# Copyright (c) 2008 Charles Bailey
4#
5
6test_description='git mergetool
7
8Testing basic merge tool invocation'
9
10. ./test-lib.sh
11
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
15
16test_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" &&
23
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" &&
30
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" &&
37
38 git config merge.tool mytool &&
39 git config mergetool.mytool.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" &&
40 git config mergetool.mytool.trustExitCode true
41'
42
43test_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"
53'
54
55test_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
68'
69
70test_expect_success 'mergetool in subdir' '
71 git checkout -b test3 branch1 &&
72 (
73 cd subdir &&
74 test_must_fail git merge master >/dev/null 2>&1 &&
75 ( yes "" | git mergetool file3 >/dev/null 2>&1 ) &&
76 test "$(cat file3)" = "master new sub"
77 )
78'
79
80test_expect_success 'mergetool on file in parent dir' '
81 (
82 cd subdir &&
83 ( yes "" | git mergetool ../file1 >/dev/null 2>&1 ) &&
84 ( yes "" | git mergetool ../file2 >/dev/null 2>&1 ) &&
85 test "$(cat ../file1)" = "master updated" &&
86 test "$(cat ../file2)" = "master new" &&
87 git commit -m "branch1 resolved with mergetool - subdir"
88 )
89'
90
91test_expect_success 'mergetool skips autoresolved' '
92 git checkout -b test4 branch1 &&
93 test_must_fail git merge master &&
94 test -n "$(git ls-files -u)" &&
95 output="$(git mergetool --no-prompt)" &&
96 test "$output" = "No files need merging" &&
97 git reset --hard
98'
99
100test_expect_success 'mergetool merges all from subdir' '
101 (
102 cd subdir &&
103 git config rerere.enabled false &&
104 test_must_fail git merge master &&
105 git mergetool --no-prompt &&
106 test "$(cat ../file1)" = "master updated" &&
107 test "$(cat ../file2)" = "master new" &&
108 test "$(cat file3)" = "master new sub" &&
109 git add ../file1 ../file2 file3 &&
110 git commit -m "branch2 resolved by mergetool from subdir"
111 )
112'
113
114test_done