3 test_description='RCS merge replacement: merge-file'
9 In loco pascuae ibi me collocavit,
10 super aquam refectionis educavit me;
11 animam meam convertit,
12 deduxit me super semitas jusitiae,
19 In loco pascuae ibi me collocavit,
20 super aquam refectionis educavit me;
21 animam meam convertit,
22 deduxit me super semitas jusitiae,
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.
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,
41 In loco pascuae ibi me collocavit,
42 super aquam refectionis educavit me;
43 animam meam convertit,
44 deduxit me super semitas jusitiae,
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,
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
64 test_expect_success "merge without conflict" \
65 "git merge-file test.txt orig.txt new2.txt"
67 test_expect_success 'works in subdirectory' '
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 test_path_is_missing a.txt
77 test_expect_success "merge without conflict (--quiet)" \
78 "git merge-file --quiet test.txt orig.txt new2.txt"
81 test_expect_failure "merge without conflict (missing LF at EOF)" \
82 "git merge-file test2.txt orig.txt new4.txt"
84 test_expect_failure "merge result added missing LF" \
85 "test_cmp test.txt test2.txt"
88 test_expect_success "merge without conflict (missing LF at EOF, away from change in the other file)" \
89 "git merge-file --quiet test3.txt new2.txt new3.txt"
91 cat > expect.txt << EOF
94 In loco pascuae ibi me collocavit,
95 super aquam refectionis educavit me;
96 animam meam convertit,
97 deduxit me super semitas jusitiae,
99 printf "propter nomen suum." >> expect.txt
101 test_expect_success "merge does not add LF away of change" \
102 "test_cmp test3.txt expect.txt"
104 cp test.txt backup.txt
105 test_expect_success "merge with conflicts" \
106 "test_must_fail git merge-file test.txt orig.txt new3.txt"
108 cat > expect.txt << EOF
110 Dominus regit me, et nihil mihi deerit.
113 et nihil mihi deerit.
115 In loco pascuae ibi me collocavit,
116 super aquam refectionis educavit me;
117 animam meam convertit,
118 deduxit me super semitas jusitiae,
120 Nam et si ambulavero in medio umbrae mortis,
121 non timebo mala, quoniam tu mecum es:
122 virga tua et baculus tuus ipsa me consolata sunt.
125 test_expect_success "expected conflict markers" "test_cmp test.txt expect.txt"
127 cp backup.txt test.txt
129 cat > expect.txt << EOF
130 Dominus regit me, et nihil mihi deerit.
131 In loco pascuae ibi me collocavit,
132 super aquam refectionis educavit me;
133 animam meam convertit,
134 deduxit me super semitas jusitiae,
136 Nam et si ambulavero in medio umbrae mortis,
137 non timebo mala, quoniam tu mecum es:
138 virga tua et baculus tuus ipsa me consolata sunt.
140 test_expect_success "merge conflicting with --ours" \
141 "git merge-file --ours test.txt orig.txt new3.txt && test_cmp test.txt expect.txt"
142 cp backup.txt test.txt
144 cat > expect.txt << EOF
146 et nihil mihi deerit.
147 In loco pascuae ibi me collocavit,
148 super aquam refectionis educavit me;
149 animam meam convertit,
150 deduxit me super semitas jusitiae,
152 Nam et si ambulavero in medio umbrae mortis,
153 non timebo mala, quoniam tu mecum es:
154 virga tua et baculus tuus ipsa me consolata sunt.
156 test_expect_success "merge conflicting with --theirs" \
157 "git merge-file --theirs test.txt orig.txt new3.txt && test_cmp test.txt expect.txt"
158 cp backup.txt test.txt
160 cat > expect.txt << EOF
161 Dominus regit me, et nihil mihi deerit.
163 et nihil mihi deerit.
164 In loco pascuae ibi me collocavit,
165 super aquam refectionis educavit me;
166 animam meam convertit,
167 deduxit me super semitas jusitiae,
169 Nam et si ambulavero in medio umbrae mortis,
170 non timebo mala, quoniam tu mecum es:
171 virga tua et baculus tuus ipsa me consolata sunt.
173 test_expect_success "merge conflicting with --union" \
174 "git merge-file --union test.txt orig.txt new3.txt && test_cmp test.txt expect.txt"
175 cp backup.txt test.txt
177 test_expect_success "merge with conflicts, using -L" \
178 "test_must_fail git merge-file -L 1 -L 2 test.txt orig.txt new3.txt"
180 cat > expect.txt << EOF
182 Dominus regit me, et nihil mihi deerit.
185 et nihil mihi deerit.
187 In loco pascuae ibi me collocavit,
188 super aquam refectionis educavit me;
189 animam meam convertit,
190 deduxit me super semitas jusitiae,
192 Nam et si ambulavero in medio umbrae mortis,
193 non timebo mala, quoniam tu mecum es:
194 virga tua et baculus tuus ipsa me consolata sunt.
197 test_expect_success "expected conflict markers, with -L" \
198 "test_cmp test.txt expect.txt"
200 sed "s/ tu / TU /" < new1.txt > new5.txt
201 test_expect_success "conflict in removed tail" \
202 "test_must_fail git merge-file -p orig.txt new1.txt new5.txt > out"
206 et nihil mihi deerit.
207 In loco pascuae ibi me collocavit,
208 super aquam refectionis educavit me;
209 animam meam convertit,
210 deduxit me super semitas jusitiae,
214 Nam et si ambulavero in medio umbrae mortis,
215 non timebo mala, quoniam TU mecum es:
216 virga tua et baculus tuus ipsa me consolata sunt.
220 test_expect_success "expected conflict markers" "test_cmp expect out"
222 test_expect_success 'binary files cannot be merged' '
223 test_must_fail git merge-file -p \
224 orig.txt "$TEST_DIRECTORY"/test-binary-1.png new1.txt 2> merge.err &&
225 grep "Cannot merge binary files" merge.err
228 sed -e "s/deerit.\$/deerit;/" -e "s/me;\$/me./" < new5.txt > new6.txt
229 sed -e "s/deerit.\$/deerit,/" -e "s/me;\$/me,/" < new5.txt > new7.txt
231 test_expect_success 'MERGE_ZEALOUS simplifies non-conflicts' '
233 test_must_fail git merge-file -p new6.txt new5.txt new7.txt > output &&
234 test 1 = $(grep ======= < output | wc -l)
238 sed -e 's/deerit./&%%%%/' -e "s/locavit,/locavit;/"< new6.txt | tr '%' '\012' > new8.txt
239 sed -e 's/deerit./&%%%%/' -e "s/locavit,/locavit --/" < new7.txt | tr '%' '\012' > new9.txt
241 test_expect_success 'ZEALOUS_ALNUM' '
243 test_must_fail git merge-file -p \
244 new8.txt new5.txt new9.txt > merge.out &&
245 test 1 = $(grep ======= < merge.out | wc -l)
252 et nihil mihi deerit;
257 In loco pascuae ibi me collocavit;
258 super aquam refectionis educavit me.
260 et nihil mihi deerit.
261 In loco pascuae ibi me collocavit,
262 super aquam refectionis educavit me;
264 et nihil mihi deerit,
269 In loco pascuae ibi me collocavit --
270 super aquam refectionis educavit me,
272 animam meam convertit,
273 deduxit me super semitas jusitiae,
275 Nam et si ambulavero in medio umbrae mortis,
276 non timebo mala, quoniam TU mecum es:
277 virga tua et baculus tuus ipsa me consolata sunt.
280 test_expect_success '"diff3 -m" style output (1)' '
281 test_must_fail git merge-file -p --diff3 \
282 new8.txt new5.txt new9.txt >actual &&
283 test_cmp expect actual
286 test_expect_success '"diff3 -m" style output (2)' '
287 git config merge.conflictstyle diff3 &&
288 test_must_fail git merge-file -p \
289 new8.txt new5.txt new9.txt >actual &&
290 test_cmp expect actual
296 et nihil mihi deerit;
301 In loco pascuae ibi me collocavit;
302 super aquam refectionis educavit me.
304 et nihil mihi deerit.
305 In loco pascuae ibi me collocavit,
306 super aquam refectionis educavit me;
308 et nihil mihi deerit,
313 In loco pascuae ibi me collocavit --
314 super aquam refectionis educavit me,
316 animam meam convertit,
317 deduxit me super semitas jusitiae,
319 Nam et si ambulavero in medio umbrae mortis,
320 non timebo mala, quoniam TU mecum es:
321 virga tua et baculus tuus ipsa me consolata sunt.
324 test_expect_success 'marker size' '
325 test_must_fail git merge-file -p --marker-size=10 \
326 new8.txt new5.txt new9.txt >actual &&
327 test_cmp expect actual
330 printf "line1\nline2\nline3" >nolf-orig.txt
331 printf "line1\nline2\nline3x" >nolf-diff1.txt
332 printf "line1\nline2\nline3y" >nolf-diff2.txt
334 test_expect_success 'conflict at EOF without LF resolved by --ours' \
335 'git merge-file -p --ours nolf-diff1.txt nolf-orig.txt nolf-diff2.txt >output.txt &&
336 printf "line1\nline2\nline3x" >expect.txt &&
337 test_cmp expect.txt output.txt'
339 test_expect_success 'conflict at EOF without LF resolved by --theirs' \
340 'git merge-file -p --theirs nolf-diff1.txt nolf-orig.txt nolf-diff2.txt >output.txt &&
341 printf "line1\nline2\nline3y" >expect.txt &&
342 test_cmp expect.txt output.txt'
344 test_expect_success 'conflict at EOF without LF resolved by --union' \
345 'git merge-file -p --union nolf-diff1.txt nolf-orig.txt nolf-diff2.txt >output.txt &&
346 printf "line1\nline2\nline3x\nline3y" >expect.txt &&
347 test_cmp expect.txt output.txt'
349 test_expect_success 'conflict sections match existing line endings' '
350 printf "1\\r\\n2\\r\\n3" >crlf-orig.txt &&
351 printf "1\\r\\n2\\r\\n4" >crlf-diff1.txt &&
352 printf "1\\r\\n2\\r\\n5" >crlf-diff2.txt &&
353 test_must_fail git -c core.eol=crlf merge-file -p \
354 crlf-diff1.txt crlf-orig.txt crlf-diff2.txt >crlf.txt &&
355 test $(tr "\015" Q <crlf.txt | grep "^[<=>].*Q$" | wc -l) = 3 &&
356 test $(tr "\015" Q <crlf.txt | grep "[345]Q$" | wc -l) = 3 &&
357 test_must_fail git -c core.eol=crlf merge-file -p \
358 nolf-diff1.txt nolf-orig.txt nolf-diff2.txt >nolf.txt &&
359 test $(tr "\015" Q <nolf.txt | grep "^[<=>].*Q$" | wc -l) = 0