Merge branch 'dj/fetch-tagopt'
[git/gitweb.git] / t / t6023-merge-file.sh
blobd486d73994cf563063b578ec5e212331e87bf67f
1 #!/bin/sh
3 test_description='RCS merge replacement: merge-file'
4 . ./test-lib.sh
6 cat > orig.txt << EOF
7 Dominus regit me,
8 et nihil mihi deerit.
9 In loco pascuae ibi me collocavit,
10 super aquam refectionis educavit me;
11 animam meam convertit,
12 deduxit me super semitas jusitiae,
13 propter nomen suum.
14 EOF
16 cat > new1.txt << EOF
17 Dominus regit me,
18 et nihil mihi deerit.
19 In loco pascuae ibi me collocavit,
20 super aquam refectionis educavit me;
21 animam meam convertit,
22 deduxit me super semitas jusitiae,
23 propter nomen suum.
24 Nam et si ambulavero in medio umbrae mortis,
25 non timebo mala, quoniam tu mecum es:
26 virga tua et baculus tuus ipsa me consolata sunt.
27 EOF
29 cat > new2.txt << EOF
30 Dominus regit me, et nihil mihi deerit.
31 In loco pascuae ibi me collocavit,
32 super aquam refectionis educavit me;
33 animam meam convertit,
34 deduxit me super semitas jusitiae,
35 propter nomen suum.
36 EOF
38 cat > new3.txt << EOF
39 DOMINUS regit me,
40 et nihil mihi deerit.
41 In loco pascuae ibi me collocavit,
42 super aquam refectionis educavit me;
43 animam meam convertit,
44 deduxit me super semitas jusitiae,
45 propter nomen suum.
46 EOF
48 cat > new4.txt << EOF
49 Dominus regit me, et nihil mihi deerit.
50 In loco pascuae ibi me collocavit,
51 super aquam refectionis educavit me;
52 animam meam convertit,
53 deduxit me super semitas jusitiae,
54 EOF
55 printf "propter nomen suum." >> new4.txt
57 test_expect_success 'merge with no changes' '
58 cp orig.txt test.txt &&
59 git merge-file test.txt orig.txt orig.txt &&
60 test_cmp test.txt orig.txt
63 cp new1.txt test.txt
64 test_expect_success "merge without conflict" \
65 "git merge-file test.txt orig.txt new2.txt"
67 cp new1.txt test.txt
68 test_expect_success "merge without conflict (--quiet)" \
69 "git merge-file --quiet test.txt orig.txt new2.txt"
71 cp new1.txt test2.txt
72 test_expect_success "merge without conflict (missing LF at EOF)" \
73 "git merge-file test2.txt orig.txt new2.txt"
75 test_expect_success "merge result added missing LF" \
76 "test_cmp test.txt test2.txt"
78 cp test.txt backup.txt
79 test_expect_success "merge with conflicts" \
80 "test_must_fail git merge-file test.txt orig.txt new3.txt"
82 cat > expect.txt << EOF
83 <<<<<<< test.txt
84 Dominus regit me, et nihil mihi deerit.
85 =======
86 DOMINUS regit me,
87 et nihil mihi deerit.
88 >>>>>>> new3.txt
89 In loco pascuae ibi me collocavit,
90 super aquam refectionis educavit me;
91 animam meam convertit,
92 deduxit me super semitas jusitiae,
93 propter nomen suum.
94 Nam et si ambulavero in medio umbrae mortis,
95 non timebo mala, quoniam tu mecum es:
96 virga tua et baculus tuus ipsa me consolata sunt.
97 EOF
99 test_expect_success "expected conflict markers" "test_cmp test.txt expect.txt"
101 cp backup.txt test.txt
102 test_expect_success "merge with conflicts, using -L" \
103 "test_must_fail git merge-file -L 1 -L 2 test.txt orig.txt new3.txt"
105 cat > expect.txt << EOF
106 <<<<<<< 1
107 Dominus regit me, et nihil mihi deerit.
108 =======
109 DOMINUS regit me,
110 et nihil mihi deerit.
111 >>>>>>> new3.txt
112 In loco pascuae ibi me collocavit,
113 super aquam refectionis educavit me;
114 animam meam convertit,
115 deduxit me super semitas jusitiae,
116 propter nomen suum.
117 Nam et si ambulavero in medio umbrae mortis,
118 non timebo mala, quoniam tu mecum es:
119 virga tua et baculus tuus ipsa me consolata sunt.
122 test_expect_success "expected conflict markers, with -L" \
123 "test_cmp test.txt expect.txt"
125 sed "s/ tu / TU /" < new1.txt > new5.txt
126 test_expect_success "conflict in removed tail" \
127 "test_must_fail git merge-file -p orig.txt new1.txt new5.txt > out"
129 cat > expect << EOF
130 Dominus regit me,
131 et nihil mihi deerit.
132 In loco pascuae ibi me collocavit,
133 super aquam refectionis educavit me;
134 animam meam convertit,
135 deduxit me super semitas jusitiae,
136 propter nomen suum.
137 <<<<<<< orig.txt
138 =======
139 Nam et si ambulavero in medio umbrae mortis,
140 non timebo mala, quoniam TU mecum es:
141 virga tua et baculus tuus ipsa me consolata sunt.
142 >>>>>>> new5.txt
145 test_expect_success "expected conflict markers" "test_cmp expect out"
147 test_expect_success 'binary files cannot be merged' '
148 test_must_fail git merge-file -p \
149 orig.txt "$TEST_DIRECTORY"/test4012.png new1.txt 2> merge.err &&
150 grep "Cannot merge binary files" merge.err
153 sed -e "s/deerit.\$/deerit;/" -e "s/me;\$/me./" < new5.txt > new6.txt
154 sed -e "s/deerit.\$/deerit,/" -e "s/me;\$/me,/" < new5.txt > new7.txt
156 test_expect_success 'MERGE_ZEALOUS simplifies non-conflicts' '
158 test_must_fail git merge-file -p new6.txt new5.txt new7.txt > output &&
159 test 1 = $(grep ======= < output | wc -l)
163 sed -e 's/deerit./&%%%%/' -e "s/locavit,/locavit;/"< new6.txt | tr '%' '\012' > new8.txt
164 sed -e 's/deerit./&%%%%/' -e "s/locavit,/locavit --/" < new7.txt | tr '%' '\012' > new9.txt
166 test_expect_success 'ZEALOUS_ALNUM' '
168 test_must_fail git merge-file -p \
169 new8.txt new5.txt new9.txt > merge.out &&
170 test 1 = $(grep ======= < merge.out | wc -l)
174 cat >expect <<\EOF
175 Dominus regit me,
176 <<<<<<< new8.txt
177 et nihil mihi deerit;
182 In loco pascuae ibi me collocavit;
183 super aquam refectionis educavit me.
184 ||||||| new5.txt
185 et nihil mihi deerit.
186 In loco pascuae ibi me collocavit,
187 super aquam refectionis educavit me;
188 =======
189 et nihil mihi deerit,
194 In loco pascuae ibi me collocavit --
195 super aquam refectionis educavit me,
196 >>>>>>> new9.txt
197 animam meam convertit,
198 deduxit me super semitas jusitiae,
199 propter nomen suum.
200 Nam et si ambulavero in medio umbrae mortis,
201 non timebo mala, quoniam TU mecum es:
202 virga tua et baculus tuus ipsa me consolata sunt.
205 test_expect_success '"diff3 -m" style output (1)' '
206 test_must_fail git merge-file -p --diff3 \
207 new8.txt new5.txt new9.txt >actual &&
208 test_cmp expect actual
211 test_expect_success '"diff3 -m" style output (2)' '
212 git config merge.conflictstyle diff3 &&
213 test_must_fail git merge-file -p \
214 new8.txt new5.txt new9.txt >actual &&
215 test_cmp expect actual
218 cat >expect <<\EOF
219 Dominus regit me,
220 <<<<<<<<<< new8.txt
221 et nihil mihi deerit;
226 In loco pascuae ibi me collocavit;
227 super aquam refectionis educavit me.
228 |||||||||| new5.txt
229 et nihil mihi deerit.
230 In loco pascuae ibi me collocavit,
231 super aquam refectionis educavit me;
232 ==========
233 et nihil mihi deerit,
238 In loco pascuae ibi me collocavit --
239 super aquam refectionis educavit me,
240 >>>>>>>>>> new9.txt
241 animam meam convertit,
242 deduxit me super semitas jusitiae,
243 propter nomen suum.
244 Nam et si ambulavero in medio umbrae mortis,
245 non timebo mala, quoniam TU mecum es:
246 virga tua et baculus tuus ipsa me consolata sunt.
249 test_expect_success 'marker size' '
250 test_must_fail git merge-file -p --marker-size=10 \
251 new8.txt new5.txt new9.txt >actual &&
252 test_cmp expect actual
255 test_done