blob: 22b3a85b3e960e4d40024179b1fbaef3355d304d [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
Johannes Schindelin1e2ae142020-11-18 23:44:40 +000010GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
Johannes Schindelin334afbc2020-11-18 23:44:19 +000011export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
12
Charles Bailey05e934b2008-02-21 23:31:56 +000013. ./test-lib.sh
14
Charles Baileyb9b50782009-01-30 23:20:10 +000015# All the mergetool test work by checking out a temporary branch based
Johannes Schindelin1e2ae142020-11-18 23:44:40 +000016# off 'branch1' and then merging in main and checking the results of
Charles Baileyb9b50782009-01-30 23:20:10 +000017# running mergetool
18
Charles Bailey05e934b2008-02-21 23:31:56 +000019test_expect_success 'setup' '
David Aguilarf9e43082014-10-15 01:35:20 -070020 test_config rerere.enabled true &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +000021 echo main >file1 &&
22 echo main spaced >"spaced name" &&
23 echo main file11 >file11 &&
24 echo main file12 >file12 &&
25 echo main file13 >file13 &&
26 echo main file14 >file14 &&
David Aguilar74578612014-10-15 01:35:17 -070027 mkdir subdir &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +000028 echo main sub >subdir/file3 &&
David Aguilar74578612014-10-15 01:35:17 -070029 test_create_repo submod &&
30 (
31 cd submod &&
32 : >foo &&
33 git add foo &&
34 git commit -m "Add foo"
35 ) &&
Ævar Arnfjörð Bjarmason23fb3282022-11-16 00:40:14 +010036 git submodule add file:///dev/null submod &&
David Aguilar74578612014-10-15 01:35:17 -070037 git add file1 "spaced name" file1[1-4] subdir/file3 .gitmodules submod &&
38 git commit -m "add initial versions" &&
Charles Baileyb9b50782009-01-30 23:20:10 +000039
Johannes Schindelin1e2ae142020-11-18 23:44:40 +000040 git checkout -b branch1 main &&
David Aguilar74578612014-10-15 01:35:17 -070041 git submodule update -N &&
42 echo branch1 change >file1 &&
43 echo branch1 newfile >file2 &&
44 echo branch1 spaced >"spaced name" &&
45 echo branch1 both added >both &&
46 echo branch1 change file11 >file11 &&
47 echo branch1 change file13 >file13 &&
48 echo branch1 sub >subdir/file3 &&
49 (
50 cd submod &&
51 echo branch1 submodule >bar &&
52 git add bar &&
53 git commit -m "Add bar on branch1" &&
54 git checkout -b submod-branch1
55 ) &&
56 git add file1 "spaced name" file11 file13 file2 subdir/file3 submod &&
57 git add both &&
58 git rm file12 &&
59 git commit -m "branch1 changes" &&
Charles Baileyb9b50782009-01-30 23:20:10 +000060
Richard Hansen157acfc2017-01-10 15:41:52 -050061 git checkout -b delete-base branch1 &&
62 mkdir -p a/a &&
Eric Sunshine0590ff22018-07-01 20:23:42 -040063 test_write_lines one two 3 4 >a/a/file.txt &&
Richard Hansen157acfc2017-01-10 15:41:52 -050064 git add a/a/file.txt &&
65 git commit -m"base file" &&
66 git checkout -b move-to-b delete-base &&
67 mkdir -p b/b &&
68 git mv a/a/file.txt b/b/file.txt &&
Eric Sunshine0590ff22018-07-01 20:23:42 -040069 test_write_lines one two 4 >b/b/file.txt &&
Richard Hansen157acfc2017-01-10 15:41:52 -050070 git commit -a -m"move to b" &&
71 git checkout -b move-to-c delete-base &&
72 mkdir -p c/c &&
73 git mv a/a/file.txt c/c/file.txt &&
Eric Sunshine0590ff22018-07-01 20:23:42 -040074 test_write_lines one two 3 >c/c/file.txt &&
Richard Hansen157acfc2017-01-10 15:41:52 -050075 git commit -a -m"move to c" &&
76
Johannes Schindelin1e2ae142020-11-18 23:44:40 +000077 git checkout -b stash1 main &&
David Aguilar74578612014-10-15 01:35:17 -070078 echo stash1 change file11 >file11 &&
79 git add file11 &&
80 git commit -m "stash1 changes" &&
Phil Hord79dc2d02012-07-10 18:52:27 -040081
Johannes Schindelin1e2ae142020-11-18 23:44:40 +000082 git checkout -b stash2 main &&
David Aguilar74578612014-10-15 01:35:17 -070083 echo stash2 change file11 >file11 &&
84 git add file11 &&
85 git commit -m "stash2 changes" &&
Phil Hord79dc2d02012-07-10 18:52:27 -040086
Johannes Schindelin1e2ae142020-11-18 23:44:40 +000087 git checkout main &&
David Aguilar74578612014-10-15 01:35:17 -070088 git submodule update -N &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +000089 echo main updated >file1 &&
90 echo main new >file2 &&
91 echo main updated spaced >"spaced name" &&
92 echo main both added >both &&
93 echo main updated file12 >file12 &&
94 echo main updated file14 >file14 &&
95 echo main new sub >subdir/file3 &&
David Aguilar74578612014-10-15 01:35:17 -070096 (
97 cd submod &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +000098 echo main submodule >bar &&
David Aguilar74578612014-10-15 01:35:17 -070099 git add bar &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000100 git commit -m "Add bar on main" &&
101 git checkout -b submod-main
David Aguilar74578612014-10-15 01:35:17 -0700102 ) &&
103 git add file1 "spaced name" file12 file14 file2 subdir/file3 submod &&
104 git add both &&
105 git rm file11 &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000106 git commit -m "main updates" &&
Charles Baileyb9b50782009-01-30 23:20:10 +0000107
Richard Hansen157acfc2017-01-10 15:41:52 -0500108 git clean -fdx &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000109 git checkout -b order-file-start main &&
Richard Hansen157acfc2017-01-10 15:41:52 -0500110 echo start >a &&
111 echo start >b &&
112 git add a b &&
113 git commit -m start &&
114 git checkout -b order-file-side1 order-file-start &&
115 echo side1 >a &&
116 echo side1 >b &&
117 git add a b &&
118 git commit -m side1 &&
119 git checkout -b order-file-side2 order-file-start &&
120 echo side2 >a &&
121 echo side2 >b &&
122 git add a b &&
123 git commit -m side2 &&
124
David Aguilar74578612014-10-15 01:35:17 -0700125 git config merge.tool mytool &&
126 git config mergetool.mytool.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" &&
127 git config mergetool.mytool.trustExitCode true &&
128 git config mergetool.mybase.cmd "cat \"\$BASE\" >\"\$MERGED\"" &&
129 git config mergetool.mybase.trustExitCode true
Charles Bailey05e934b2008-02-21 23:31:56 +0000130'
131
132test_expect_success 'custom mergetool' '
Richard Hansenc3ad3122017-01-10 15:41:55 -0500133 test_when_finished "git reset --hard" &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500134 git checkout -b test$test_count branch1 &&
David Aguilar74578612014-10-15 01:35:17 -0700135 git submodule update -N &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000136 test_must_fail git merge main &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200137 yes "" | git mergetool both &&
138 yes "" | git mergetool file1 file1 &&
139 yes "" | git mergetool file2 "spaced name" &&
140 yes "" | git mergetool subdir/file3 &&
141 yes "d" | git mergetool file11 &&
142 yes "d" | git mergetool file12 &&
143 yes "l" | git mergetool submod &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000144 echo "main updated" >expect &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200145 test_cmp expect file1 &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000146 echo "main new" >expect &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200147 test_cmp expect file2 &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000148 echo "main new sub" >expect &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200149 test_cmp expect subdir/file3 &&
150 echo "branch1 submodule" >expect &&
151 test_cmp expect submod/bar &&
David Aguilar74578612014-10-15 01:35:17 -0700152 git commit -m "branch1 resolved with mergetool"
Charles Bailey0ec7b6c2009-01-21 22:57:48 +0000153'
154
Denton Liu57d93c12019-04-24 15:46:59 -0700155test_expect_success 'gui mergetool' '
156 test_config merge.guitool myguitool &&
157 test_config mergetool.myguitool.cmd "(printf \"gui \" && cat \"\$REMOTE\") >\"\$MERGED\"" &&
158 test_config mergetool.myguitool.trustExitCode true &&
159 test_when_finished "git reset --hard" &&
160 git checkout -b test$test_count branch1 &&
161 git submodule update -N &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000162 test_must_fail git merge main &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200163 yes "" | git mergetool --gui both &&
164 yes "" | git mergetool -g file1 file1 &&
165 yes "" | git mergetool --gui file2 "spaced name" &&
166 yes "" | git mergetool --gui subdir/file3 &&
167 yes "d" | git mergetool --gui file11 &&
168 yes "d" | git mergetool --gui file12 &&
169 yes "l" | git mergetool --gui submod &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000170 echo "gui main updated" >expect &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200171 test_cmp expect file1 &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000172 echo "gui main new" >expect &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200173 test_cmp expect file2 &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000174 echo "gui main new sub" >expect &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200175 test_cmp expect subdir/file3 &&
176 echo "branch1 submodule" >expect &&
177 test_cmp expect submod/bar &&
Denton Liu57d93c12019-04-24 15:46:59 -0700178 git commit -m "branch1 resolved with mergetool"
179'
180
Denton Liu60aced32019-04-29 02:21:14 -0400181test_expect_success 'gui mergetool without merge.guitool set falls back to merge.tool' '
182 test_when_finished "git reset --hard" &&
183 git checkout -b test$test_count branch1 &&
184 git submodule update -N &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000185 test_must_fail git merge main &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200186 yes "" | git mergetool --gui both &&
187 yes "" | git mergetool -g file1 file1 &&
188 yes "" | git mergetool --gui file2 "spaced name" &&
189 yes "" | git mergetool --gui subdir/file3 &&
190 yes "d" | git mergetool --gui file11 &&
191 yes "d" | git mergetool --gui file12 &&
192 yes "l" | git mergetool --gui submod &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000193 echo "main updated" >expect &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200194 test_cmp expect file1 &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000195 echo "main new" >expect &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200196 test_cmp expect file2 &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000197 echo "main new sub" >expect &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200198 test_cmp expect subdir/file3 &&
199 echo "branch1 submodule" >expect &&
200 test_cmp expect submod/bar &&
Denton Liu60aced32019-04-29 02:21:14 -0400201 git commit -m "branch1 resolved with mergetool"
202'
203
Charles Bailey0ec7b6c2009-01-21 22:57:48 +0000204test_expect_success 'mergetool crlf' '
Richard Hansen614eb272017-01-10 15:41:53 -0500205 test_when_finished "git reset --hard" &&
206 # This test_config line must go after the above reset line so that
207 # core.autocrlf is unconfigured before reset runs. (The
208 # test_config command uses test_when_finished internally and
209 # test_when_finished is LIFO.)
David Aguilarf9e43082014-10-15 01:35:20 -0700210 test_config core.autocrlf true &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500211 git checkout -b test$test_count branch1 &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000212 test_must_fail git merge main &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200213 yes "" | git mergetool file1 &&
214 yes "" | git mergetool file2 &&
215 yes "" | git mergetool "spaced name" &&
216 yes "" | git mergetool both &&
217 yes "" | git mergetool subdir/file3 &&
218 yes "d" | git mergetool file11 &&
219 yes "d" | git mergetool file12 &&
220 yes "r" | git mergetool submod &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000221 test "$(printf x | cat file1 -)" = "$(printf "main updated\r\nx")" &&
222 test "$(printf x | cat file2 -)" = "$(printf "main new\r\nx")" &&
223 test "$(printf x | cat subdir/file3 -)" = "$(printf "main new sub\r\nx")" &&
David Aguilar74578612014-10-15 01:35:17 -0700224 git submodule update -N &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000225 echo "main submodule" >expect &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200226 test_cmp expect submod/bar &&
Richard Hansen614eb272017-01-10 15:41:53 -0500227 git commit -m "branch1 resolved with mergetool - autocrlf"
Charles Bailey05e934b2008-02-21 23:31:56 +0000228'
229
Charles Baileyff4a1852009-01-30 23:20:11 +0000230test_expect_success 'mergetool in subdir' '
Richard Hansenc3ad3122017-01-10 15:41:55 -0500231 test_when_finished "git reset --hard" &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500232 git checkout -b test$test_count branch1 &&
David Aguilar74578612014-10-15 01:35:17 -0700233 git submodule update -N &&
234 (
235 cd subdir &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000236 test_must_fail git merge main &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200237 yes "" | git mergetool file3 &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000238 echo "main new sub" >expect &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200239 test_cmp expect file3
David Aguilar74578612014-10-15 01:35:17 -0700240 )
Charles Baileyb9b50782009-01-30 23:20:10 +0000241'
242
David Aguilarbb0a4842010-08-17 02:22:46 -0700243test_expect_success 'mergetool on file in parent dir' '
Richard Hansenc3ad3122017-01-10 15:41:55 -0500244 test_when_finished "git reset --hard" &&
Richard Hansenfef6c062017-01-10 15:41:58 -0500245 git checkout -b test$test_count branch1 &&
Richard Hansenb696ac92017-01-10 15:41:54 -0500246 git submodule update -N &&
David Aguilar74578612014-10-15 01:35:17 -0700247 (
248 cd subdir &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000249 test_must_fail git merge main &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200250 yes "" | git mergetool file3 &&
251 yes "" | git mergetool ../file1 &&
252 yes "" | git mergetool ../file2 ../spaced\ name &&
253 yes "" | git mergetool ../both &&
254 yes "d" | git mergetool ../file11 &&
255 yes "d" | git mergetool ../file12 &&
256 yes "l" | git mergetool ../submod &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000257 echo "main updated" >expect &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200258 test_cmp expect ../file1 &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000259 echo "main new" >expect &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200260 test_cmp expect ../file2 &&
261 echo "branch1 submodule" >expect &&
262 test_cmp expect ../submod/bar &&
David Aguilar74578612014-10-15 01:35:17 -0700263 git commit -m "branch1 resolved with mergetool - subdir"
264 )
David Aguilarbb0a4842010-08-17 02:22:46 -0700265'
266
267test_expect_success 'mergetool skips autoresolved' '
Richard Hansen614eb272017-01-10 15:41:53 -0500268 test_when_finished "git reset --hard" &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500269 git checkout -b test$test_count branch1 &&
David Aguilar74578612014-10-15 01:35:17 -0700270 git submodule update -N &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000271 test_must_fail git merge main &&
David Aguilar74578612014-10-15 01:35:17 -0700272 test -n "$(git ls-files -u)" &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200273 yes "d" | git mergetool file11 &&
274 yes "d" | git mergetool file12 &&
275 yes "l" | git mergetool submod &&
David Aguilar74578612014-10-15 01:35:17 -0700276 output="$(git mergetool --no-prompt)" &&
Richard Hansen614eb272017-01-10 15:41:53 -0500277 test "$output" = "No files need merging"
David Aguilarbb0a4842010-08-17 02:22:46 -0700278'
279
Richard Hansenb9ebb652017-01-10 15:42:00 -0500280test_expect_success 'mergetool merges all from subdir (rerere disabled)' '
Richard Hansenc3ad3122017-01-10 15:41:55 -0500281 test_when_finished "git reset --hard" &&
Richard Hansenfef6c062017-01-10 15:41:58 -0500282 git checkout -b test$test_count branch1 &&
John Keeping1a9a23e2015-09-05 14:12:45 +0100283 test_config rerere.enabled false &&
David Aguilar74578612014-10-15 01:35:17 -0700284 (
285 cd subdir &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000286 test_must_fail git merge main &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200287 yes "r" | git mergetool ../submod &&
288 yes "d" "d" | git mergetool --no-prompt &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000289 echo "main updated" >expect &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200290 test_cmp expect ../file1 &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000291 echo "main new" >expect &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200292 test_cmp expect ../file2 &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000293 echo "main new sub" >expect &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200294 test_cmp expect file3 &&
David Aguilar74578612014-10-15 01:35:17 -0700295 ( cd .. && git submodule update -N ) &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000296 echo "main submodule" >expect &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200297 test_cmp expect ../submod/bar &&
David Aguilar74578612014-10-15 01:35:17 -0700298 git commit -m "branch2 resolved by mergetool from subdir"
299 )
David Aguilarbb0a4842010-08-17 02:22:46 -0700300'
Charles Baileyb9b50782009-01-30 23:20:10 +0000301
Richard Hansend0e0cfe2017-01-10 15:42:02 -0500302test_expect_success 'mergetool merges all from subdir (rerere enabled)' '
Richard Hansenb9ebb652017-01-10 15:42:00 -0500303 test_when_finished "git reset --hard" &&
304 git checkout -b test$test_count branch1 &&
David Aguilarf9e43082014-10-15 01:35:20 -0700305 test_config rerere.enabled true &&
David Aguilar74578612014-10-15 01:35:17 -0700306 rm -rf .git/rr-cache &&
Richard Hansenb9ebb652017-01-10 15:42:00 -0500307 (
308 cd subdir &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000309 test_must_fail git merge main &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200310 yes "r" | git mergetool ../submod &&
311 yes "d" "d" | git mergetool --no-prompt &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000312 echo "main updated" >expect &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200313 test_cmp expect ../file1 &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000314 echo "main new" >expect &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200315 test_cmp expect ../file2 &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000316 echo "main new sub" >expect &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200317 test_cmp expect file3 &&
Richard Hansenb9ebb652017-01-10 15:42:00 -0500318 ( cd .. && git submodule update -N ) &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000319 echo "main submodule" >expect &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200320 test_cmp expect ../submod/bar &&
Richard Hansenb9ebb652017-01-10 15:42:00 -0500321 git commit -m "branch2 resolved by mergetool from subdir"
322 )
323'
324
Martin von Zweigbergk2f59c942011-02-16 05:47:45 -0500325test_expect_success 'mergetool skips resolved paths when rerere is active' '
Richard Hansen614eb272017-01-10 15:41:53 -0500326 test_when_finished "git reset --hard" &&
David Aguilar74578612014-10-15 01:35:17 -0700327 test_config rerere.enabled true &&
328 rm -rf .git/rr-cache &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500329 git checkout -b test$test_count branch1 &&
David Aguilar74578612014-10-15 01:35:17 -0700330 git submodule update -N &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000331 test_must_fail git merge main &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200332 yes "l" | git mergetool --no-prompt submod &&
333 yes "d" "d" | git mergetool --no-prompt &&
David Aguilar74578612014-10-15 01:35:17 -0700334 git submodule update -N &&
335 output="$(yes "n" | git mergetool --no-prompt)" &&
Richard Hansen614eb272017-01-10 15:41:53 -0500336 test "$output" = "No files need merging"
Martin von Zweigbergk2f59c942011-02-16 05:47:45 -0500337'
338
Phil Hord743bf6d2012-07-10 18:52:28 -0400339test_expect_success 'conflicted stash sets up rerere' '
Richard Hansenc3ad3122017-01-10 15:41:55 -0500340 test_when_finished "git reset --hard" &&
David Aguilarf9e43082014-10-15 01:35:20 -0700341 test_config rerere.enabled true &&
David Aguilar74578612014-10-15 01:35:17 -0700342 git checkout stash1 &&
343 echo "Conflicting stash content" >file11 &&
344 git stash &&
Phil Hord79dc2d02012-07-10 18:52:27 -0400345
David Aguilar74578612014-10-15 01:35:17 -0700346 git checkout --detach stash2 &&
347 test_must_fail git stash apply &&
Phil Hord79dc2d02012-07-10 18:52:27 -0400348
David Aguilar74578612014-10-15 01:35:17 -0700349 test -n "$(git ls-files -u)" &&
350 conflicts="$(git rerere remaining)" &&
351 test "$conflicts" = "file11" &&
352 output="$(git mergetool --no-prompt)" &&
353 test "$output" != "No files need merging" &&
Phil Hord79dc2d02012-07-10 18:52:27 -0400354
David Aguilar74578612014-10-15 01:35:17 -0700355 git commit -am "save the stash resolution" &&
Phil Hord79dc2d02012-07-10 18:52:27 -0400356
David Aguilar74578612014-10-15 01:35:17 -0700357 git reset --hard stash2 &&
358 test_must_fail git stash apply &&
Phil Hord79dc2d02012-07-10 18:52:27 -0400359
David Aguilar74578612014-10-15 01:35:17 -0700360 test -n "$(git ls-files -u)" &&
361 conflicts="$(git rerere remaining)" &&
362 test -z "$conflicts" &&
363 output="$(git mergetool --no-prompt)" &&
364 test "$output" = "No files need merging"
Phil Hord79dc2d02012-07-10 18:52:27 -0400365'
366
Jonathon Mah3e8e6912011-09-15 19:12:10 -0700367test_expect_success 'mergetool takes partial path' '
Richard Hansen614eb272017-01-10 15:41:53 -0500368 test_when_finished "git reset --hard" &&
David Aguilarf9e43082014-10-15 01:35:20 -0700369 test_config rerere.enabled false &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500370 git checkout -b test$test_count branch1 &&
David Aguilar74578612014-10-15 01:35:17 -0700371 git submodule update -N &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000372 test_must_fail git merge main &&
Jonathon Mah3e8e6912011-09-15 19:12:10 -0700373
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200374 yes "" | git mergetool subdir &&
Jonathon Mah3e8e6912011-09-15 19:12:10 -0700375
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000376 echo "main new sub" >expect &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200377 test_cmp expect subdir/file3
Jonathon Mah3e8e6912011-09-15 19:12:10 -0700378'
379
David Aguilarfaaab8d2016-03-09 23:13:58 -0800380test_expect_success 'mergetool delete/delete conflict' '
Richard Hansenbd9714f2017-01-10 15:41:59 -0500381 test_when_finished "git reset --hard" &&
Richard Hansen61b76d22017-01-10 15:41:57 -0500382 git checkout -b test$test_count move-to-c &&
David Aguilarfaaab8d2016-03-09 23:13:58 -0800383 test_must_fail git merge move-to-b &&
384 echo d | git mergetool a/a/file.txt &&
385 ! test -f a/a/file.txt &&
Richard Hansenbd9714f2017-01-10 15:41:59 -0500386 git reset --hard &&
David Aguilarfaaab8d2016-03-09 23:13:58 -0800387 test_must_fail git merge move-to-b &&
388 echo m | git mergetool a/a/file.txt &&
389 test -f b/b/file.txt &&
Richard Hansenbd9714f2017-01-10 15:41:59 -0500390 git reset --hard &&
David Aguilarfaaab8d2016-03-09 23:13:58 -0800391 test_must_fail git merge move-to-b &&
392 ! echo a | git mergetool a/a/file.txt &&
Richard Hansen614eb272017-01-10 15:41:53 -0500393 ! test -f a/a/file.txt
David Aguilarfaaab8d2016-03-09 23:13:58 -0800394'
395
396test_expect_success 'mergetool produces no errors when keepBackup is used' '
Richard Hansenbd9714f2017-01-10 15:41:59 -0500397 test_when_finished "git reset --hard" &&
Richard Hansenfef6c062017-01-10 15:41:58 -0500398 git checkout -b test$test_count move-to-c &&
David Aguilarfaaab8d2016-03-09 23:13:58 -0800399 test_config mergetool.keepBackup true &&
400 test_must_fail git merge move-to-b &&
David Aguilarfaaab8d2016-03-09 23:13:58 -0800401 echo d | git mergetool a/a/file.txt 2>actual &&
SZEDER Gábor1c5e94f2018-08-19 23:57:25 +0200402 test_must_be_empty actual &&
Richard Hansen614eb272017-01-10 15:41:53 -0500403 ! test -d a
David Aguilara2986042016-03-09 23:13:59 -0800404'
405
406test_expect_success 'mergetool honors tempfile config for deleted files' '
Richard Hansenbd9714f2017-01-10 15:41:59 -0500407 test_when_finished "git reset --hard" &&
Richard Hansenfef6c062017-01-10 15:41:58 -0500408 git checkout -b test$test_count move-to-c &&
David Aguilara2986042016-03-09 23:13:59 -0800409 test_config mergetool.keepTemporaries false &&
410 test_must_fail git merge move-to-b &&
411 echo d | git mergetool a/a/file.txt &&
Richard Hansen614eb272017-01-10 15:41:53 -0500412 ! test -d a
David Aguilara2986042016-03-09 23:13:59 -0800413'
414
415test_expect_success 'mergetool keeps tempfiles when aborting delete/delete' '
Richard Hansenbd9714f2017-01-10 15:41:59 -0500416 test_when_finished "git reset --hard" &&
Richard Hansen614eb272017-01-10 15:41:53 -0500417 test_when_finished "git clean -fdx" &&
Richard Hansenfef6c062017-01-10 15:41:58 -0500418 git checkout -b test$test_count move-to-c &&
David Aguilara2986042016-03-09 23:13:59 -0800419 test_config mergetool.keepTemporaries true &&
420 test_must_fail git merge move-to-b &&
Eric Sunshine0590ff22018-07-01 20:23:42 -0400421 ! test_write_lines a n | git mergetool a/a/file.txt &&
David Aguilara2986042016-03-09 23:13:59 -0800422 test -d a/a &&
423 cat >expect <<-\EOF &&
424 file_BASE_.txt
425 file_LOCAL_.txt
426 file_REMOTE_.txt
427 EOF
428 ls -1 a/a | sed -e "s/[0-9]*//g" >actual &&
Richard Hansen614eb272017-01-10 15:41:53 -0500429 test_cmp expect actual
David Aguilarfaaab8d2016-03-09 23:13:58 -0800430'
431
Jonathon Mahff7f0892011-04-13 03:00:48 -0700432test_expect_success 'deleted vs modified submodule' '
Richard Hansenbd9714f2017-01-10 15:41:59 -0500433 test_when_finished "git reset --hard" &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500434 git checkout -b test$test_count branch1 &&
David Aguilar74578612014-10-15 01:35:17 -0700435 git submodule update -N &&
436 mv submod submod-movedaside &&
437 git rm --cached submod &&
438 git commit -m "Submodule deleted from branch" &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500439 git checkout -b test$test_count.a test$test_count &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000440 test_must_fail git merge main &&
David Aguilar74578612014-10-15 01:35:17 -0700441 test -n "$(git ls-files -u)" &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200442 yes "" | git mergetool file1 file2 spaced\ name subdir/file3 &&
443 yes "" | git mergetool both &&
444 yes "d" | git mergetool file11 file12 &&
445 yes "r" | git mergetool submod &&
David Aguilar74578612014-10-15 01:35:17 -0700446 rmdir submod && mv submod-movedaside submod &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200447 echo "branch1 submodule" >expect &&
448 test_cmp expect submod/bar &&
David Aguilar74578612014-10-15 01:35:17 -0700449 git submodule update -N &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000450 echo "main submodule" >expect &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200451 test_cmp expect submod/bar &&
David Aguilar74578612014-10-15 01:35:17 -0700452 output="$(git mergetool --no-prompt)" &&
453 test "$output" = "No files need merging" &&
454 git commit -m "Merge resolved by keeping module" &&
Jonathon Mahff7f0892011-04-13 03:00:48 -0700455
David Aguilar74578612014-10-15 01:35:17 -0700456 mv submod submod-movedaside &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500457 git checkout -b test$test_count.b test$test_count &&
David Aguilar74578612014-10-15 01:35:17 -0700458 git submodule update -N &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000459 test_must_fail git merge main &&
David Aguilar74578612014-10-15 01:35:17 -0700460 test -n "$(git ls-files -u)" &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200461 yes "" | git mergetool file1 file2 spaced\ name subdir/file3 &&
462 yes "" | git mergetool both &&
463 yes "d" | git mergetool file11 file12 &&
464 yes "l" | git mergetool submod &&
David Aguilar74578612014-10-15 01:35:17 -0700465 test ! -e submod &&
466 output="$(git mergetool --no-prompt)" &&
467 test "$output" = "No files need merging" &&
468 git commit -m "Merge resolved by deleting module" &&
Jonathon Mahff7f0892011-04-13 03:00:48 -0700469
David Aguilar74578612014-10-15 01:35:17 -0700470 mv submod-movedaside submod &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000471 git checkout -b test$test_count.c main &&
David Aguilar74578612014-10-15 01:35:17 -0700472 git submodule update -N &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500473 test_must_fail git merge test$test_count &&
David Aguilar74578612014-10-15 01:35:17 -0700474 test -n "$(git ls-files -u)" &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200475 yes "" | git mergetool file1 file2 spaced\ name subdir/file3 &&
476 yes "" | git mergetool both &&
477 yes "d" | git mergetool file11 file12 &&
478 yes "r" | git mergetool submod &&
David Aguilar74578612014-10-15 01:35:17 -0700479 test ! -e submod &&
480 test -d submod.orig &&
481 git submodule update -N &&
482 output="$(git mergetool --no-prompt)" &&
483 test "$output" = "No files need merging" &&
484 git commit -m "Merge resolved by deleting module" &&
485 mv submod.orig submod &&
Jonathon Mahff7f0892011-04-13 03:00:48 -0700486
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000487 git checkout -b test$test_count.d main &&
David Aguilar74578612014-10-15 01:35:17 -0700488 git submodule update -N &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500489 test_must_fail git merge test$test_count &&
David Aguilar74578612014-10-15 01:35:17 -0700490 test -n "$(git ls-files -u)" &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200491 yes "" | git mergetool file1 file2 spaced\ name subdir/file3 &&
492 yes "" | git mergetool both &&
493 yes "d" | git mergetool file11 file12 &&
494 yes "l" | git mergetool submod &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000495 echo "main submodule" >expect &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200496 test_cmp expect submod/bar &&
David Aguilar74578612014-10-15 01:35:17 -0700497 git submodule update -N &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000498 echo "main submodule" >expect &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200499 test_cmp expect submod/bar &&
David Aguilar74578612014-10-15 01:35:17 -0700500 output="$(git mergetool --no-prompt)" &&
501 test "$output" = "No files need merging" &&
Richard Hansen614eb272017-01-10 15:41:53 -0500502 git commit -m "Merge resolved by keeping module"
Jonathon Mahff7f0892011-04-13 03:00:48 -0700503'
504
505test_expect_success 'file vs modified submodule' '
Richard Hansenc3ad3122017-01-10 15:41:55 -0500506 test_when_finished "git reset --hard" &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500507 git checkout -b test$test_count branch1 &&
David Aguilar74578612014-10-15 01:35:17 -0700508 git submodule update -N &&
509 mv submod submod-movedaside &&
510 git rm --cached submod &&
511 echo not a submodule >submod &&
512 git add submod &&
513 git commit -m "Submodule path becomes file" &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500514 git checkout -b test$test_count.a branch1 &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000515 test_must_fail git merge main &&
David Aguilar74578612014-10-15 01:35:17 -0700516 test -n "$(git ls-files -u)" &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200517 yes "" | git mergetool file1 file2 spaced\ name subdir/file3 &&
518 yes "" | git mergetool both &&
519 yes "d" | git mergetool file11 file12 &&
520 yes "r" | git mergetool submod &&
David Aguilar74578612014-10-15 01:35:17 -0700521 rmdir submod && mv submod-movedaside submod &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200522 echo "branch1 submodule" >expect &&
523 test_cmp expect submod/bar &&
David Aguilar74578612014-10-15 01:35:17 -0700524 git submodule update -N &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000525 echo "main submodule" >expect &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200526 test_cmp expect submod/bar &&
David Aguilar74578612014-10-15 01:35:17 -0700527 output="$(git mergetool --no-prompt)" &&
528 test "$output" = "No files need merging" &&
529 git commit -m "Merge resolved by keeping module" &&
Jonathon Mahff7f0892011-04-13 03:00:48 -0700530
David Aguilar74578612014-10-15 01:35:17 -0700531 mv submod submod-movedaside &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500532 git checkout -b test$test_count.b test$test_count &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000533 test_must_fail git merge main &&
David Aguilar74578612014-10-15 01:35:17 -0700534 test -n "$(git ls-files -u)" &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200535 yes "" | git mergetool file1 file2 spaced\ name subdir/file3 &&
536 yes "" | git mergetool both &&
537 yes "d" | git mergetool file11 file12 &&
Elijah Newrenef527782020-10-26 17:01:37 +0000538 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
539 then
540 yes "c" | git mergetool submod~HEAD &&
541 git rm submod &&
542 git mv submod~HEAD submod
543 else
544 yes "l" | git mergetool submod
545 fi &&
David Aguilar74578612014-10-15 01:35:17 -0700546 git submodule update -N &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200547 echo "not a submodule" >expect &&
548 test_cmp expect submod &&
David Aguilar74578612014-10-15 01:35:17 -0700549 output="$(git mergetool --no-prompt)" &&
550 test "$output" = "No files need merging" &&
551 git commit -m "Merge resolved by keeping file" &&
Jonathon Mahff7f0892011-04-13 03:00:48 -0700552
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000553 git checkout -b test$test_count.c main &&
David Aguilar74578612014-10-15 01:35:17 -0700554 rmdir submod && mv submod-movedaside submod &&
555 test ! -e submod.orig &&
556 git submodule update -N &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500557 test_must_fail git merge test$test_count &&
David Aguilar74578612014-10-15 01:35:17 -0700558 test -n "$(git ls-files -u)" &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200559 yes "" | git mergetool file1 file2 spaced\ name subdir/file3 &&
560 yes "" | git mergetool both &&
561 yes "d" | git mergetool file11 file12 &&
Elijah Newrenef527782020-10-26 17:01:37 +0000562 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
563 then
564 mv submod submod.orig &&
565 git rm --cached submod &&
566 yes "c" | git mergetool submod~test19 &&
567 git mv submod~test19 submod
568 else
569 yes "r" | git mergetool submod
570 fi &&
David Aguilar74578612014-10-15 01:35:17 -0700571 test -d submod.orig &&
572 git submodule update -N &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200573 echo "not a submodule" >expect &&
574 test_cmp expect submod &&
David Aguilar74578612014-10-15 01:35:17 -0700575 output="$(git mergetool --no-prompt)" &&
576 test "$output" = "No files need merging" &&
577 git commit -m "Merge resolved by keeping file" &&
Jonathon Mahff7f0892011-04-13 03:00:48 -0700578
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000579 git checkout -b test$test_count.d main &&
David Aguilar74578612014-10-15 01:35:17 -0700580 rmdir submod && mv submod.orig submod &&
581 git submodule update -N &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500582 test_must_fail git merge test$test_count &&
David Aguilar74578612014-10-15 01:35:17 -0700583 test -n "$(git ls-files -u)" &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200584 yes "" | git mergetool file1 file2 spaced\ name subdir/file3 &&
585 yes "" | git mergetool both &&
586 yes "d" | git mergetool file11 file12 &&
587 yes "l" | git mergetool submod &&
Elijah Newrenef527782020-10-26 17:01:37 +0000588 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
589 then
590 yes "d" | git mergetool submod~test19
591 fi &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000592 echo "main submodule" >expect &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200593 test_cmp expect submod/bar &&
David Aguilar74578612014-10-15 01:35:17 -0700594 git submodule update -N &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000595 echo "main submodule" >expect &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200596 test_cmp expect submod/bar &&
David Aguilar74578612014-10-15 01:35:17 -0700597 output="$(git mergetool --no-prompt)" &&
598 test "$output" = "No files need merging" &&
599 git commit -m "Merge resolved by keeping module"
Jonathon Mahff7f0892011-04-13 03:00:48 -0700600'
601
602test_expect_success 'submodule in subdirectory' '
Richard Hansenc3ad3122017-01-10 15:41:55 -0500603 test_when_finished "git reset --hard" &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500604 git checkout -b test$test_count branch1 &&
David Aguilar74578612014-10-15 01:35:17 -0700605 git submodule update -N &&
Jonathon Mahff7f0892011-04-13 03:00:48 -0700606 (
David Aguilar74578612014-10-15 01:35:17 -0700607 cd subdir &&
608 test_create_repo subdir_module &&
609 (
610 cd subdir_module &&
611 : >file15 &&
612 git add file15 &&
613 git commit -m "add initial versions"
614 )
615 ) &&
Richard Hansen614eb272017-01-10 15:41:53 -0500616 test_when_finished "rm -rf subdir/subdir_module" &&
Ævar Arnfjörð Bjarmason23fb3282022-11-16 00:40:14 +0100617 git submodule add file:///dev/null subdir/subdir_module &&
David Aguilar74578612014-10-15 01:35:17 -0700618 git add subdir/subdir_module &&
619 git commit -m "add submodule in subdirectory" &&
Jonathon Mahff7f0892011-04-13 03:00:48 -0700620
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500621 git checkout -b test$test_count.a test$test_count &&
David Aguilar74578612014-10-15 01:35:17 -0700622 git submodule update -N &&
623 (
Jonathon Mahff7f0892011-04-13 03:00:48 -0700624 cd subdir/subdir_module &&
David Aguilar74578612014-10-15 01:35:17 -0700625 git checkout -b super10.a &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500626 echo test$test_count.a >file15 &&
David Aguilar74578612014-10-15 01:35:17 -0700627 git add file15 &&
628 git commit -m "on branch 10.a"
629 ) &&
630 git add subdir/subdir_module &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500631 git commit -m "change submodule in subdirectory on test$test_count.a" &&
Jonathon Mahff7f0892011-04-13 03:00:48 -0700632
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500633 git checkout -b test$test_count.b test$test_count &&
David Aguilar74578612014-10-15 01:35:17 -0700634 git submodule update -N &&
635 (
636 cd subdir/subdir_module &&
637 git checkout -b super10.b &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500638 echo test$test_count.b >file15 &&
David Aguilar74578612014-10-15 01:35:17 -0700639 git add file15 &&
640 git commit -m "on branch 10.b"
641 ) &&
642 git add subdir/subdir_module &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500643 git commit -m "change submodule in subdirectory on test$test_count.b" &&
Jonathon Mahff7f0892011-04-13 03:00:48 -0700644
Denton Liue9d309e2019-04-24 15:46:57 -0700645 test_must_fail git merge test$test_count.a &&
David Aguilar74578612014-10-15 01:35:17 -0700646 (
647 cd subdir &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200648 yes "l" | git mergetool subdir_module
David Aguilar74578612014-10-15 01:35:17 -0700649 ) &&
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 submodule update -N &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200653 echo "test$test_count.b" >expect &&
654 test_cmp expect subdir/subdir_module/file15 &&
David Aguilar74578612014-10-15 01:35:17 -0700655 git reset --hard &&
656 git submodule update -N &&
Jonathon Mahff7f0892011-04-13 03:00:48 -0700657
Denton Liue9d309e2019-04-24 15:46:57 -0700658 test_must_fail git merge test$test_count.a &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200659 yes "r" | git mergetool subdir/subdir_module &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200660 echo "test$test_count.b" >expect &&
661 test_cmp expect subdir/subdir_module/file15 &&
David Aguilar74578612014-10-15 01:35:17 -0700662 git submodule update -N &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200663 echo "test$test_count.a" >expect &&
664 test_cmp expect subdir/subdir_module/file15 &&
Richard Hansen614eb272017-01-10 15:41:53 -0500665 git commit -m "branch1 resolved with mergetool"
Jonathon Mahff7f0892011-04-13 03:00:48 -0700666'
667
668test_expect_success 'directory vs modified submodule' '
Richard Hansenc3ad3122017-01-10 15:41:55 -0500669 test_when_finished "git reset --hard" &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500670 git checkout -b test$test_count branch1 &&
David Aguilar74578612014-10-15 01:35:17 -0700671 mv submod submod-movedaside &&
672 git rm --cached submod &&
673 mkdir submod &&
674 echo not a submodule >submod/file16 &&
675 git add submod/file16 &&
676 git commit -m "Submodule path becomes directory" &&
Jonathon Mahff7f0892011-04-13 03:00:48 -0700677
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000678 test_must_fail git merge main &&
David Aguilar74578612014-10-15 01:35:17 -0700679 test -n "$(git ls-files -u)" &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200680 yes "l" | git mergetool submod &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200681 echo "not a submodule" >expect &&
682 test_cmp expect submod/file16 &&
David Aguilar74578612014-10-15 01:35:17 -0700683 rm -rf submod.orig &&
Jonathon Mahff7f0892011-04-13 03:00:48 -0700684
Richard Hansenbd9714f2017-01-10 15:41:59 -0500685 git reset --hard &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000686 test_must_fail git merge main &&
David Aguilar74578612014-10-15 01:35:17 -0700687 test -n "$(git ls-files -u)" &&
688 test ! -e submod.orig &&
Elijah Newrenef527782020-10-26 17:01:37 +0000689 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
690 then
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000691 yes "r" | git mergetool submod~main &&
Elijah Newrenef527782020-10-26 17:01:37 +0000692 git mv submod submod.orig &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000693 git mv submod~main submod
Elijah Newrenef527782020-10-26 17:01:37 +0000694 else
695 yes "r" | git mergetool submod
696 fi &&
David Aguilar74578612014-10-15 01:35:17 -0700697 test -d submod.orig &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200698 echo "not a submodule" >expect &&
699 test_cmp expect submod.orig/file16 &&
David Aguilar74578612014-10-15 01:35:17 -0700700 rm -r submod.orig &&
701 mv submod-movedaside/.git submod &&
702 ( cd submod && git clean -f && git reset --hard ) &&
703 git submodule update -N &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000704 echo "main submodule" >expect &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200705 test_cmp expect submod/bar &&
Richard Hansenbd9714f2017-01-10 15:41:59 -0500706 git reset --hard &&
707 rm -rf submod-movedaside &&
Jonathon Mahff7f0892011-04-13 03:00:48 -0700708
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000709 git checkout -b test$test_count.c main &&
David Aguilar74578612014-10-15 01:35:17 -0700710 git submodule update -N &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500711 test_must_fail git merge test$test_count &&
David Aguilar74578612014-10-15 01:35:17 -0700712 test -n "$(git ls-files -u)" &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200713 yes "l" | git mergetool submod &&
David Aguilar74578612014-10-15 01:35:17 -0700714 git submodule update -N &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000715 echo "main submodule" >expect &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200716 test_cmp expect submod/bar &&
Jonathon Mahff7f0892011-04-13 03:00:48 -0700717
Richard Hansenbd9714f2017-01-10 15:41:59 -0500718 git reset --hard &&
David Aguilar74578612014-10-15 01:35:17 -0700719 git submodule update -N &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500720 test_must_fail git merge test$test_count &&
David Aguilar74578612014-10-15 01:35:17 -0700721 test -n "$(git ls-files -u)" &&
722 test ! -e submod.orig &&
Johannes Sixtb4a04c82019-06-10 10:58:58 +0200723 yes "r" | git mergetool submod &&
Johannes Sixte10dffd2019-06-12 18:33:46 +0200724 echo "not a submodule" >expect &&
725 test_cmp expect submod/file16 &&
Jonathon Mahff7f0892011-04-13 03:00:48 -0700726
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000727 git reset --hard main &&
David Aguilar74578612014-10-15 01:35:17 -0700728 ( cd submod && git clean -f && git reset --hard ) &&
729 git submodule update -N
Jonathon Mahff7f0892011-04-13 03:00:48 -0700730'
731
David Aguilarec245ba2012-01-19 23:47:35 -0800732test_expect_success 'file with no base' '
Richard Hansenbd9714f2017-01-10 15:41:59 -0500733 test_when_finished "git reset --hard" &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500734 git checkout -b test$test_count branch1 &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000735 test_must_fail git merge main &&
David Aguilar74578612014-10-15 01:35:17 -0700736 git mergetool --no-prompt --tool mybase -- both &&
Ævar Arnfjörð Bjarmasond3c67512018-07-27 17:48:11 +0000737 test_must_be_empty both
David Aguilarec245ba2012-01-19 23:47:35 -0800738'
739
David Aguilara427ef72012-09-25 00:48:11 -0700740test_expect_success 'custom commands override built-ins' '
Richard Hansenbd9714f2017-01-10 15:41:59 -0500741 test_when_finished "git reset --hard" &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500742 git checkout -b test$test_count branch1 &&
David Aguilarf9e43082014-10-15 01:35:20 -0700743 test_config mergetool.defaults.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" &&
744 test_config mergetool.defaults.trustExitCode true &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000745 test_must_fail git merge main &&
David Aguilar74578612014-10-15 01:35:17 -0700746 git mergetool --no-prompt --tool defaults -- both &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000747 echo main both added >expected &&
Stefan Beller9c5b2fa2017-10-06 12:00:06 -0700748 test_cmp expected both
David Aguilara427ef72012-09-25 00:48:11 -0700749'
750
David Aguilar688684e2014-10-15 01:35:19 -0700751test_expect_success 'filenames seen by tools start with ./' '
Richard Hansenbd9714f2017-01-10 15:41:59 -0500752 test_when_finished "git reset --hard" &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500753 git checkout -b test$test_count branch1 &&
David Aguilar688684e2014-10-15 01:35:19 -0700754 test_config mergetool.writeToTemp false &&
755 test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
756 test_config mergetool.myecho.trustExitCode true &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000757 test_must_fail git merge main &&
David Aguilar688684e2014-10-15 01:35:19 -0700758 git mergetool --no-prompt --tool myecho -- both >actual &&
Denton Liue9d309e2019-04-24 15:46:57 -0700759 grep ^\./both_LOCAL_ actual
David Aguilar688684e2014-10-15 01:35:19 -0700760'
761
Armin Kunaschikc578a092016-07-02 21:01:51 +0200762test_lazy_prereq MKTEMP '
763 tempdir=$(mktemp -d -t foo.XXXXXX) &&
Jeff Kingfa3142c2016-11-27 01:34:45 -0500764 test -d "$tempdir" &&
765 rmdir "$tempdir"
Armin Kunaschikc578a092016-07-02 21:01:51 +0200766'
767
768test_expect_success MKTEMP 'temporary filenames are used with mergetool.writeToTemp' '
Richard Hansenbd9714f2017-01-10 15:41:59 -0500769 test_when_finished "git reset --hard" &&
Richard Hansenecfdf0b2017-01-10 15:41:51 -0500770 git checkout -b test$test_count branch1 &&
David Aguilar688684e2014-10-15 01:35:19 -0700771 test_config mergetool.writeToTemp true &&
772 test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
773 test_config mergetool.myecho.trustExitCode true &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000774 test_must_fail git merge main &&
David Aguilar688684e2014-10-15 01:35:19 -0700775 git mergetool --no-prompt --tool myecho -- both >actual &&
Denton Liue9d309e2019-04-24 15:46:57 -0700776 ! grep ^\./both_LOCAL_ actual &&
777 grep /both_LOCAL_ actual
David Aguilar688684e2014-10-15 01:35:19 -0700778'
779
David Aguilar57937f72016-10-07 16:58:05 -0700780test_expect_success 'diff.orderFile configuration is honored' '
Richard Hansenbd9714f2017-01-10 15:41:59 -0500781 test_when_finished "git reset --hard" &&
Richard Hansen61b76d22017-01-10 15:41:57 -0500782 git checkout -b test$test_count order-file-side2 &&
David Aguilar57937f72016-10-07 16:58:05 -0700783 test_config diff.orderFile order-file &&
784 test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
785 test_config mergetool.myecho.trustExitCode true &&
786 echo b >order-file &&
787 echo a >>order-file &&
David Aguilar57937f72016-10-07 16:58:05 -0700788 test_must_fail git merge order-file-side1 &&
789 cat >expect <<-\EOF &&
790 Merging:
791 b
792 a
793 EOF
Richard Hansend0e0cfe2017-01-10 15:42:02 -0500794
795 # make sure "order-file" that is ambiguous between
796 # rev and path is understood correctly.
797 git branch order-file HEAD &&
798
David Aguilar57937f72016-10-07 16:58:05 -0700799 git mergetool --no-prompt --tool myecho >output &&
800 git grep --no-index -h -A2 Merging: output >actual &&
Richard Hansen614eb272017-01-10 15:41:53 -0500801 test_cmp expect actual
David Aguilar57937f72016-10-07 16:58:05 -0700802'
David Aguilar654311b2016-10-07 17:01:30 -0700803test_expect_success 'mergetool -Oorder-file is honored' '
Richard Hansenbd9714f2017-01-10 15:41:59 -0500804 test_when_finished "git reset --hard" &&
Richard Hansenfef6c062017-01-10 15:41:58 -0500805 git checkout -b test$test_count order-file-side2 &&
David Aguilar654311b2016-10-07 17:01:30 -0700806 test_config diff.orderFile order-file &&
807 test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
808 test_config mergetool.myecho.trustExitCode true &&
Richard Hansenb696ac92017-01-10 15:41:54 -0500809 echo b >order-file &&
810 echo a >>order-file &&
David Aguilar654311b2016-10-07 17:01:30 -0700811 test_must_fail git merge order-file-side1 &&
812 cat >expect <<-\EOF &&
813 Merging:
814 a
815 b
816 EOF
817 git mergetool -O/dev/null --no-prompt --tool myecho >output &&
818 git grep --no-index -h -A2 Merging: output >actual &&
819 test_cmp expect actual &&
Richard Hansenbd9714f2017-01-10 15:41:59 -0500820 git reset --hard &&
David Aguilar654311b2016-10-07 17:01:30 -0700821
822 git config --unset diff.orderFile &&
823 test_must_fail git merge order-file-side1 &&
824 cat >expect <<-\EOF &&
825 Merging:
826 b
827 a
828 EOF
829 git mergetool -Oorder-file --no-prompt --tool myecho >output &&
830 git grep --no-index -h -A2 Merging: output >actual &&
Richard Hansen614eb272017-01-10 15:41:53 -0500831 test_cmp expect actual
David Aguilar654311b2016-10-07 17:01:30 -0700832'
David Aguilar57937f72016-10-07 16:58:05 -0700833
Philippe Blain80f5a162021-01-07 01:09:05 +0000834test_expect_success 'mergetool --tool-help shows recognized tools' '
835 # Check a few known tools are correctly shown
836 git mergetool --tool-help >mergetools &&
837 grep vimdiff mergetools &&
838 grep vimdiff3 mergetools &&
839 grep gvimdiff2 mergetools &&
840 grep araxis mergetools &&
841 grep xxdiff mergetools &&
842 grep meld mergetools
843'
844
Seth House98ea3092021-02-09 13:07:10 -0700845test_expect_success 'mergetool hideResolved' '
846 test_config mergetool.hideResolved true &&
847 test_when_finished "git reset --hard" &&
Junio C Hamano78a26cb2021-02-17 17:21:41 -0800848 git checkout -b test${test_count}_b main &&
Seth House98ea3092021-02-09 13:07:10 -0700849 test_write_lines >file1 base "" a &&
850 git commit -a -m "base" &&
851 test_write_lines >file1 base "" c &&
852 git commit -a -m "remote update" &&
853 git checkout -b test${test_count}_a HEAD~ &&
854 test_write_lines >file1 local "" b &&
855 git commit -a -m "local update" &&
856 test_must_fail git merge test${test_count}_b &&
857 yes "" | git mergetool file1 &&
858 test_write_lines >expect local "" c &&
859 test_cmp expect file1 &&
860 git commit -m "test resolved with mergetool"
861'
862
Tao Klerks42943b92023-03-18 15:27:43 +0000863test_expect_success 'mergetool with guiDefault' '
864 test_config merge.guitool myguitool &&
865 test_config mergetool.myguitool.cmd "(printf \"gui \" && cat \"\$REMOTE\") >\"\$MERGED\"" &&
866 test_config mergetool.myguitool.trustExitCode true &&
867 test_when_finished "git reset --hard" &&
868 git checkout -b test$test_count branch1 &&
869 git submodule update -N &&
870 test_must_fail git merge main &&
871
872 test_config mergetool.guiDefault auto &&
873 DISPLAY=SOMETHING && export DISPLAY &&
874 yes "" | git mergetool both &&
875 yes "" | git mergetool file1 file1 &&
876
877 DISPLAY= && export DISPLAY &&
878 yes "" | git mergetool file2 "spaced name" &&
879
880 test_config mergetool.guiDefault true &&
881 yes "" | git mergetool subdir/file3 &&
882
883 yes "d" | git mergetool file11 &&
884 yes "d" | git mergetool file12 &&
885 yes "l" | git mergetool submod &&
886
887 echo "gui main updated" >expect &&
888 test_cmp expect file1 &&
889
890 echo "main new" >expect &&
891 test_cmp expect file2 &&
892
893 echo "gui main new sub" >expect &&
894 test_cmp expect subdir/file3 &&
895
896 echo "branch1 submodule" >expect &&
897 test_cmp expect submod/bar &&
898 git commit -m "branch1 resolved with mergetool"
899'
900
Charles Bailey05e934b2008-02-21 23:31:56 +0000901test_done