Code

Merge branch 'cb/maint-t5541-make-server-port-portable' into maint-1.7.8
[git.git] / t / t7610-mergetool.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2008 Charles Bailey
4 #
6 test_description='git mergetool
8 Testing basic merge tool invocation'
10 . ./test-lib.sh
12 # All the mergetool test work by checking out a temporary branch based
13 # off 'branch1' and then merging in master and checking the results of
14 # running mergetool
16 test_expect_success 'setup' '
17     git config rerere.enabled true &&
18     echo master >file1 &&
19     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" &&
37     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 change file11 >file11 &&
43     echo branch1 change file13 >file13 &&
44     echo branch1 sub >subdir/file3 &&
45     (
46         cd submod &&
47         echo branch1 submodule >bar &&
48         git add bar &&
49         git commit -m "Add bar on branch1" &&
50         git checkout -b submod-branch1
51     ) &&
52     git add file1 "spaced name" file11 file13 file2 subdir/file3 submod &&
53     git rm file12 &&
54     git commit -m "branch1 changes" &&
56     git checkout master &&
57     git submodule update -N &&
58     echo master updated >file1 &&
59     echo master new >file2 &&
60     echo master updated spaced >"spaced name" &&
61     echo master updated file12 >file12 &&
62     echo master updated file14 >file14 &&
63     echo master new sub >subdir/file3 &&
64     (
65         cd submod &&
66         echo master submodule >bar &&
67         git add bar &&
68         git commit -m "Add bar on master" &&
69         git checkout -b submod-master
70     ) &&
71     git add file1 "spaced name" file12 file14 file2 subdir/file3 submod &&
72     git rm file11 &&
73     git commit -m "master updates" &&
75     git config merge.tool mytool &&
76     git config mergetool.mytool.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" &&
77     git config mergetool.mytool.trustExitCode true
78 '
80 test_expect_success 'custom mergetool' '
81     git checkout -b test1 branch1 &&
82     git submodule update -N &&
83     test_must_fail git merge master >/dev/null 2>&1 &&
84     ( yes "" | git mergetool file1 file1 ) &&
85     ( yes "" | git mergetool file2 "spaced name" >/dev/null 2>&1 ) &&
86     ( yes "" | git mergetool subdir/file3 >/dev/null 2>&1 ) &&
87     ( yes "d" | git mergetool file11 >/dev/null 2>&1 ) &&
88     ( yes "d" | git mergetool file12 >/dev/null 2>&1 ) &&
89     ( yes "l" | git mergetool submod >/dev/null 2>&1 ) &&
90     test "$(cat file1)" = "master updated" &&
91     test "$(cat file2)" = "master new" &&
92     test "$(cat subdir/file3)" = "master new sub" &&
93     test "$(cat submod/bar)" = "branch1 submodule" &&
94     git commit -m "branch1 resolved with mergetool"
95 '
97 test_expect_success 'mergetool crlf' '
98     git config core.autocrlf true &&
99     git checkout -b test2 branch1 &&
100     test_must_fail git merge master >/dev/null 2>&1 &&
101     ( yes "" | git mergetool file1 >/dev/null 2>&1 ) &&
102     ( yes "" | git mergetool file2 >/dev/null 2>&1 ) &&
103     ( yes "" | git mergetool "spaced name" >/dev/null 2>&1 ) &&
104     ( yes "" | git mergetool subdir/file3 >/dev/null 2>&1 ) &&
105     ( yes "d" | git mergetool file11 >/dev/null 2>&1 ) &&
106     ( yes "d" | git mergetool file12 >/dev/null 2>&1 ) &&
107     ( yes "r" | git mergetool submod >/dev/null 2>&1 ) &&
108     test "$(printf x | cat file1 -)" = "$(printf "master updated\r\nx")" &&
109     test "$(printf x | cat file2 -)" = "$(printf "master new\r\nx")" &&
110     test "$(printf x | cat subdir/file3 -)" = "$(printf "master new sub\r\nx")" &&
111     git submodule update -N &&
112     test "$(cat submod/bar)" = "master submodule" &&
113     git commit -m "branch1 resolved with mergetool - autocrlf" &&
114     git config core.autocrlf false &&
115     git reset --hard
118 test_expect_success 'mergetool in subdir' '
119     git checkout -b test3 branch1 &&
120     git submodule update -N &&
121     (
122         cd subdir &&
123         test_must_fail git merge master >/dev/null 2>&1 &&
124         ( yes "" | git mergetool file3 >/dev/null 2>&1 ) &&
125         test "$(cat file3)" = "master new sub"
126     )
129 test_expect_success 'mergetool on file in parent dir' '
130     (
131         cd subdir &&
132         ( yes "" | git mergetool ../file1 >/dev/null 2>&1 ) &&
133         ( yes "" | git mergetool ../file2 ../spaced\ name >/dev/null 2>&1 ) &&
134         ( yes "d" | git mergetool ../file11 >/dev/null 2>&1 ) &&
135         ( yes "d" | git mergetool ../file12 >/dev/null 2>&1 ) &&
136         ( yes "l" | git mergetool ../submod >/dev/null 2>&1 ) &&
137         test "$(cat ../file1)" = "master updated" &&
138         test "$(cat ../file2)" = "master new" &&
139         test "$(cat ../submod/bar)" = "branch1 submodule" &&
140         git commit -m "branch1 resolved with mergetool - subdir"
141     )
144 test_expect_success 'mergetool skips autoresolved' '
145     git checkout -b test4 branch1 &&
146     git submodule update -N &&
147     test_must_fail git merge master &&
148     test -n "$(git ls-files -u)" &&
149     ( yes "d" | git mergetool file11 >/dev/null 2>&1 ) &&
150     ( yes "d" | git mergetool file12 >/dev/null 2>&1 ) &&
151     ( yes "l" | git mergetool submod >/dev/null 2>&1 ) &&
152     output="$(git mergetool --no-prompt)" &&
153     test "$output" = "No files need merging" &&
154     git reset --hard
157 test_expect_success 'mergetool merges all from subdir' '
158     (
159         cd subdir &&
160         git config rerere.enabled false &&
161         test_must_fail git merge master &&
162         ( yes "r" | git mergetool ../submod ) &&
163         ( yes "d" "d" | git mergetool --no-prompt ) &&
164         test "$(cat ../file1)" = "master updated" &&
165         test "$(cat ../file2)" = "master new" &&
166         test "$(cat file3)" = "master new sub" &&
167         ( cd .. && git submodule update -N ) &&
168         test "$(cat ../submod/bar)" = "master submodule" &&
169         git commit -m "branch2 resolved by mergetool from subdir"
170     )
173 test_expect_success 'mergetool skips resolved paths when rerere is active' '
174     git config rerere.enabled true &&
175     rm -rf .git/rr-cache &&
176     git checkout -b test5 branch1
177     git submodule update -N &&
178     test_must_fail git merge master >/dev/null 2>&1 &&
179     ( yes "l" | git mergetool --no-prompt submod >/dev/null 2>&1 ) &&
180     ( yes "d" "d" | git mergetool --no-prompt >/dev/null 2>&1 ) &&
181     git submodule update -N &&
182     output="$(yes "n" | git mergetool --no-prompt)" &&
183     test "$output" = "No files need merging" &&
184     git reset --hard
187 test_expect_success 'mergetool takes partial path' '
188     git config rerere.enabled false &&
189     git checkout -b test12 branch1 &&
190     git submodule update -N &&
191     test_must_fail git merge master &&
193     #shouldnt need these lines
194     #( yes "d" | git mergetool file11 >/dev/null 2>&1 ) &&
195     #( yes "d" | git mergetool file12 >/dev/null 2>&1 ) &&
196     #( yes "l" | git mergetool submod >/dev/null 2>&1 ) &&
197     #( yes "" | git mergetool file1 file2 >/dev/null 2>&1 ) &&
199     ( yes "" | git mergetool subdir ) &&
201     test "$(cat subdir/file3)" = "master new sub" &&
202     git reset --hard
205 test_expect_success 'deleted vs modified submodule' '
206     git checkout -b test6 branch1 &&
207     git submodule update -N &&
208     mv submod submod-movedaside &&
209     git rm submod &&
210     git commit -m "Submodule deleted from branch" &&
211     git checkout -b test6.a test6 &&
212     test_must_fail git merge master &&
213     test -n "$(git ls-files -u)" &&
214     ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
215     ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
216     ( yes "r" | git mergetool submod ) &&
217     rmdir submod && mv submod-movedaside submod &&
218     test "$(cat submod/bar)" = "branch1 submodule" &&
219     git submodule update -N &&
220     test "$(cat submod/bar)" = "master submodule" &&
221     output="$(git mergetool --no-prompt)" &&
222     test "$output" = "No files need merging" &&
223     git commit -m "Merge resolved by keeping module" &&
225     mv submod submod-movedaside &&
226     git checkout -b test6.b test6 &&
227     git submodule update -N &&
228     test_must_fail git merge master &&
229     test -n "$(git ls-files -u)" &&
230     ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
231     ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
232     ( yes "l" | git mergetool submod ) &&
233     test ! -e submod &&
234     output="$(git mergetool --no-prompt)" &&
235     test "$output" = "No files need merging" &&
236     git commit -m "Merge resolved by deleting module" &&
238     mv submod-movedaside submod &&
239     git checkout -b test6.c master &&
240     git submodule update -N &&
241     test_must_fail git merge test6 &&
242     test -n "$(git ls-files -u)" &&
243     ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
244     ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
245     ( yes "r" | git mergetool submod ) &&
246     test ! -e submod &&
247     test -d submod.orig &&
248     git submodule update -N &&
249     output="$(git mergetool --no-prompt)" &&
250     test "$output" = "No files need merging" &&
251     git commit -m "Merge resolved by deleting module" &&
252     mv submod.orig submod &&
254     git checkout -b test6.d master &&
255     git submodule update -N &&
256     test_must_fail git merge test6 &&
257     test -n "$(git ls-files -u)" &&
258     ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
259     ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
260     ( yes "l" | git mergetool submod ) &&
261     test "$(cat submod/bar)" = "master submodule" &&
262     git submodule update -N &&
263     test "$(cat submod/bar)" = "master submodule" &&
264     output="$(git mergetool --no-prompt)" &&
265     test "$output" = "No files need merging" &&
266     git commit -m "Merge resolved by keeping module" &&
267     git reset --hard HEAD
270 test_expect_success 'file vs modified submodule' '
271     git checkout -b test7 branch1 &&
272     git submodule update -N &&
273     mv submod submod-movedaside &&
274     git rm submod &&
275     echo not a submodule >submod &&
276     git add submod &&
277     git commit -m "Submodule path becomes file" &&
278     git checkout -b test7.a branch1 &&
279     test_must_fail git merge master &&
280     test -n "$(git ls-files -u)" &&
281     ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
282     ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
283     ( yes "r" | git mergetool submod ) &&
284     rmdir submod && mv submod-movedaside submod &&
285     test "$(cat submod/bar)" = "branch1 submodule" &&
286     git submodule update -N &&
287     test "$(cat submod/bar)" = "master submodule" &&
288     output="$(git mergetool --no-prompt)" &&
289     test "$output" = "No files need merging" &&
290     git commit -m "Merge resolved by keeping module" &&
292     mv submod submod-movedaside &&
293     git checkout -b test7.b test7 &&
294     test_must_fail git merge master &&
295     test -n "$(git ls-files -u)" &&
296     ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
297     ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
298     ( yes "l" | git mergetool submod ) &&
299     git submodule update -N &&
300     test "$(cat submod)" = "not a submodule" &&
301     output="$(git mergetool --no-prompt)" &&
302     test "$output" = "No files need merging" &&
303     git commit -m "Merge resolved by keeping file" &&
305     git checkout -b test7.c master &&
306     rmdir submod && mv submod-movedaside submod &&
307     test ! -e submod.orig &&
308     git submodule update -N &&
309     test_must_fail git merge test7 &&
310     test -n "$(git ls-files -u)" &&
311     ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
312     ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
313     ( yes "r" | git mergetool submod ) &&
314     test -d submod.orig &&
315     git submodule update -N &&
316     test "$(cat submod)" = "not a submodule" &&
317     output="$(git mergetool --no-prompt)" &&
318     test "$output" = "No files need merging" &&
319     git commit -m "Merge resolved by keeping file" &&
321     git checkout -b test7.d master &&
322     rmdir submod && mv submod.orig submod &&
323     git submodule update -N &&
324     test_must_fail git merge test7 &&
325     test -n "$(git ls-files -u)" &&
326     ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
327     ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
328     ( yes "l" | git mergetool submod ) &&
329     test "$(cat submod/bar)" = "master submodule" &&
330     git submodule update -N &&
331     test "$(cat submod/bar)" = "master submodule" &&
332     output="$(git mergetool --no-prompt)" &&
333     test "$output" = "No files need merging" &&
334     git commit -m "Merge resolved by keeping module"
337 test_expect_success 'submodule in subdirectory' '
338     git checkout -b test10 branch1 &&
339     git submodule update -N &&
340     (
341         cd subdir &&
342         test_create_repo subdir_module &&
343         (
344             cd subdir_module &&
345             : >file15 &&
346             git add file15 &&
347             git commit -m "add initial versions"
348         )
349     ) &&
350     git submodule add git://example.com/subsubmodule subdir/subdir_module &&
351     git add subdir/subdir_module &&
352     git commit -m "add submodule in subdirectory" &&
354     git checkout -b test10.a test10 &&
355     git submodule update -N &&
356     (
357         cd subdir/subdir_module &&
358         git checkout -b super10.a &&
359         echo test10.a >file15 &&
360         git add file15 &&
361         git commit -m "on branch 10.a"
362     ) &&
363     git add subdir/subdir_module &&
364     git commit -m "change submodule in subdirectory on test10.a" &&
366     git checkout -b test10.b test10 &&
367     git submodule update -N &&
368     (
369         cd subdir/subdir_module &&
370         git checkout -b super10.b &&
371         echo test10.b >file15 &&
372         git add file15 &&
373         git commit -m "on branch 10.b"
374     ) &&
375     git add subdir/subdir_module &&
376     git commit -m "change submodule in subdirectory on test10.b" &&
378     test_must_fail git merge test10.a >/dev/null 2>&1 &&
379     (
380         cd subdir &&
381         ( yes "l" | git mergetool subdir_module )
382     ) &&
383     test "$(cat subdir/subdir_module/file15)" = "test10.b" &&
384     git submodule update -N &&
385     test "$(cat subdir/subdir_module/file15)" = "test10.b" &&
386     git reset --hard &&
387     git submodule update -N &&
389     test_must_fail git merge test10.a >/dev/null 2>&1 &&
390     ( yes "r" | git mergetool subdir/subdir_module ) &&
391     test "$(cat subdir/subdir_module/file15)" = "test10.b" &&
392     git submodule update -N &&
393     test "$(cat subdir/subdir_module/file15)" = "test10.a" &&
394     git commit -m "branch1 resolved with mergetool" &&
395     rm -rf subdir/subdir_module
398 test_expect_success 'directory vs modified submodule' '
399     git checkout -b test11 branch1 &&
400     mv submod submod-movedaside &&
401     git rm submod &&
402     mkdir submod &&
403     echo not a submodule >submod/file16 &&
404     git add submod/file16 &&
405     git commit -m "Submodule path becomes directory" &&
407     test_must_fail git merge master &&
408     test -n "$(git ls-files -u)" &&
409     ( yes "l" | git mergetool submod ) &&
410     test "$(cat submod/file16)" = "not a submodule" &&
411     rm -rf submod.orig &&
413     git reset --hard >/dev/null 2>&1 &&
414     test_must_fail git merge master &&
415     test -n "$(git ls-files -u)" &&
416     test ! -e submod.orig &&
417     ( yes "r" | git mergetool submod ) &&
418     test -d submod.orig &&
419     test "$(cat submod.orig/file16)" = "not a submodule" &&
420     rm -r submod.orig &&
421     mv submod-movedaside/.git submod &&
422     ( cd submod && git clean -f && git reset --hard ) &&
423     git submodule update -N &&
424     test "$(cat submod/bar)" = "master submodule" &&
425     git reset --hard >/dev/null 2>&1 && rm -rf submod-movedaside &&
427     git checkout -b test11.c master &&
428     git submodule update -N &&
429     test_must_fail git merge test11 &&
430     test -n "$(git ls-files -u)" &&
431     ( yes "l" | git mergetool submod ) &&
432     git submodule update -N &&
433     test "$(cat submod/bar)" = "master submodule" &&
435     git reset --hard >/dev/null 2>&1 &&
436     git submodule update -N &&
437     test_must_fail git merge test11 &&
438     test -n "$(git ls-files -u)" &&
439     test ! -e submod.orig &&
440     ( yes "r" | git mergetool submod ) &&
441     test "$(cat submod/file16)" = "not a submodule" &&
443     git reset --hard master >/dev/null 2>&1 &&
444     ( cd submod && git clean -f && git reset --hard ) &&
445     git submodule update -N
448 test_done