]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7610-mergetool.sh
rerere "remaining"
[thirdparty/git.git] / t / t7610-mergetool.sh
CommitLineData
05e934bb
CB
1#!/bin/sh
2#
3# Copyright (c) 2008 Charles Bailey
4#
5
47a528ad 6test_description='git mergetool
05e934bb
CB
7
8Testing basic merge tool invocation'
9
10. ./test-lib.sh
11
b9b5078e
CB
12# All the mergetool test work by checking out a temporary branch based
13# off 'branch1' and then merging in master and checking the results of
14# running mergetool
15
05e934bb 16test_expect_success 'setup' '
bb0a484e 17 git config rerere.enabled true &&
05e934bb 18 echo master >file1 &&
b9b5078e
CB
19 mkdir subdir &&
20 echo master sub >subdir/file3 &&
21 git add file1 subdir/file3 &&
05e934bb 22 git commit -m "added file1" &&
b9b5078e 23
05e934bb
CB
24 git checkout -b branch1 master &&
25 echo branch1 change >file1 &&
26 echo branch1 newfile >file2 &&
b9b5078e
CB
27 echo branch1 sub >subdir/file3 &&
28 git add file1 file2 subdir/file3 &&
05e934bb 29 git commit -m "branch1 changes" &&
b9b5078e 30
05e934bb
CB
31 git checkout master &&
32 echo master updated >file1 &&
33 echo master new >file2 &&
b9b5078e
CB
34 echo master new sub >subdir/file3 &&
35 git add file1 file2 subdir/file3 &&
36 git commit -m "master updates" &&
05e934bb 37
05e934bb
CB
38 git config merge.tool mytool &&
39 git config mergetool.mytool.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" &&
b9b5078e
CB
40 git config mergetool.mytool.trustExitCode true
41'
42
43test_expect_success 'custom mergetool' '
44 git checkout -b test1 branch1 &&
d492b31c 45 test_must_fail git merge master >/dev/null 2>&1 &&
b9b5078e
CB
46 ( yes "" | git mergetool file1 >/dev/null 2>&1 ) &&
47 ( yes "" | git mergetool file2 >/dev/null 2>&1 ) &&
48 ( yes "" | git mergetool subdir/file3 >/dev/null 2>&1 ) &&
05e934bb
CB
49 test "$(cat file1)" = "master updated" &&
50 test "$(cat file2)" = "master new" &&
b9b5078e 51 test "$(cat subdir/file3)" = "master new sub" &&
0ec7b6c2
CB
52 git commit -m "branch1 resolved with mergetool"
53'
54
55test_expect_success 'mergetool crlf' '
56 git config core.autocrlf true &&
a48fcd83 57 git checkout -b test2 branch1 &&
0ec7b6c2 58 test_must_fail git merge master >/dev/null 2>&1 &&
b9b5078e
CB
59 ( yes "" | git mergetool file1 >/dev/null 2>&1 ) &&
60 ( yes "" | git mergetool file2 >/dev/null 2>&1 ) &&
61 ( yes "" | git mergetool subdir/file3 >/dev/null 2>&1 ) &&
0ec7b6c2
CB
62 test "$(printf x | cat file1 -)" = "$(printf "master updated\r\nx")" &&
63 test "$(printf x | cat file2 -)" = "$(printf "master new\r\nx")" &&
b9b5078e
CB
64 test "$(printf x | cat subdir/file3 -)" = "$(printf "master new sub\r\nx")" &&
65 git commit -m "branch1 resolved with mergetool - autocrlf" &&
66 git config core.autocrlf false &&
67 git reset --hard
68'
69
ff4a1855 70test_expect_success 'mergetool in subdir' '
25641fcd
BG
71 git checkout -b test3 branch1 &&
72 (
73 cd subdir &&
74 test_must_fail git merge master >/dev/null 2>&1 &&
75 ( yes "" | git mergetool file3 >/dev/null 2>&1 ) &&
76 test "$(cat file3)" = "master new sub"
77 )
05e934bb
CB
78'
79
bb0a484e 80test_expect_success 'mergetool on file in parent dir' '
25641fcd
BG
81 (
82 cd subdir &&
83 ( yes "" | git mergetool ../file1 >/dev/null 2>&1 ) &&
84 ( yes "" | git mergetool ../file2 >/dev/null 2>&1 ) &&
85 test "$(cat ../file1)" = "master updated" &&
86 test "$(cat ../file2)" = "master new" &&
87 git commit -m "branch1 resolved with mergetool - subdir"
88 )
bb0a484e
DA
89'
90
91test_expect_success 'mergetool skips autoresolved' '
92 git checkout -b test4 branch1 &&
93 test_must_fail git merge master &&
94 test -n "$(git ls-files -u)" &&
95 output="$(git mergetool --no-prompt)" &&
96 test "$output" = "No files need merging" &&
97 git reset --hard
98'
99
100test_expect_success 'mergetool merges all from subdir' '
25641fcd
BG
101 (
102 cd subdir &&
103 git config rerere.enabled false &&
104 test_must_fail git merge master &&
105 git mergetool --no-prompt &&
106 test "$(cat ../file1)" = "master updated" &&
107 test "$(cat ../file2)" = "master new" &&
108 test "$(cat file3)" = "master new sub" &&
109 git add ../file1 ../file2 file3 &&
110 git commit -m "branch2 resolved by mergetool from subdir"
111 )
bb0a484e 112'
b9b5078e 113
05e934bb 114test_done