]>
Commit | Line | Data |
---|---|---|
05e934bb CB |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2008 Charles Bailey | |
4 | # | |
5 | ||
47a528ad | 6 | test_description='git mergetool |
05e934bb CB |
7 | |
8 | Testing basic merge tool invocation' | |
9 | ||
10 | . ./test-lib.sh | |
11 | ||
b9b5078e CB |
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 | ||
05e934bb | 16 | test_expect_success 'setup' ' |
bb0a484e | 17 | git config rerere.enabled true && |
05e934bb | 18 | echo master >file1 && |
2f59c947 MZ |
19 | echo master file11 >file11 && |
20 | echo master file12 >file12 && | |
21 | echo master file13 >file13 && | |
22 | echo master file14 >file14 && | |
b9b5078e CB |
23 | mkdir subdir && |
24 | echo master sub >subdir/file3 && | |
2f59c947 MZ |
25 | git add file1 file1[1-4] subdir/file3 && |
26 | git commit -m "add initial versions" && | |
b9b5078e | 27 | |
05e934bb CB |
28 | git checkout -b branch1 master && |
29 | echo branch1 change >file1 && | |
30 | echo branch1 newfile >file2 && | |
2f59c947 MZ |
31 | echo branch1 change file11 >file11 && |
32 | echo branch1 change file13 >file13 && | |
b9b5078e | 33 | echo branch1 sub >subdir/file3 && |
2f59c947 MZ |
34 | git add file1 file11 file13 file2 subdir/file3 && |
35 | git rm file12 && | |
05e934bb | 36 | git commit -m "branch1 changes" && |
b9b5078e | 37 | |
05e934bb CB |
38 | git checkout master && |
39 | echo master updated >file1 && | |
40 | echo master new >file2 && | |
2f59c947 MZ |
41 | echo master updated file12 >file12 && |
42 | echo master updated file14 >file14 && | |
b9b5078e | 43 | echo master new sub >subdir/file3 && |
2f59c947 MZ |
44 | git add file1 file12 file14 file2 subdir/file3 && |
45 | git rm file11 && | |
b9b5078e | 46 | git commit -m "master updates" && |
05e934bb | 47 | |
05e934bb CB |
48 | git config merge.tool mytool && |
49 | git config mergetool.mytool.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" && | |
b9b5078e CB |
50 | git config mergetool.mytool.trustExitCode true |
51 | ' | |
52 | ||
53 | test_expect_success 'custom mergetool' ' | |
54 | git checkout -b test1 branch1 && | |
d492b31c | 55 | test_must_fail git merge master >/dev/null 2>&1 && |
b9b5078e CB |
56 | ( yes "" | git mergetool file1 >/dev/null 2>&1 ) && |
57 | ( yes "" | git mergetool file2 >/dev/null 2>&1 ) && | |
58 | ( yes "" | git mergetool subdir/file3 >/dev/null 2>&1 ) && | |
2f59c947 MZ |
59 | ( yes "d" | git mergetool file11 >/dev/null 2>&1 ) && |
60 | ( yes "d" | git mergetool file12 >/dev/null 2>&1 ) && | |
05e934bb CB |
61 | test "$(cat file1)" = "master updated" && |
62 | test "$(cat file2)" = "master new" && | |
b9b5078e | 63 | test "$(cat subdir/file3)" = "master new sub" && |
0ec7b6c2 CB |
64 | git commit -m "branch1 resolved with mergetool" |
65 | ' | |
66 | ||
67 | test_expect_success 'mergetool crlf' ' | |
68 | git config core.autocrlf true && | |
a48fcd83 | 69 | git checkout -b test2 branch1 && |
0ec7b6c2 | 70 | test_must_fail git merge master >/dev/null 2>&1 && |
b9b5078e CB |
71 | ( yes "" | git mergetool file1 >/dev/null 2>&1 ) && |
72 | ( yes "" | git mergetool file2 >/dev/null 2>&1 ) && | |
73 | ( yes "" | git mergetool subdir/file3 >/dev/null 2>&1 ) && | |
2f59c947 MZ |
74 | ( yes "d" | git mergetool file11 >/dev/null 2>&1 ) && |
75 | ( yes "d" | git mergetool file12 >/dev/null 2>&1 ) && | |
0ec7b6c2 CB |
76 | test "$(printf x | cat file1 -)" = "$(printf "master updated\r\nx")" && |
77 | test "$(printf x | cat file2 -)" = "$(printf "master new\r\nx")" && | |
b9b5078e CB |
78 | test "$(printf x | cat subdir/file3 -)" = "$(printf "master new sub\r\nx")" && |
79 | git commit -m "branch1 resolved with mergetool - autocrlf" && | |
80 | git config core.autocrlf false && | |
81 | git reset --hard | |
82 | ' | |
83 | ||
ff4a1855 | 84 | test_expect_success 'mergetool in subdir' ' |
25641fcd BG |
85 | git checkout -b test3 branch1 && |
86 | ( | |
87 | cd subdir && | |
88 | test_must_fail git merge master >/dev/null 2>&1 && | |
89 | ( yes "" | git mergetool file3 >/dev/null 2>&1 ) && | |
90 | test "$(cat file3)" = "master new sub" | |
91 | ) | |
05e934bb CB |
92 | ' |
93 | ||
bb0a484e | 94 | test_expect_success 'mergetool on file in parent dir' ' |
25641fcd BG |
95 | ( |
96 | cd subdir && | |
97 | ( yes "" | git mergetool ../file1 >/dev/null 2>&1 ) && | |
98 | ( yes "" | git mergetool ../file2 >/dev/null 2>&1 ) && | |
2f59c947 MZ |
99 | ( yes "d" | git mergetool ../file11 >/dev/null 2>&1 ) && |
100 | ( yes "d" | git mergetool ../file12 >/dev/null 2>&1 ) && | |
25641fcd BG |
101 | test "$(cat ../file1)" = "master updated" && |
102 | test "$(cat ../file2)" = "master new" && | |
103 | git commit -m "branch1 resolved with mergetool - subdir" | |
104 | ) | |
bb0a484e DA |
105 | ' |
106 | ||
107 | test_expect_success 'mergetool skips autoresolved' ' | |
108 | git checkout -b test4 branch1 && | |
109 | test_must_fail git merge master && | |
110 | test -n "$(git ls-files -u)" && | |
2f59c947 MZ |
111 | ( yes "d" | git mergetool file11 >/dev/null 2>&1 ) && |
112 | ( yes "d" | git mergetool file12 >/dev/null 2>&1 ) && | |
bb0a484e DA |
113 | output="$(git mergetool --no-prompt)" && |
114 | test "$output" = "No files need merging" && | |
115 | git reset --hard | |
116 | ' | |
117 | ||
118 | test_expect_success 'mergetool merges all from subdir' ' | |
25641fcd BG |
119 | ( |
120 | cd subdir && | |
121 | git config rerere.enabled false && | |
122 | test_must_fail git merge master && | |
2f59c947 | 123 | ( yes "d" "d" | git mergetool --no-prompt ) && |
25641fcd BG |
124 | test "$(cat ../file1)" = "master updated" && |
125 | test "$(cat ../file2)" = "master new" && | |
126 | test "$(cat file3)" = "master new sub" && | |
25641fcd BG |
127 | git commit -m "branch2 resolved by mergetool from subdir" |
128 | ) | |
bb0a484e | 129 | ' |
b9b5078e | 130 | |
2f59c947 MZ |
131 | test_expect_success 'mergetool skips resolved paths when rerere is active' ' |
132 | git config rerere.enabled true && | |
133 | rm -rf .git/rr-cache && | |
134 | git checkout -b test5 branch1 | |
135 | test_must_fail git merge master >/dev/null 2>&1 && | |
136 | ( yes "d" "d" | git mergetool --no-prompt >/dev/null 2>&1 ) && | |
137 | output="$(yes "n" | git mergetool --no-prompt)" && | |
138 | test "$output" = "No files need merging" && | |
139 | git reset --hard | |
140 | ' | |
141 | ||
05e934bb | 142 | test_done |