Merge branch 'mk/reachable-protect-detached-head' into maint
[git/git-svn.git] / t / t6023-merge-file.sh
blob3758961765635c4ce504eec1540605f65efd386a
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 )
75 cp new1.txt test.txt
76 test_expect_success "merge without conflict (--quiet)" \
77 "git merge-file --quiet test.txt orig.txt new2.txt"
79 cp new1.txt test2.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"
86 cp new4.txt test3.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
91 DOMINUS regit me,
92 et nihil mihi deerit.
93 In loco pascuae ibi me collocavit,
94 super aquam refectionis educavit me;
95 animam meam convertit,
96 deduxit me super semitas jusitiae,
97 EOF
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
108 <<<<<<< test.txt
109 Dominus regit me, et nihil mihi deerit.
110 =======
111 DOMINUS regit me,
112 et nihil mihi deerit.
113 >>>>>>> new3.txt
114 In loco pascuae ibi me collocavit,
115 super aquam refectionis educavit me;
116 animam meam convertit,
117 deduxit me super semitas jusitiae,
118 propter nomen suum.
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,
134 propter nomen suum.
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
144 DOMINUS regit me,
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,
150 propter nomen suum.
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.
161 DOMINUS regit me,
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,
167 propter nomen suum.
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
180 <<<<<<< 1
181 Dominus regit me, et nihil mihi deerit.
182 =======
183 DOMINUS regit me,
184 et nihil mihi deerit.
185 >>>>>>> new3.txt
186 In loco pascuae ibi me collocavit,
187 super aquam refectionis educavit me;
188 animam meam convertit,
189 deduxit me super semitas jusitiae,
190 propter nomen suum.
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"
203 cat > expect << EOF
204 Dominus regit me,
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,
210 propter nomen suum.
211 <<<<<<< orig.txt
212 =======
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.
216 >>>>>>> new5.txt
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)
248 cat >expect <<\EOF
249 Dominus regit me,
250 <<<<<<< new8.txt
251 et nihil mihi deerit;
256 In loco pascuae ibi me collocavit;
257 super aquam refectionis educavit me.
258 ||||||| new5.txt
259 et nihil mihi deerit.
260 In loco pascuae ibi me collocavit,
261 super aquam refectionis educavit me;
262 =======
263 et nihil mihi deerit,
268 In loco pascuae ibi me collocavit --
269 super aquam refectionis educavit me,
270 >>>>>>> new9.txt
271 animam meam convertit,
272 deduxit me super semitas jusitiae,
273 propter nomen suum.
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
292 cat >expect <<\EOF
293 Dominus regit me,
294 <<<<<<<<<< new8.txt
295 et nihil mihi deerit;
300 In loco pascuae ibi me collocavit;
301 super aquam refectionis educavit me.
302 |||||||||| new5.txt
303 et nihil mihi deerit.
304 In loco pascuae ibi me collocavit,
305 super aquam refectionis educavit me;
306 ==========
307 et nihil mihi deerit,
312 In loco pascuae ibi me collocavit --
313 super aquam refectionis educavit me,
314 >>>>>>>>>> new9.txt
315 animam meam convertit,
316 deduxit me super semitas jusitiae,
317 propter nomen suum.
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'
348 test_done