Interested in helping open source friends on HP-UX?
[git/mjg.git] / t / t6023-merge-file.sh
blob190ee903cf6269071809e82d61d6065f1de679c6
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 test_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 test_path_is_missing a.txt
76 cp new1.txt test.txt
77 test_expect_success "merge without conflict (--quiet)" \
78 "git merge-file --quiet test.txt orig.txt new2.txt"
80 cp new1.txt test2.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"
87 cp new4.txt test3.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
92 DOMINUS regit me,
93 et nihil mihi deerit.
94 In loco pascuae ibi me collocavit,
95 super aquam refectionis educavit me;
96 animam meam convertit,
97 deduxit me super semitas jusitiae,
98 EOF
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
109 <<<<<<< test.txt
110 Dominus regit me, et nihil mihi deerit.
111 =======
112 DOMINUS regit me,
113 et nihil mihi deerit.
114 >>>>>>> new3.txt
115 In loco pascuae ibi me collocavit,
116 super aquam refectionis educavit me;
117 animam meam convertit,
118 deduxit me super semitas jusitiae,
119 propter nomen suum.
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,
135 propter nomen suum.
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
145 DOMINUS regit me,
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,
151 propter nomen suum.
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.
162 DOMINUS regit me,
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,
168 propter nomen suum.
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
181 <<<<<<< 1
182 Dominus regit me, et nihil mihi deerit.
183 =======
184 DOMINUS regit me,
185 et nihil mihi deerit.
186 >>>>>>> new3.txt
187 In loco pascuae ibi me collocavit,
188 super aquam refectionis educavit me;
189 animam meam convertit,
190 deduxit me super semitas jusitiae,
191 propter nomen suum.
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"
204 cat > expect << EOF
205 Dominus regit me,
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,
211 propter nomen suum.
212 <<<<<<< orig.txt
213 =======
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.
217 >>>>>>> new5.txt
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)
249 cat >expect <<\EOF
250 Dominus regit me,
251 <<<<<<< new8.txt
252 et nihil mihi deerit;
257 In loco pascuae ibi me collocavit;
258 super aquam refectionis educavit me.
259 ||||||| new5.txt
260 et nihil mihi deerit.
261 In loco pascuae ibi me collocavit,
262 super aquam refectionis educavit me;
263 =======
264 et nihil mihi deerit,
269 In loco pascuae ibi me collocavit --
270 super aquam refectionis educavit me,
271 >>>>>>> new9.txt
272 animam meam convertit,
273 deduxit me super semitas jusitiae,
274 propter nomen suum.
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
293 cat >expect <<\EOF
294 Dominus regit me,
295 <<<<<<<<<< new8.txt
296 et nihil mihi deerit;
301 In loco pascuae ibi me collocavit;
302 super aquam refectionis educavit me.
303 |||||||||| new5.txt
304 et nihil mihi deerit.
305 In loco pascuae ibi me collocavit,
306 super aquam refectionis educavit me;
307 ==========
308 et nihil mihi deerit,
313 In loco pascuae ibi me collocavit --
314 super aquam refectionis educavit me,
315 >>>>>>>>>> new9.txt
316 animam meam convertit,
317 deduxit me super semitas jusitiae,
318 propter nomen suum.
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_done