1#!/bin/sh
2
3test_description='RCS merge replacement: merge-file'
4. ./test-lib.sh
5
6cat > orig.txt << EOF
7Dominus regit me,
8et nihil mihi deerit.
9In loco pascuae ibi me collocavit,
10super aquam refectionis educavit me;
11animam meam convertit,
12deduxit me super semitas jusitiae,
13propter nomen suum.
14EOF
15
16cat > new1.txt << EOF
17Dominus regit me,
18et nihil mihi deerit.
19In loco pascuae ibi me collocavit,
20super aquam refectionis educavit me;
21animam meam convertit,
22deduxit me super semitas jusitiae,
23propter nomen suum.
24Nam et si ambulavero in medio umbrae mortis,
25non timebo mala, quoniam tu mecum es:
26virga tua et baculus tuus ipsa me consolata sunt.
27EOF
28
29cat > new2.txt << EOF
30Dominus regit me, et nihil mihi deerit.
31In loco pascuae ibi me collocavit,
32super aquam refectionis educavit me;
33animam meam convertit,
34deduxit me super semitas jusitiae,
35propter nomen suum.
36EOF
37
38cat > new3.txt << EOF
39DOMINUS regit me,
40et nihil mihi deerit.
41In loco pascuae ibi me collocavit,
42super aquam refectionis educavit me;
43animam meam convertit,
44deduxit me super semitas jusitiae,
45propter nomen suum.
46EOF
47
48cat > new4.txt << EOF
49Dominus regit me, et nihil mihi deerit.
50In loco pascuae ibi me collocavit,
51super aquam refectionis educavit me;
52animam meam convertit,
53deduxit me super semitas jusitiae,
54EOF
55printf "propter nomen suum." >> new4.txt
56
57test_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
61'
62
63cp new1.txt test.txt
64test_expect_success "merge without conflict" \
65 "git merge-file test.txt orig.txt new2.txt"
66
67test_expect_success 'works in subdirectory' '
68 mkdir dir &&
69 cp new1.txt dir/a.txt &&
70 cp orig.txt dir/o.txt &&
71 cp new2.txt dir/b.txt &&
72 ( cd dir && git merge-file a.txt o.txt b.txt )
73'
74
75cp new1.txt test.txt
76test_expect_success "merge without conflict (--quiet)" \
77 "git merge-file --quiet test.txt orig.txt new2.txt"
78
79cp new1.txt test2.txt
80test_expect_failure "merge without conflict (missing LF at EOF)" \
81 "git merge-file test2.txt orig.txt new4.txt"
82
83test_expect_failure "merge result added missing LF" \
84 "test_cmp test.txt test2.txt"
85
86cp new4.txt test3.txt
87test_expect_success "merge without conflict (missing LF at EOF, away from change in the other file)" \
88 "git merge-file --quiet test3.txt new2.txt new3.txt"
89
90cat > expect.txt << EOF
91DOMINUS regit me,
92et nihil mihi deerit.
93In loco pascuae ibi me collocavit,
94super aquam refectionis educavit me;
95animam meam convertit,
96deduxit me super semitas jusitiae,
97EOF
98printf "propter nomen suum." >> expect.txt
99
100test_expect_success "merge does not add LF away of change" \
101 "test_cmp test3.txt expect.txt"
102
103cp test.txt backup.txt
104test_expect_success "merge with conflicts" \
105 "test_must_fail git merge-file test.txt orig.txt new3.txt"
106
107cat > expect.txt << EOF
108<<<<<<< test.txt
109Dominus regit me, et nihil mihi deerit.
110=======
111DOMINUS regit me,
112et nihil mihi deerit.
113>>>>>>> new3.txt
114In loco pascuae ibi me collocavit,
115super aquam refectionis educavit me;
116animam meam convertit,
117deduxit me super semitas jusitiae,
118propter nomen suum.
119Nam et si ambulavero in medio umbrae mortis,
120non timebo mala, quoniam tu mecum es:
121virga tua et baculus tuus ipsa me consolata sunt.
122EOF
123
124test_expect_success "expected conflict markers" "test_cmp test.txt expect.txt"
125
126cp backup.txt test.txt
127
128cat > expect.txt << EOF
129Dominus regit me, et nihil mihi deerit.
130In loco pascuae ibi me collocavit,
131super aquam refectionis educavit me;
132animam meam convertit,
133deduxit me super semitas jusitiae,
134propter nomen suum.
135Nam et si ambulavero in medio umbrae mortis,
136non timebo mala, quoniam tu mecum es:
137virga tua et baculus tuus ipsa me consolata sunt.
138EOF
139test_expect_success "merge conflicting with --ours" \
140 "git merge-file --ours test.txt orig.txt new3.txt && test_cmp test.txt expect.txt"
141cp backup.txt test.txt
142
143cat > expect.txt << EOF
144DOMINUS regit me,
145et nihil mihi deerit.
146In loco pascuae ibi me collocavit,
147super aquam refectionis educavit me;
148animam meam convertit,
149deduxit me super semitas jusitiae,
150propter nomen suum.
151Nam et si ambulavero in medio umbrae mortis,
152non timebo mala, quoniam tu mecum es:
153virga tua et baculus tuus ipsa me consolata sunt.
154EOF
155test_expect_success "merge conflicting with --theirs" \
156 "git merge-file --theirs test.txt orig.txt new3.txt && test_cmp test.txt expect.txt"
157cp backup.txt test.txt
158
159cat > expect.txt << EOF
160Dominus regit me, et nihil mihi deerit.
161DOMINUS regit me,
162et nihil mihi deerit.
163In loco pascuae ibi me collocavit,
164super aquam refectionis educavit me;
165animam meam convertit,
166deduxit me super semitas jusitiae,
167propter nomen suum.
168Nam et si ambulavero in medio umbrae mortis,
169non timebo mala, quoniam tu mecum es:
170virga tua et baculus tuus ipsa me consolata sunt.
171EOF
172test_expect_success "merge conflicting with --union" \
173 "git merge-file --union test.txt orig.txt new3.txt && test_cmp test.txt expect.txt"
174cp backup.txt test.txt
175
176test_expect_success "merge with conflicts, using -L" \
177 "test_must_fail git merge-file -L 1 -L 2 test.txt orig.txt new3.txt"
178
179cat > expect.txt << EOF
180<<<<<<< 1
181Dominus regit me, et nihil mihi deerit.
182=======
183DOMINUS regit me,
184et nihil mihi deerit.
185>>>>>>> new3.txt
186In loco pascuae ibi me collocavit,
187super aquam refectionis educavit me;
188animam meam convertit,
189deduxit me super semitas jusitiae,
190propter nomen suum.
191Nam et si ambulavero in medio umbrae mortis,
192non timebo mala, quoniam tu mecum es:
193virga tua et baculus tuus ipsa me consolata sunt.
194EOF
195
196test_expect_success "expected conflict markers, with -L" \
197 "test_cmp test.txt expect.txt"
198
199sed "s/ tu / TU /" < new1.txt > new5.txt
200test_expect_success "conflict in removed tail" \
201 "test_must_fail git merge-file -p orig.txt new1.txt new5.txt > out"
202
203cat > expect << EOF
204Dominus regit me,
205et nihil mihi deerit.
206In loco pascuae ibi me collocavit,
207super aquam refectionis educavit me;
208animam meam convertit,
209deduxit me super semitas jusitiae,
210propter nomen suum.
211<<<<<<< orig.txt
212=======
213Nam et si ambulavero in medio umbrae mortis,
214non timebo mala, quoniam TU mecum es:
215virga tua et baculus tuus ipsa me consolata sunt.
216>>>>>>> new5.txt
217EOF
218
219test_expect_success "expected conflict markers" "test_cmp expect out"
220
221test_expect_success 'binary files cannot be merged' '
222 test_must_fail git merge-file -p \
223 orig.txt "$TEST_DIRECTORY"/test-binary-1.png new1.txt 2> merge.err &&
224 grep "Cannot merge binary files" merge.err
225'
226
227sed -e "s/deerit.\$/deerit;/" -e "s/me;\$/me./" < new5.txt > new6.txt
228sed -e "s/deerit.\$/deerit,/" -e "s/me;\$/me,/" < new5.txt > new7.txt
229
230test_expect_success 'MERGE_ZEALOUS simplifies non-conflicts' '
231
232 test_must_fail git merge-file -p new6.txt new5.txt new7.txt > output &&
233 test 1 = $(grep ======= < output | wc -l)
234
235'
236
237sed -e 's/deerit./&%%%%/' -e "s/locavit,/locavit;/"< new6.txt | tr '%' '\012' > new8.txt
238sed -e 's/deerit./&%%%%/' -e "s/locavit,/locavit --/" < new7.txt | tr '%' '\012' > new9.txt
239
240test_expect_success 'ZEALOUS_ALNUM' '
241
242 test_must_fail git merge-file -p \
243 new8.txt new5.txt new9.txt > merge.out &&
244 test 1 = $(grep ======= < merge.out | wc -l)
245
246'
247
248cat >expect <<\EOF
249Dominus regit me,
250<<<<<<< new8.txt
251et nihil mihi deerit;
252
253
254
255
256In loco pascuae ibi me collocavit;
257super aquam refectionis educavit me.
258||||||| new5.txt
259et nihil mihi deerit.
260In loco pascuae ibi me collocavit,
261super aquam refectionis educavit me;
262=======
263et nihil mihi deerit,
264
265
266
267
268In loco pascuae ibi me collocavit --
269super aquam refectionis educavit me,
270>>>>>>> new9.txt
271animam meam convertit,
272deduxit me super semitas jusitiae,
273propter nomen suum.
274Nam et si ambulavero in medio umbrae mortis,
275non timebo mala, quoniam TU mecum es:
276virga tua et baculus tuus ipsa me consolata sunt.
277EOF
278
279test_expect_success '"diff3 -m" style output (1)' '
280 test_must_fail git merge-file -p --diff3 \
281 new8.txt new5.txt new9.txt >actual &&
282 test_cmp expect actual
283'
284
285test_expect_success '"diff3 -m" style output (2)' '
286 git config merge.conflictstyle diff3 &&
287 test_must_fail git merge-file -p \
288 new8.txt new5.txt new9.txt >actual &&
289 test_cmp expect actual
290'
291
292cat >expect <<\EOF
293Dominus regit me,
294<<<<<<<<<< new8.txt
295et nihil mihi deerit;
296
297
298
299
300In loco pascuae ibi me collocavit;
301super aquam refectionis educavit me.
302|||||||||| new5.txt
303et nihil mihi deerit.
304In loco pascuae ibi me collocavit,
305super aquam refectionis educavit me;
306==========
307et nihil mihi deerit,
308
309
310
311
312In loco pascuae ibi me collocavit --
313super aquam refectionis educavit me,
314>>>>>>>>>> new9.txt
315animam meam convertit,
316deduxit me super semitas jusitiae,
317propter nomen suum.
318Nam et si ambulavero in medio umbrae mortis,
319non timebo mala, quoniam TU mecum es:
320virga tua et baculus tuus ipsa me consolata sunt.
321EOF
322
323test_expect_success 'marker size' '
324 test_must_fail git merge-file -p --marker-size=10 \
325 new8.txt new5.txt new9.txt >actual &&
326 test_cmp expect actual
327'
328
329printf "line1\nline2\nline3" >nolf-orig.txt
330printf "line1\nline2\nline3x" >nolf-diff1.txt
331printf "line1\nline2\nline3y" >nolf-diff2.txt
332
333test_expect_success 'conflict at EOF without LF resolved by --ours' \
334 'git merge-file -p --ours nolf-diff1.txt nolf-orig.txt nolf-diff2.txt >output.txt &&
335 printf "line1\nline2\nline3x" >expect.txt &&
336 test_cmp expect.txt output.txt'
337
338test_expect_success 'conflict at EOF without LF resolved by --theirs' \
339 'git merge-file -p --theirs nolf-diff1.txt nolf-orig.txt nolf-diff2.txt >output.txt &&
340 printf "line1\nline2\nline3y" >expect.txt &&
341 test_cmp expect.txt output.txt'
342
343test_expect_success 'conflict at EOF without LF resolved by --union' \
344 'git merge-file -p --union nolf-diff1.txt nolf-orig.txt nolf-diff2.txt >output.txt &&
345 printf "line1\nline2\nline3x\nline3y" >expect.txt &&
346 test_cmp expect.txt output.txt'
347
348test_done