blob: 0e34b87e376accbd613d96645f368fb5300c43e3 [file] [log] [blame]
Charles Bailey05e934b2008-02-21 23:31:56 +00001#!/bin/sh
2#
3# Copyright (c) 2008 Charles Bailey
4#
5
Nanako Shiraishi47a528a2008-09-03 17:59:33 +09006test_description='git mergetool
Charles Bailey05e934b2008-02-21 23:31:56 +00007
8Testing basic merge tool invocation'
9
10. ./test-lib.sh
11
Charles Baileyb9b50782009-01-30 23:20:10 +000012# 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
Charles Bailey05e934b2008-02-21 23:31:56 +000016test_expect_success 'setup' '
David Aguilarf9e43082014-10-15 01:35:20 -070017 test_config rerere.enabled true &&
David Aguilar74578612014-10-15 01:35:17 -070018 echo master >file1 &&
19 echo master spaced >"spaced name" &&
20 echo master file11 >file11 &&
21 echo master file12 >file12 &&
22 echo master file13 >file13 &&
23 echo master file14 >file14 &&
24 mkdir subdir &&
25 echo master sub >subdir/file3 &&
26 test_create_repo submod &&
27 (
28 cd submod &&
29 : >foo &&
30 git add foo &&
31 git commit -m "Add foo"
32 ) &&
33 git submodule add git://example.com/submod submod &&
34 git add file1 "spaced name" file1[1-4] subdir/file3 .gitmodules submod &&
35 git commit -m "add initial versions" &&
Charles Baileyb9b50782009-01-30 23:20:10 +000036
David Aguilar74578612014-10-15 01:35:17 -070037 git checkout -b branch1 master &&
38 git submodule update -N &&
39 echo branch1 change >file1 &&
40 echo branch1 newfile >file2 &&
41 echo branch1 spaced >"spaced name" &&
42 echo branch1 both added >both &&
43 echo branch1 change file11 >file11 &&
44 echo branch1 change file13 >file13 &&
45 echo branch1 sub >subdir/file3 &&
46 (
47 cd submod &&
48 echo branch1 submodule >bar &&
49 git add bar &&
50 git commit -m "Add bar on branch1" &&
51 git checkout -b submod-branch1
52 ) &&
53 git add file1 "spaced name" file11 file13 file2 subdir/file3 submod &&
54 git add both &&
55 git rm file12 &&
56 git commit -m "branch1 changes" &&
Charles Baileyb9b50782009-01-30 23:20:10 +000057
Richard Hansen157acfc2017-01-10 15:41:52 -050058 git checkout -b delete-base branch1 &&
59 mkdir -p a/a &&
Eric Sunshine0590ff22018-07-01 20:23:42 -040060 test_write_lines one two 3 4 >a/a/file.txt &&
Richard Hansen157acfc2017-01-10 15:41:52 -050061 git add a/a/file.txt &&
62 git commit -m"base file" &&
63 git checkout -b move-to-b delete-base &&
64 mkdir -p b/b &&
65 git mv a/a/file.txt b/b/file.txt &&
Eric Sunshine0590ff22018-07-01 20:23:42 -040066 test_write_lines one two 4 >b/b/file.txt &&
Richard Hansen157acfc2017-01-10 15:41:52 -050067 git commit -a -m"move to b" &&
68 git checkout -b move-to-c delete-base &&
69 mkdir -p c/c &&
70 git mv a/a/file.txt c/c/file.txt &&
Eric Sunshine0590ff22018-07-01 20:23:42 -040071 test_write_lines one two 3 >c/c/file.txt &&
Richard Hansen157acfc2017-01-10 15:41:52 -050072 git commit -a -m"move to c" &&
73
David Aguilar74578612014-10-15 01:35:17 -070074 git checkout -b stash1 master &&
75 echo stash1 change file11 >file11 &&
76 git add file11 &&
77 git commit -m "stash1 changes" &&
Phil Hord79dc2d02012-07-10 18:52:27 -040078
David Aguilar74578612014-10-15 01:35:17 -070079 git checkout -b stash2 master &&
80 echo stash2 change file11 >file11 &&
81 git add file11 &&
82 git commit -m "stash2 changes" &&
Phil Hord79dc2d02012-07-10 18:52:27 -040083
David Aguilar74578612014-10-15 01:35:17 -070084 git checkout master &&
85 git submodule update -N &&
86 echo master updated >file1 &&
87 echo master new >file2 &&
88 echo master updated spaced >"spaced name" &&
89 echo master both added >both &&
90 echo master updated file12 >file12 &&
91 echo master updated file14 >file14 &&
92 echo master new sub >subdir/file3 &&
93 (
94 cd submod &&
95 echo master submodule >bar &&
96 git add bar &&
97 git commit -m "Add bar on master" &&
98 git checkout -b submod-master
99 ) &&
100 git add file1 "spaced name" file12 file14 file2 subdir/file3 submod &&
101 git add both &&
102 git rm file11 &&
103 git commit -m "master updates" &&
Charles Baileyb9b50782009-01-30 23:20:10 +0000104
Richard Hansen157acfc2017-01-10 15:41:52 -0500105 git clean -fdx &&
106 git checkout -b order-file-start master &&
107 echo start >a &&
108 echo start >b &&
109 git add a b &&
110 git commit -m start &&
111 git checkout -b order-file-side1 order-file-start &&
112 echo side1 >a &&
113 echo side1 >b &&
114 git add a b &&
115 git commit -m side1 &&
116 git checkout -b order-file-side2 order-file-start &&
117 echo side2 >a &&
118 echo side2 >b &&
119 git add a b &&
120 git commit -m side2 &&
121
David Aguilar74578612014-10-15 01:35:17 -0700122 git config merge.tool mytool &&
123 git config mergetool.mytool.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" &&
124 git config mergetool.mytool.trustExitCode true &&
125 git config mergetool.mybase.cmd "cat \"\$BASE\" >\"\$MERGED\"" &&
126 git config mergetool.mybase.trustExitCode true
Charles Bailey05e934b2008-02-21 23:31:56 +0000127'
128
129test_expect_success 'custom mergetool' '
Richard Hansenc3ad3122017-01-10 15:41:55 -0500130 test_when_finished "git reset --hard" &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500131 git checkout -b test$test_count branch1 &&
David Aguilar74578612014-10-15 01:35:17 -0700132 git submodule update -N &&
Denton Liue9d309e2019-04-24 15:46:57 -0700133 test_must_fail git merge master &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200134 yes "" | git mergetool both &&
135 yes "" | git mergetool file1 file1 &&
136 yes "" | git mergetool file2 "spaced name" &&
137 yes "" | git mergetool subdir/file3 &&
138 yes "d" | git mergetool file11 &&
139 yes "d" | git mergetool file12 &&
140 yes "l" | git mergetool submod &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200141 echo "master updated" >expect &&
142 test_cmp expect file1 &&
143 echo "master new" >expect &&
144 test_cmp expect file2 &&
145 echo "master new sub" >expect &&
146 test_cmp expect subdir/file3 &&
147 echo "branch1 submodule" >expect &&
148 test_cmp expect submod/bar &&
David Aguilar74578612014-10-15 01:35:17 -0700149 git commit -m "branch1 resolved with mergetool"
Charles Bailey0ec7b6c2009-01-21 22:57:48 +0000150'
151
Denton Liu57d93c12019-04-24 15:46:59 -0700152test_expect_success 'gui mergetool' '
153 test_config merge.guitool myguitool &&
154 test_config mergetool.myguitool.cmd "(printf \"gui \" && cat \"\$REMOTE\") >\"\$MERGED\"" &&
155 test_config mergetool.myguitool.trustExitCode true &&
156 test_when_finished "git reset --hard" &&
157 git checkout -b test$test_count branch1 &&
158 git submodule update -N &&
159 test_must_fail git merge master &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200160 yes "" | git mergetool --gui both &&
161 yes "" | git mergetool -g file1 file1 &&
162 yes "" | git mergetool --gui file2 "spaced name" &&
163 yes "" | git mergetool --gui subdir/file3 &&
164 yes "d" | git mergetool --gui file11 &&
165 yes "d" | git mergetool --gui file12 &&
166 yes "l" | git mergetool --gui submod &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200167 echo "gui master updated" >expect &&
168 test_cmp expect file1 &&
169 echo "gui master new" >expect &&
170 test_cmp expect file2 &&
171 echo "gui master new sub" >expect &&
172 test_cmp expect subdir/file3 &&
173 echo "branch1 submodule" >expect &&
174 test_cmp expect submod/bar &&
Denton Liu57d93c12019-04-24 15:46:59 -0700175 git commit -m "branch1 resolved with mergetool"
176'
177
Denton Liu60aced32019-04-29 02:21:14 -0400178test_expect_success 'gui mergetool without merge.guitool set falls back to merge.tool' '
179 test_when_finished "git reset --hard" &&
180 git checkout -b test$test_count branch1 &&
181 git submodule update -N &&
182 test_must_fail git merge master &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200183 yes "" | git mergetool --gui both &&
184 yes "" | git mergetool -g file1 file1 &&
185 yes "" | git mergetool --gui file2 "spaced name" &&
186 yes "" | git mergetool --gui subdir/file3 &&
187 yes "d" | git mergetool --gui file11 &&
188 yes "d" | git mergetool --gui file12 &&
189 yes "l" | git mergetool --gui submod &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200190 echo "master updated" >expect &&
191 test_cmp expect file1 &&
192 echo "master new" >expect &&
193 test_cmp expect file2 &&
194 echo "master new sub" >expect &&
195 test_cmp expect subdir/file3 &&
196 echo "branch1 submodule" >expect &&
197 test_cmp expect submod/bar &&
Denton Liu60aced32019-04-29 02:21:14 -0400198 git commit -m "branch1 resolved with mergetool"
199'
200
Charles Bailey0ec7b6c2009-01-21 22:57:48 +0000201test_expect_success 'mergetool crlf' '
Richard Hansen614eb272017-01-10 15:41:53 -0500202 test_when_finished "git reset --hard" &&
203 # This test_config line must go after the above reset line so that
204 # core.autocrlf is unconfigured before reset runs. (The
205 # test_config command uses test_when_finished internally and
206 # test_when_finished is LIFO.)
David Aguilarf9e43082014-10-15 01:35:20 -0700207 test_config core.autocrlf true &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500208 git checkout -b test$test_count branch1 &&
Denton Liue9d309e2019-04-24 15:46:57 -0700209 test_must_fail git merge master &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200210 yes "" | git mergetool file1 &&
211 yes "" | git mergetool file2 &&
212 yes "" | git mergetool "spaced name" &&
213 yes "" | git mergetool both &&
214 yes "" | git mergetool subdir/file3 &&
215 yes "d" | git mergetool file11 &&
216 yes "d" | git mergetool file12 &&
217 yes "r" | git mergetool submod &&
David Aguilar74578612014-10-15 01:35:17 -0700218 test "$(printf x | cat file1 -)" = "$(printf "master updated\r\nx")" &&
219 test "$(printf x | cat file2 -)" = "$(printf "master new\r\nx")" &&
220 test "$(printf x | cat subdir/file3 -)" = "$(printf "master new sub\r\nx")" &&
221 git submodule update -N &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200222 echo "master submodule" >expect &&
223 test_cmp expect submod/bar &&
Richard Hansen614eb272017-01-10 15:41:53 -0500224 git commit -m "branch1 resolved with mergetool - autocrlf"
Charles Bailey05e934b2008-02-21 23:31:56 +0000225'
226
Charles Baileyff4a1852009-01-30 23:20:11 +0000227test_expect_success 'mergetool in subdir' '
Richard Hansenc3ad3122017-01-10 15:41:55 -0500228 test_when_finished "git reset --hard" &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500229 git checkout -b test$test_count branch1 &&
David Aguilar74578612014-10-15 01:35:17 -0700230 git submodule update -N &&
231 (
232 cd subdir &&
Denton Liue9d309e2019-04-24 15:46:57 -0700233 test_must_fail git merge master &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200234 yes "" | git mergetool file3 &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200235 echo "master new sub" >expect &&
236 test_cmp expect file3
David Aguilar74578612014-10-15 01:35:17 -0700237 )
Charles Baileyb9b50782009-01-30 23:20:10 +0000238'
239
David Aguilarbb0a4842010-08-17 02:22:46 -0700240test_expect_success 'mergetool on file in parent dir' '
Richard Hansenc3ad3122017-01-10 15:41:55 -0500241 test_when_finished "git reset --hard" &&
Richard Hansenfef6c062017-01-10 15:41:58 -0500242 git checkout -b test$test_count branch1 &&
Richard Hansenb696ac92017-01-10 15:41:54 -0500243 git submodule update -N &&
David Aguilar74578612014-10-15 01:35:17 -0700244 (
245 cd subdir &&
Denton Liue9d309e2019-04-24 15:46:57 -0700246 test_must_fail git merge master &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200247 yes "" | git mergetool file3 &&
248 yes "" | git mergetool ../file1 &&
249 yes "" | git mergetool ../file2 ../spaced\ name &&
250 yes "" | git mergetool ../both &&
251 yes "d" | git mergetool ../file11 &&
252 yes "d" | git mergetool ../file12 &&
253 yes "l" | git mergetool ../submod &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200254 echo "master updated" >expect &&
255 test_cmp expect ../file1 &&
256 echo "master new" >expect &&
257 test_cmp expect ../file2 &&
258 echo "branch1 submodule" >expect &&
259 test_cmp expect ../submod/bar &&
David Aguilar74578612014-10-15 01:35:17 -0700260 git commit -m "branch1 resolved with mergetool - subdir"
261 )
David Aguilarbb0a4842010-08-17 02:22:46 -0700262'
263
264test_expect_success 'mergetool skips autoresolved' '
Richard Hansen614eb272017-01-10 15:41:53 -0500265 test_when_finished "git reset --hard" &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500266 git checkout -b test$test_count branch1 &&
David Aguilar74578612014-10-15 01:35:17 -0700267 git submodule update -N &&
268 test_must_fail git merge master &&
269 test -n "$(git ls-files -u)" &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200270 yes "d" | git mergetool file11 &&
271 yes "d" | git mergetool file12 &&
272 yes "l" | git mergetool submod &&
David Aguilar74578612014-10-15 01:35:17 -0700273 output="$(git mergetool --no-prompt)" &&
Richard Hansen614eb272017-01-10 15:41:53 -0500274 test "$output" = "No files need merging"
David Aguilarbb0a4842010-08-17 02:22:46 -0700275'
276
Richard Hansenb9ebb652017-01-10 15:42:00 -0500277test_expect_success 'mergetool merges all from subdir (rerere disabled)' '
Richard Hansenc3ad3122017-01-10 15:41:55 -0500278 test_when_finished "git reset --hard" &&
Richard Hansenfef6c062017-01-10 15:41:58 -0500279 git checkout -b test$test_count branch1 &&
John Keeping1a9a23e2015-09-05 14:12:45 +0100280 test_config rerere.enabled false &&
David Aguilar74578612014-10-15 01:35:17 -0700281 (
282 cd subdir &&
David Aguilar74578612014-10-15 01:35:17 -0700283 test_must_fail git merge master &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200284 yes "r" | git mergetool ../submod &&
285 yes "d" "d" | git mergetool --no-prompt &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200286 echo "master updated" >expect &&
287 test_cmp expect ../file1 &&
288 echo "master new" >expect &&
289 test_cmp expect ../file2 &&
290 echo "master new sub" >expect &&
291 test_cmp expect file3 &&
David Aguilar74578612014-10-15 01:35:17 -0700292 ( cd .. && git submodule update -N ) &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200293 echo "master submodule" >expect &&
294 test_cmp expect ../submod/bar &&
David Aguilar74578612014-10-15 01:35:17 -0700295 git commit -m "branch2 resolved by mergetool from subdir"
296 )
David Aguilarbb0a4842010-08-17 02:22:46 -0700297'
Charles Baileyb9b50782009-01-30 23:20:10 +0000298
Richard Hansend0e0cfe2017-01-10 15:42:02 -0500299test_expect_success 'mergetool merges all from subdir (rerere enabled)' '
Richard Hansenb9ebb652017-01-10 15:42:00 -0500300 test_when_finished "git reset --hard" &&
301 git checkout -b test$test_count branch1 &&
David Aguilarf9e43082014-10-15 01:35:20 -0700302 test_config rerere.enabled true &&
David Aguilar74578612014-10-15 01:35:17 -0700303 rm -rf .git/rr-cache &&
Richard Hansenb9ebb652017-01-10 15:42:00 -0500304 (
305 cd subdir &&
306 test_must_fail git merge master &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200307 yes "r" | git mergetool ../submod &&
308 yes "d" "d" | git mergetool --no-prompt &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200309 echo "master updated" >expect &&
310 test_cmp expect ../file1 &&
311 echo "master new" >expect &&
312 test_cmp expect ../file2 &&
313 echo "master new sub" >expect &&
314 test_cmp expect file3 &&
Richard Hansenb9ebb652017-01-10 15:42:00 -0500315 ( cd .. && git submodule update -N ) &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200316 echo "master submodule" >expect &&
317 test_cmp expect ../submod/bar &&
Richard Hansenb9ebb652017-01-10 15:42:00 -0500318 git commit -m "branch2 resolved by mergetool from subdir"
319 )
320'
321
Martin von Zweigbergk2f59c942011-02-16 05:47:45 -0500322test_expect_success 'mergetool skips resolved paths when rerere is active' '
Richard Hansen614eb272017-01-10 15:41:53 -0500323 test_when_finished "git reset --hard" &&
David Aguilarf9e43082014-10-15 01:35:20 -0700324 test_config rerere.enabled true &&
David Aguilar74578612014-10-15 01:35:17 -0700325 rm -rf .git/rr-cache &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500326 git checkout -b test$test_count branch1 &&
David Aguilar74578612014-10-15 01:35:17 -0700327 git submodule update -N &&
Denton Liue9d309e2019-04-24 15:46:57 -0700328 test_must_fail git merge master &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200329 yes "l" | git mergetool --no-prompt submod &&
330 yes "d" "d" | git mergetool --no-prompt &&
David Aguilar74578612014-10-15 01:35:17 -0700331 git submodule update -N &&
332 output="$(yes "n" | git mergetool --no-prompt)" &&
Richard Hansen614eb272017-01-10 15:41:53 -0500333 test "$output" = "No files need merging"
Martin von Zweigbergk2f59c942011-02-16 05:47:45 -0500334'
335
Phil Hord743bf6d2012-07-10 18:52:28 -0400336test_expect_success 'conflicted stash sets up rerere' '
Richard Hansenc3ad3122017-01-10 15:41:55 -0500337 test_when_finished "git reset --hard" &&
David Aguilarf9e43082014-10-15 01:35:20 -0700338 test_config rerere.enabled true &&
David Aguilar74578612014-10-15 01:35:17 -0700339 git checkout stash1 &&
340 echo "Conflicting stash content" >file11 &&
341 git stash &&
Phil Hord79dc2d02012-07-10 18:52:27 -0400342
David Aguilar74578612014-10-15 01:35:17 -0700343 git checkout --detach stash2 &&
344 test_must_fail git stash apply &&
Phil Hord79dc2d02012-07-10 18:52:27 -0400345
David Aguilar74578612014-10-15 01:35:17 -0700346 test -n "$(git ls-files -u)" &&
347 conflicts="$(git rerere remaining)" &&
348 test "$conflicts" = "file11" &&
349 output="$(git mergetool --no-prompt)" &&
350 test "$output" != "No files need merging" &&
Phil Hord79dc2d02012-07-10 18:52:27 -0400351
David Aguilar74578612014-10-15 01:35:17 -0700352 git commit -am "save the stash resolution" &&
Phil Hord79dc2d02012-07-10 18:52:27 -0400353
David Aguilar74578612014-10-15 01:35:17 -0700354 git reset --hard stash2 &&
355 test_must_fail git stash apply &&
Phil Hord79dc2d02012-07-10 18:52:27 -0400356
David Aguilar74578612014-10-15 01:35:17 -0700357 test -n "$(git ls-files -u)" &&
358 conflicts="$(git rerere remaining)" &&
359 test -z "$conflicts" &&
360 output="$(git mergetool --no-prompt)" &&
361 test "$output" = "No files need merging"
Phil Hord79dc2d02012-07-10 18:52:27 -0400362'
363
Jonathon Mah3e8e6912011-09-15 19:12:10 -0700364test_expect_success 'mergetool takes partial path' '
Richard Hansen614eb272017-01-10 15:41:53 -0500365 test_when_finished "git reset --hard" &&
David Aguilarf9e43082014-10-15 01:35:20 -0700366 test_config rerere.enabled false &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500367 git checkout -b test$test_count branch1 &&
David Aguilar74578612014-10-15 01:35:17 -0700368 git submodule update -N &&
369 test_must_fail git merge master &&
Jonathon Mah3e8e6912011-09-15 19:12:10 -0700370
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200371 yes "" | git mergetool subdir &&
Jonathon Mah3e8e6912011-09-15 19:12:10 -0700372
Johannes Sixte10dffd2019-06-12 18:33:46 +0200373 echo "master new sub" >expect &&
374 test_cmp expect subdir/file3
Jonathon Mah3e8e6912011-09-15 19:12:10 -0700375'
376
David Aguilarfaaab8d2016-03-09 23:13:58 -0800377test_expect_success 'mergetool delete/delete conflict' '
Richard Hansenbd9714f2017-01-10 15:41:59 -0500378 test_when_finished "git reset --hard" &&
Richard Hansen61b76d22017-01-10 15:41:57 -0500379 git checkout -b test$test_count move-to-c &&
David Aguilarfaaab8d2016-03-09 23:13:58 -0800380 test_must_fail git merge move-to-b &&
381 echo d | git mergetool a/a/file.txt &&
382 ! test -f a/a/file.txt &&
Richard Hansenbd9714f2017-01-10 15:41:59 -0500383 git reset --hard &&
David Aguilarfaaab8d2016-03-09 23:13:58 -0800384 test_must_fail git merge move-to-b &&
385 echo m | git mergetool a/a/file.txt &&
386 test -f b/b/file.txt &&
Richard Hansenbd9714f2017-01-10 15:41:59 -0500387 git reset --hard &&
David Aguilarfaaab8d2016-03-09 23:13:58 -0800388 test_must_fail git merge move-to-b &&
389 ! echo a | git mergetool a/a/file.txt &&
Richard Hansen614eb272017-01-10 15:41:53 -0500390 ! test -f a/a/file.txt
David Aguilarfaaab8d2016-03-09 23:13:58 -0800391'
392
393test_expect_success 'mergetool produces no errors when keepBackup is used' '
Richard Hansenbd9714f2017-01-10 15:41:59 -0500394 test_when_finished "git reset --hard" &&
Richard Hansenfef6c062017-01-10 15:41:58 -0500395 git checkout -b test$test_count move-to-c &&
David Aguilarfaaab8d2016-03-09 23:13:58 -0800396 test_config mergetool.keepBackup true &&
397 test_must_fail git merge move-to-b &&
David Aguilarfaaab8d2016-03-09 23:13:58 -0800398 echo d | git mergetool a/a/file.txt 2>actual &&
SZEDER Gábor1c5e94f2018-08-19 23:57:25 +0200399 test_must_be_empty actual &&
Richard Hansen614eb272017-01-10 15:41:53 -0500400 ! test -d a
David Aguilara2986042016-03-09 23:13:59 -0800401'
402
403test_expect_success 'mergetool honors tempfile config for deleted files' '
Richard Hansenbd9714f2017-01-10 15:41:59 -0500404 test_when_finished "git reset --hard" &&
Richard Hansenfef6c062017-01-10 15:41:58 -0500405 git checkout -b test$test_count move-to-c &&
David Aguilara2986042016-03-09 23:13:59 -0800406 test_config mergetool.keepTemporaries false &&
407 test_must_fail git merge move-to-b &&
408 echo d | git mergetool a/a/file.txt &&
Richard Hansen614eb272017-01-10 15:41:53 -0500409 ! test -d a
David Aguilara2986042016-03-09 23:13:59 -0800410'
411
412test_expect_success 'mergetool keeps tempfiles when aborting delete/delete' '
Richard Hansenbd9714f2017-01-10 15:41:59 -0500413 test_when_finished "git reset --hard" &&
Richard Hansen614eb272017-01-10 15:41:53 -0500414 test_when_finished "git clean -fdx" &&
Richard Hansenfef6c062017-01-10 15:41:58 -0500415 git checkout -b test$test_count move-to-c &&
David Aguilara2986042016-03-09 23:13:59 -0800416 test_config mergetool.keepTemporaries true &&
417 test_must_fail git merge move-to-b &&
Eric Sunshine0590ff22018-07-01 20:23:42 -0400418 ! test_write_lines a n | git mergetool a/a/file.txt &&
David Aguilara2986042016-03-09 23:13:59 -0800419 test -d a/a &&
420 cat >expect <<-\EOF &&
421 file_BASE_.txt
422 file_LOCAL_.txt
423 file_REMOTE_.txt
424 EOF
425 ls -1 a/a | sed -e "s/[0-9]*//g" >actual &&
Richard Hansen614eb272017-01-10 15:41:53 -0500426 test_cmp expect actual
David Aguilarfaaab8d2016-03-09 23:13:58 -0800427'
428
Jonathon Mahff7f0892011-04-13 03:00:48 -0700429test_expect_success 'deleted vs modified submodule' '
Richard Hansenbd9714f2017-01-10 15:41:59 -0500430 test_when_finished "git reset --hard" &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500431 git checkout -b test$test_count branch1 &&
David Aguilar74578612014-10-15 01:35:17 -0700432 git submodule update -N &&
433 mv submod submod-movedaside &&
434 git rm --cached submod &&
435 git commit -m "Submodule deleted from branch" &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500436 git checkout -b test$test_count.a test$test_count &&
David Aguilar74578612014-10-15 01:35:17 -0700437 test_must_fail git merge master &&
438 test -n "$(git ls-files -u)" &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200439 yes "" | git mergetool file1 file2 spaced\ name subdir/file3 &&
440 yes "" | git mergetool both &&
441 yes "d" | git mergetool file11 file12 &&
442 yes "r" | git mergetool submod &&
David Aguilar74578612014-10-15 01:35:17 -0700443 rmdir submod && mv submod-movedaside submod &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200444 echo "branch1 submodule" >expect &&
445 test_cmp expect submod/bar &&
David Aguilar74578612014-10-15 01:35:17 -0700446 git submodule update -N &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200447 echo "master submodule" >expect &&
448 test_cmp expect submod/bar &&
David Aguilar74578612014-10-15 01:35:17 -0700449 output="$(git mergetool --no-prompt)" &&
450 test "$output" = "No files need merging" &&
451 git commit -m "Merge resolved by keeping module" &&
Jonathon Mahff7f0892011-04-13 03:00:48 -0700452
David Aguilar74578612014-10-15 01:35:17 -0700453 mv submod submod-movedaside &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500454 git checkout -b test$test_count.b test$test_count &&
David Aguilar74578612014-10-15 01:35:17 -0700455 git submodule update -N &&
456 test_must_fail git merge master &&
457 test -n "$(git ls-files -u)" &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200458 yes "" | git mergetool file1 file2 spaced\ name subdir/file3 &&
459 yes "" | git mergetool both &&
460 yes "d" | git mergetool file11 file12 &&
461 yes "l" | git mergetool submod &&
David Aguilar74578612014-10-15 01:35:17 -0700462 test ! -e submod &&
463 output="$(git mergetool --no-prompt)" &&
464 test "$output" = "No files need merging" &&
465 git commit -m "Merge resolved by deleting module" &&
Jonathon Mahff7f0892011-04-13 03:00:48 -0700466
David Aguilar74578612014-10-15 01:35:17 -0700467 mv submod-movedaside submod &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500468 git checkout -b test$test_count.c master &&
David Aguilar74578612014-10-15 01:35:17 -0700469 git submodule update -N &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500470 test_must_fail git merge test$test_count &&
David Aguilar74578612014-10-15 01:35:17 -0700471 test -n "$(git ls-files -u)" &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200472 yes "" | git mergetool file1 file2 spaced\ name subdir/file3 &&
473 yes "" | git mergetool both &&
474 yes "d" | git mergetool file11 file12 &&
475 yes "r" | git mergetool submod &&
David Aguilar74578612014-10-15 01:35:17 -0700476 test ! -e submod &&
477 test -d submod.orig &&
478 git submodule update -N &&
479 output="$(git mergetool --no-prompt)" &&
480 test "$output" = "No files need merging" &&
481 git commit -m "Merge resolved by deleting module" &&
482 mv submod.orig submod &&
Jonathon Mahff7f0892011-04-13 03:00:48 -0700483
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500484 git checkout -b test$test_count.d master &&
David Aguilar74578612014-10-15 01:35:17 -0700485 git submodule update -N &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500486 test_must_fail git merge test$test_count &&
David Aguilar74578612014-10-15 01:35:17 -0700487 test -n "$(git ls-files -u)" &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200488 yes "" | git mergetool file1 file2 spaced\ name subdir/file3 &&
489 yes "" | git mergetool both &&
490 yes "d" | git mergetool file11 file12 &&
491 yes "l" | git mergetool submod &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200492 echo "master submodule" >expect &&
493 test_cmp expect submod/bar &&
David Aguilar74578612014-10-15 01:35:17 -0700494 git submodule update -N &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200495 echo "master submodule" >expect &&
496 test_cmp expect submod/bar &&
David Aguilar74578612014-10-15 01:35:17 -0700497 output="$(git mergetool --no-prompt)" &&
498 test "$output" = "No files need merging" &&
Richard Hansen614eb272017-01-10 15:41:53 -0500499 git commit -m "Merge resolved by keeping module"
Jonathon Mahff7f0892011-04-13 03:00:48 -0700500'
501
502test_expect_success 'file vs modified submodule' '
Richard Hansenc3ad3122017-01-10 15:41:55 -0500503 test_when_finished "git reset --hard" &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500504 git checkout -b test$test_count branch1 &&
David Aguilar74578612014-10-15 01:35:17 -0700505 git submodule update -N &&
506 mv submod submod-movedaside &&
507 git rm --cached submod &&
508 echo not a submodule >submod &&
509 git add submod &&
510 git commit -m "Submodule path becomes file" &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500511 git checkout -b test$test_count.a branch1 &&
David Aguilar74578612014-10-15 01:35:17 -0700512 test_must_fail git merge master &&
513 test -n "$(git ls-files -u)" &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200514 yes "" | git mergetool file1 file2 spaced\ name subdir/file3 &&
515 yes "" | git mergetool both &&
516 yes "d" | git mergetool file11 file12 &&
517 yes "r" | git mergetool submod &&
David Aguilar74578612014-10-15 01:35:17 -0700518 rmdir submod && mv submod-movedaside submod &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200519 echo "branch1 submodule" >expect &&
520 test_cmp expect submod/bar &&
David Aguilar74578612014-10-15 01:35:17 -0700521 git submodule update -N &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200522 echo "master submodule" >expect &&
523 test_cmp expect submod/bar &&
David Aguilar74578612014-10-15 01:35:17 -0700524 output="$(git mergetool --no-prompt)" &&
525 test "$output" = "No files need merging" &&
526 git commit -m "Merge resolved by keeping module" &&
Jonathon Mahff7f0892011-04-13 03:00:48 -0700527
David Aguilar74578612014-10-15 01:35:17 -0700528 mv submod submod-movedaside &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500529 git checkout -b test$test_count.b test$test_count &&
David Aguilar74578612014-10-15 01:35:17 -0700530 test_must_fail git merge master &&
531 test -n "$(git ls-files -u)" &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200532 yes "" | git mergetool file1 file2 spaced\ name subdir/file3 &&
533 yes "" | git mergetool both &&
534 yes "d" | git mergetool file11 file12 &&
Elijah Newrenef527782020-10-26 17:01:37 +0000535 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
536 then
537 yes "c" | git mergetool submod~HEAD &&
538 git rm submod &&
539 git mv submod~HEAD submod
540 else
541 yes "l" | git mergetool submod
542 fi &&
David Aguilar74578612014-10-15 01:35:17 -0700543 git submodule update -N &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200544 echo "not a submodule" >expect &&
545 test_cmp expect submod &&
David Aguilar74578612014-10-15 01:35:17 -0700546 output="$(git mergetool --no-prompt)" &&
547 test "$output" = "No files need merging" &&
548 git commit -m "Merge resolved by keeping file" &&
Jonathon Mahff7f0892011-04-13 03:00:48 -0700549
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500550 git checkout -b test$test_count.c master &&
David Aguilar74578612014-10-15 01:35:17 -0700551 rmdir submod && mv submod-movedaside submod &&
552 test ! -e submod.orig &&
553 git submodule update -N &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500554 test_must_fail git merge test$test_count &&
David Aguilar74578612014-10-15 01:35:17 -0700555 test -n "$(git ls-files -u)" &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200556 yes "" | git mergetool file1 file2 spaced\ name subdir/file3 &&
557 yes "" | git mergetool both &&
558 yes "d" | git mergetool file11 file12 &&
Elijah Newrenef527782020-10-26 17:01:37 +0000559 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
560 then
561 mv submod submod.orig &&
562 git rm --cached submod &&
563 yes "c" | git mergetool submod~test19 &&
564 git mv submod~test19 submod
565 else
566 yes "r" | git mergetool submod
567 fi &&
David Aguilar74578612014-10-15 01:35:17 -0700568 test -d submod.orig &&
569 git submodule update -N &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200570 echo "not a submodule" >expect &&
571 test_cmp expect submod &&
David Aguilar74578612014-10-15 01:35:17 -0700572 output="$(git mergetool --no-prompt)" &&
573 test "$output" = "No files need merging" &&
574 git commit -m "Merge resolved by keeping file" &&
Jonathon Mahff7f0892011-04-13 03:00:48 -0700575
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500576 git checkout -b test$test_count.d master &&
David Aguilar74578612014-10-15 01:35:17 -0700577 rmdir submod && mv submod.orig submod &&
578 git submodule update -N &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500579 test_must_fail git merge test$test_count &&
David Aguilar74578612014-10-15 01:35:17 -0700580 test -n "$(git ls-files -u)" &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200581 yes "" | git mergetool file1 file2 spaced\ name subdir/file3 &&
582 yes "" | git mergetool both &&
583 yes "d" | git mergetool file11 file12 &&
584 yes "l" | git mergetool submod &&
Elijah Newrenef527782020-10-26 17:01:37 +0000585 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
586 then
587 yes "d" | git mergetool submod~test19
588 fi &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200589 echo "master submodule" >expect &&
590 test_cmp expect submod/bar &&
David Aguilar74578612014-10-15 01:35:17 -0700591 git submodule update -N &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200592 echo "master submodule" >expect &&
593 test_cmp expect submod/bar &&
David Aguilar74578612014-10-15 01:35:17 -0700594 output="$(git mergetool --no-prompt)" &&
595 test "$output" = "No files need merging" &&
596 git commit -m "Merge resolved by keeping module"
Jonathon Mahff7f0892011-04-13 03:00:48 -0700597'
598
599test_expect_success 'submodule in subdirectory' '
Richard Hansenc3ad3122017-01-10 15:41:55 -0500600 test_when_finished "git reset --hard" &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500601 git checkout -b test$test_count branch1 &&
David Aguilar74578612014-10-15 01:35:17 -0700602 git submodule update -N &&
Jonathon Mahff7f0892011-04-13 03:00:48 -0700603 (
David Aguilar74578612014-10-15 01:35:17 -0700604 cd subdir &&
605 test_create_repo subdir_module &&
606 (
607 cd subdir_module &&
608 : >file15 &&
609 git add file15 &&
610 git commit -m "add initial versions"
611 )
612 ) &&
Richard Hansen614eb272017-01-10 15:41:53 -0500613 test_when_finished "rm -rf subdir/subdir_module" &&
David Aguilar74578612014-10-15 01:35:17 -0700614 git submodule add git://example.com/subsubmodule subdir/subdir_module &&
615 git add subdir/subdir_module &&
616 git commit -m "add submodule in subdirectory" &&
Jonathon Mahff7f0892011-04-13 03:00:48 -0700617
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500618 git checkout -b test$test_count.a test$test_count &&
David Aguilar74578612014-10-15 01:35:17 -0700619 git submodule update -N &&
620 (
Jonathon Mahff7f0892011-04-13 03:00:48 -0700621 cd subdir/subdir_module &&
David Aguilar74578612014-10-15 01:35:17 -0700622 git checkout -b super10.a &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500623 echo test$test_count.a >file15 &&
David Aguilar74578612014-10-15 01:35:17 -0700624 git add file15 &&
625 git commit -m "on branch 10.a"
626 ) &&
627 git add subdir/subdir_module &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500628 git commit -m "change submodule in subdirectory on test$test_count.a" &&
Jonathon Mahff7f0892011-04-13 03:00:48 -0700629
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500630 git checkout -b test$test_count.b test$test_count &&
David Aguilar74578612014-10-15 01:35:17 -0700631 git submodule update -N &&
632 (
633 cd subdir/subdir_module &&
634 git checkout -b super10.b &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500635 echo test$test_count.b >file15 &&
David Aguilar74578612014-10-15 01:35:17 -0700636 git add file15 &&
637 git commit -m "on branch 10.b"
638 ) &&
639 git add subdir/subdir_module &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500640 git commit -m "change submodule in subdirectory on test$test_count.b" &&
Jonathon Mahff7f0892011-04-13 03:00:48 -0700641
Denton Liue9d309e2019-04-24 15:46:57 -0700642 test_must_fail git merge test$test_count.a &&
David Aguilar74578612014-10-15 01:35:17 -0700643 (
644 cd subdir &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200645 yes "l" | git mergetool subdir_module
David Aguilar74578612014-10-15 01:35:17 -0700646 ) &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200647 echo "test$test_count.b" >expect &&
648 test_cmp expect subdir/subdir_module/file15 &&
David Aguilar74578612014-10-15 01:35:17 -0700649 git submodule update -N &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200650 echo "test$test_count.b" >expect &&
651 test_cmp expect subdir/subdir_module/file15 &&
David Aguilar74578612014-10-15 01:35:17 -0700652 git reset --hard &&
653 git submodule update -N &&
Jonathon Mahff7f0892011-04-13 03:00:48 -0700654
Denton Liue9d309e2019-04-24 15:46:57 -0700655 test_must_fail git merge test$test_count.a &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200656 yes "r" | git mergetool subdir/subdir_module &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200657 echo "test$test_count.b" >expect &&
658 test_cmp expect subdir/subdir_module/file15 &&
David Aguilar74578612014-10-15 01:35:17 -0700659 git submodule update -N &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200660 echo "test$test_count.a" >expect &&
661 test_cmp expect subdir/subdir_module/file15 &&
Richard Hansen614eb272017-01-10 15:41:53 -0500662 git commit -m "branch1 resolved with mergetool"
Jonathon Mahff7f0892011-04-13 03:00:48 -0700663'
664
665test_expect_success 'directory vs modified submodule' '
Richard Hansenc3ad3122017-01-10 15:41:55 -0500666 test_when_finished "git reset --hard" &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500667 git checkout -b test$test_count branch1 &&
David Aguilar74578612014-10-15 01:35:17 -0700668 mv submod submod-movedaside &&
669 git rm --cached submod &&
670 mkdir submod &&
671 echo not a submodule >submod/file16 &&
672 git add submod/file16 &&
673 git commit -m "Submodule path becomes directory" &&
Jonathon Mahff7f0892011-04-13 03:00:48 -0700674
David Aguilar74578612014-10-15 01:35:17 -0700675 test_must_fail git merge master &&
676 test -n "$(git ls-files -u)" &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200677 yes "l" | git mergetool submod &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200678 echo "not a submodule" >expect &&
679 test_cmp expect submod/file16 &&
David Aguilar74578612014-10-15 01:35:17 -0700680 rm -rf submod.orig &&
Jonathon Mahff7f0892011-04-13 03:00:48 -0700681
Richard Hansenbd9714f2017-01-10 15:41:59 -0500682 git reset --hard &&
David Aguilar74578612014-10-15 01:35:17 -0700683 test_must_fail git merge master &&
684 test -n "$(git ls-files -u)" &&
685 test ! -e submod.orig &&
Elijah Newrenef527782020-10-26 17:01:37 +0000686 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
687 then
688 yes "r" | git mergetool submod~master &&
689 git mv submod submod.orig &&
690 git mv submod~master submod
691 else
692 yes "r" | git mergetool submod
693 fi &&
David Aguilar74578612014-10-15 01:35:17 -0700694 test -d submod.orig &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200695 echo "not a submodule" >expect &&
696 test_cmp expect submod.orig/file16 &&
David Aguilar74578612014-10-15 01:35:17 -0700697 rm -r submod.orig &&
698 mv submod-movedaside/.git submod &&
699 ( cd submod && git clean -f && git reset --hard ) &&
700 git submodule update -N &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200701 echo "master submodule" >expect &&
702 test_cmp expect submod/bar &&
Richard Hansenbd9714f2017-01-10 15:41:59 -0500703 git reset --hard &&
704 rm -rf submod-movedaside &&
Jonathon Mahff7f0892011-04-13 03:00:48 -0700705
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500706 git checkout -b test$test_count.c master &&
David Aguilar74578612014-10-15 01:35:17 -0700707 git submodule update -N &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500708 test_must_fail git merge test$test_count &&
David Aguilar74578612014-10-15 01:35:17 -0700709 test -n "$(git ls-files -u)" &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200710 yes "l" | git mergetool submod &&
David Aguilar74578612014-10-15 01:35:17 -0700711 git submodule update -N &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200712 echo "master submodule" >expect &&
713 test_cmp expect submod/bar &&
Jonathon Mahff7f0892011-04-13 03:00:48 -0700714
Richard Hansenbd9714f2017-01-10 15:41:59 -0500715 git reset --hard &&
David Aguilar74578612014-10-15 01:35:17 -0700716 git submodule update -N &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500717 test_must_fail git merge test$test_count &&
David Aguilar74578612014-10-15 01:35:17 -0700718 test -n "$(git ls-files -u)" &&
719 test ! -e submod.orig &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200720 yes "r" | git mergetool submod &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200721 echo "not a submodule" >expect &&
722 test_cmp expect submod/file16 &&
Jonathon Mahff7f0892011-04-13 03:00:48 -0700723
Richard Hansenbd9714f2017-01-10 15:41:59 -0500724 git reset --hard master &&
David Aguilar74578612014-10-15 01:35:17 -0700725 ( cd submod && git clean -f && git reset --hard ) &&
726 git submodule update -N
Jonathon Mahff7f0892011-04-13 03:00:48 -0700727'
728
David Aguilarec245ba2012-01-19 23:47:35 -0800729test_expect_success 'file with no base' '
Richard Hansenbd9714f2017-01-10 15:41:59 -0500730 test_when_finished "git reset --hard" &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500731 git checkout -b test$test_count branch1 &&
David Aguilar74578612014-10-15 01:35:17 -0700732 test_must_fail git merge master &&
733 git mergetool --no-prompt --tool mybase -- both &&
Ævar Arnfjörð Bjarmasond3c67512018-07-27 17:48:11 +0000734 test_must_be_empty both
David Aguilarec245ba2012-01-19 23:47:35 -0800735'
736
David Aguilara427ef72012-09-25 00:48:11 -0700737test_expect_success 'custom commands override built-ins' '
Richard Hansenbd9714f2017-01-10 15:41:59 -0500738 test_when_finished "git reset --hard" &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500739 git checkout -b test$test_count branch1 &&
David Aguilarf9e43082014-10-15 01:35:20 -0700740 test_config mergetool.defaults.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" &&
741 test_config mergetool.defaults.trustExitCode true &&
David Aguilar74578612014-10-15 01:35:17 -0700742 test_must_fail git merge master &&
743 git mergetool --no-prompt --tool defaults -- both &&
744 echo master both added >expected &&
Stefan Beller9c5b2fa2017-10-06 12:00:06 -0700745 test_cmp expected both
David Aguilara427ef72012-09-25 00:48:11 -0700746'
747
David Aguilar688684e2014-10-15 01:35:19 -0700748test_expect_success 'filenames seen by tools start with ./' '
Richard Hansenbd9714f2017-01-10 15:41:59 -0500749 test_when_finished "git reset --hard" &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500750 git checkout -b test$test_count branch1 &&
David Aguilar688684e2014-10-15 01:35:19 -0700751 test_config mergetool.writeToTemp false &&
752 test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
753 test_config mergetool.myecho.trustExitCode true &&
754 test_must_fail git merge master &&
755 git mergetool --no-prompt --tool myecho -- both >actual &&
Denton Liue9d309e2019-04-24 15:46:57 -0700756 grep ^\./both_LOCAL_ actual
David Aguilar688684e2014-10-15 01:35:19 -0700757'
758
Armin Kunaschikc578a092016-07-02 21:01:51 +0200759test_lazy_prereq MKTEMP '
760 tempdir=$(mktemp -d -t foo.XXXXXX) &&
Jeff Kingfa3142c2016-11-27 01:34:45 -0500761 test -d "$tempdir" &&
762 rmdir "$tempdir"
Armin Kunaschikc578a092016-07-02 21:01:51 +0200763'
764
765test_expect_success MKTEMP 'temporary filenames are used with mergetool.writeToTemp' '
Richard Hansenbd9714f2017-01-10 15:41:59 -0500766 test_when_finished "git reset --hard" &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500767 git checkout -b test$test_count branch1 &&
David Aguilar688684e2014-10-15 01:35:19 -0700768 test_config mergetool.writeToTemp true &&
769 test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
770 test_config mergetool.myecho.trustExitCode true &&
771 test_must_fail git merge master &&
772 git mergetool --no-prompt --tool myecho -- both >actual &&
Denton Liue9d309e2019-04-24 15:46:57 -0700773 ! grep ^\./both_LOCAL_ actual &&
774 grep /both_LOCAL_ actual
David Aguilar688684e2014-10-15 01:35:19 -0700775'
776
David Aguilar57937f72016-10-07 16:58:05 -0700777test_expect_success 'diff.orderFile configuration is honored' '
Richard Hansenbd9714f2017-01-10 15:41:59 -0500778 test_when_finished "git reset --hard" &&
Richard Hansen61b76d22017-01-10 15:41:57 -0500779 git checkout -b test$test_count order-file-side2 &&
David Aguilar57937f72016-10-07 16:58:05 -0700780 test_config diff.orderFile order-file &&
781 test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
782 test_config mergetool.myecho.trustExitCode true &&
783 echo b >order-file &&
784 echo a >>order-file &&
David Aguilar57937f72016-10-07 16:58:05 -0700785 test_must_fail git merge order-file-side1 &&
786 cat >expect <<-\EOF &&
787 Merging:
788 b
789 a
790 EOF
Richard Hansend0e0cfe2017-01-10 15:42:02 -0500791
792 # make sure "order-file" that is ambiguous between
793 # rev and path is understood correctly.
794 git branch order-file HEAD &&
795
David Aguilar57937f72016-10-07 16:58:05 -0700796 git mergetool --no-prompt --tool myecho >output &&
797 git grep --no-index -h -A2 Merging: output >actual &&
Richard Hansen614eb272017-01-10 15:41:53 -0500798 test_cmp expect actual
David Aguilar57937f72016-10-07 16:58:05 -0700799'
David Aguilar654311b2016-10-07 17:01:30 -0700800test_expect_success 'mergetool -Oorder-file is honored' '
Richard Hansenbd9714f2017-01-10 15:41:59 -0500801 test_when_finished "git reset --hard" &&
Richard Hansenfef6c062017-01-10 15:41:58 -0500802 git checkout -b test$test_count order-file-side2 &&
David Aguilar654311b2016-10-07 17:01:30 -0700803 test_config diff.orderFile order-file &&
804 test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
805 test_config mergetool.myecho.trustExitCode true &&
Richard Hansenb696ac92017-01-10 15:41:54 -0500806 echo b >order-file &&
807 echo a >>order-file &&
David Aguilar654311b2016-10-07 17:01:30 -0700808 test_must_fail git merge order-file-side1 &&
809 cat >expect <<-\EOF &&
810 Merging:
811 a
812 b
813 EOF
814 git mergetool -O/dev/null --no-prompt --tool myecho >output &&
815 git grep --no-index -h -A2 Merging: output >actual &&
816 test_cmp expect actual &&
Richard Hansenbd9714f2017-01-10 15:41:59 -0500817 git reset --hard &&
David Aguilar654311b2016-10-07 17:01:30 -0700818
819 git config --unset diff.orderFile &&
820 test_must_fail git merge order-file-side1 &&
821 cat >expect <<-\EOF &&
822 Merging:
823 b
824 a
825 EOF
826 git mergetool -Oorder-file --no-prompt --tool myecho >output &&
827 git grep --no-index -h -A2 Merging: output >actual &&
Richard Hansen614eb272017-01-10 15:41:53 -0500828 test_cmp expect actual
David Aguilar654311b2016-10-07 17:01:30 -0700829'
David Aguilar57937f72016-10-07 16:58:05 -0700830
Seth House98ea3092021-02-09 13:07:10 -0700831test_expect_success 'mergetool hideResolved' '
832 test_config mergetool.hideResolved true &&
833 test_when_finished "git reset --hard" &&
834 git checkout -b test${test_count}_b master &&
835 test_write_lines >file1 base "" a &&
836 git commit -a -m "base" &&
837 test_write_lines >file1 base "" c &&
838 git commit -a -m "remote update" &&
839 git checkout -b test${test_count}_a HEAD~ &&
840 test_write_lines >file1 local "" b &&
841 git commit -a -m "local update" &&
842 test_must_fail git merge test${test_count}_b &&
843 yes "" | git mergetool file1 &&
844 test_write_lines >expect local "" c &&
845 test_cmp expect file1 &&
846 git commit -m "test resolved with mergetool"
847'
848
Charles Bailey05e934b2008-02-21 23:31:56 +0000849test_done