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 )
76 test_expect_success "merge without conflict (--quiet)" \
77 "git merge-file --quiet test.txt orig.txt new2.txt"
80 test_expect_failure "merge without conflict (missing LF at EOF)" \
81 "git merge-file test2.txt orig.txt new4.txt"
83 test_expect_failure "merge result added missing LF" \
84 "test_cmp test.txt test2.txt"
87 test_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"
90 cat > expect.txt << EOF
93 In loco pascuae ibi me collocavit,
94 super aquam refectionis educavit me;
95 animam meam convertit,
96 deduxit me super semitas jusitiae,
98 printf "propter nomen suum." >> expect.txt
100 test_expect_success "merge does not add LF away of change" \
101 "test_cmp test3.txt expect.txt"
103 cp test.txt backup.txt
104 test_expect_success "merge with conflicts" \
105 "test_must_fail git merge-file test.txt orig.txt new3.txt"
107 cat > expect.txt << EOF
109 Dominus regit me, et nihil mihi deerit.
112 et nihil mihi deerit.
114 In loco pascuae ibi me collocavit,
115 super aquam refectionis educavit me;
116 animam meam convertit,
117 deduxit me super semitas jusitiae,
119 Nam et si ambulavero in medio umbrae mortis,
120 non timebo mala, quoniam tu mecum es:
121 virga tua et baculus tuus ipsa me consolata sunt.
124 test_expect_success "expected conflict markers" "test_cmp test.txt expect.txt"
126 cp backup.txt test.txt
128 cat > expect.txt << EOF
129 Dominus regit me, et nihil mihi deerit.
130 In loco pascuae ibi me collocavit,
131 super aquam refectionis educavit me;
132 animam meam convertit,
133 deduxit me super semitas jusitiae,
135 Nam et si ambulavero in medio umbrae mortis,
136 non timebo mala, quoniam tu mecum es:
137 virga tua et baculus tuus ipsa me consolata sunt.
139 test_expect_success "merge conflicting with --ours" \
140 "git merge-file --ours test.txt orig.txt new3.txt && test_cmp test.txt expect.txt"
141 cp backup.txt test.txt
143 cat > expect.txt << EOF
145 et nihil mihi deerit.
146 In loco pascuae ibi me collocavit,
147 super aquam refectionis educavit me;
148 animam meam convertit,
149 deduxit me super semitas jusitiae,
151 Nam et si ambulavero in medio umbrae mortis,
152 non timebo mala, quoniam tu mecum es:
153 virga tua et baculus tuus ipsa me consolata sunt.
155 test_expect_success "merge conflicting with --theirs" \
156 "git merge-file --theirs test.txt orig.txt new3.txt && test_cmp test.txt expect.txt"
157 cp backup.txt test.txt
159 cat > expect.txt << EOF
160 Dominus regit me, et nihil mihi deerit.
162 et nihil mihi deerit.
163 In loco pascuae ibi me collocavit,
164 super aquam refectionis educavit me;
165 animam meam convertit,
166 deduxit me super semitas jusitiae,
168 Nam et si ambulavero in medio umbrae mortis,
169 non timebo mala, quoniam tu mecum es:
170 virga tua et baculus tuus ipsa me consolata sunt.
172 test_expect_success "merge conflicting with --union" \
173 "git merge-file --union test.txt orig.txt new3.txt && test_cmp test.txt expect.txt"
174 cp backup.txt test.txt
176 test_expect_success "merge with conflicts, using -L" \
177 "test_must_fail git merge-file -L 1 -L 2 test.txt orig.txt new3.txt"
179 cat > expect.txt << EOF
181 Dominus regit me, et nihil mihi deerit.
184 et nihil mihi deerit.
186 In loco pascuae ibi me collocavit,
187 super aquam refectionis educavit me;
188 animam meam convertit,
189 deduxit me super semitas jusitiae,
191 Nam et si ambulavero in medio umbrae mortis,
192 non timebo mala, quoniam tu mecum es:
193 virga tua et baculus tuus ipsa me consolata sunt.
196 test_expect_success "expected conflict markers, with -L" \
197 "test_cmp test.txt expect.txt"
199 sed "s/ tu / TU /" < new1.txt > new5.txt
200 test_expect_success "conflict in removed tail" \
201 "test_must_fail git merge-file -p orig.txt new1.txt new5.txt > out"
205 et nihil mihi deerit.
206 In loco pascuae ibi me collocavit,
207 super aquam refectionis educavit me;
208 animam meam convertit,
209 deduxit me super semitas jusitiae,
213 Nam et si ambulavero in medio umbrae mortis,
214 non timebo mala, quoniam TU mecum es:
215 virga tua et baculus tuus ipsa me consolata sunt.
219 test_expect_success "expected conflict markers" "test_cmp expect out"
221 test_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
227 sed -e "s/deerit.\$/deerit;/" -e "s/me;\$/me./" < new5.txt > new6.txt
228 sed -e "s/deerit.\$/deerit,/" -e "s/me;\$/me,/" < new5.txt > new7.txt
230 test_expect_success 'MERGE_ZEALOUS simplifies non-conflicts' '
232 test_must_fail git merge-file -p new6.txt new5.txt new7.txt > output &&
233 test 1 = $(grep ======= < output | wc -l)
237 sed -e 's/deerit./&%%%%/' -e "s/locavit,/locavit;/"< new6.txt | tr '%' '\012' > new8.txt
238 sed -e 's/deerit./&%%%%/' -e "s/locavit,/locavit --/" < new7.txt | tr '%' '\012' > new9.txt
240 test_expect_success 'ZEALOUS_ALNUM' '
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)
251 et nihil mihi deerit;
256 In loco pascuae ibi me collocavit;
257 super aquam refectionis educavit me.
259 et nihil mihi deerit.
260 In loco pascuae ibi me collocavit,
261 super aquam refectionis educavit me;
263 et nihil mihi deerit,
268 In loco pascuae ibi me collocavit --
269 super aquam refectionis educavit me,
271 animam meam convertit,
272 deduxit me super semitas jusitiae,
274 Nam et si ambulavero in medio umbrae mortis,
275 non timebo mala, quoniam TU mecum es:
276 virga tua et baculus tuus ipsa me consolata sunt.
279 test_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
285 test_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
295 et nihil mihi deerit;
300 In loco pascuae ibi me collocavit;
301 super aquam refectionis educavit me.
303 et nihil mihi deerit.
304 In loco pascuae ibi me collocavit,
305 super aquam refectionis educavit me;
307 et nihil mihi deerit,
312 In loco pascuae ibi me collocavit --
313 super aquam refectionis educavit me,
315 animam meam convertit,
316 deduxit me super semitas jusitiae,
318 Nam et si ambulavero in medio umbrae mortis,
319 non timebo mala, quoniam TU mecum es:
320 virga tua et baculus tuus ipsa me consolata sunt.
323 test_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
329 printf "line1\nline2\nline3" >nolf-orig.txt
330 printf "line1\nline2\nline3x" >nolf-diff1.txt
331 printf "line1\nline2\nline3y" >nolf-diff2.txt
333 test_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'
338 test_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'
343 test_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'