merge-file: correctly open files when in a subdir
[git/gitweb.git] / t / t6023-merge-file.sh
blobd0df869001b6441e31bc75fb78f336c748e1640e
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_success "merge without conflict (missing LF at EOF)" \
82 "git merge-file test2.txt orig.txt new2.txt"
84 test_expect_success "merge result added missing LF" \
85 "test_cmp test.txt test2.txt"
87 cp test.txt backup.txt
88 test_expect_success "merge with conflicts" \
89 "test_must_fail git merge-file test.txt orig.txt new3.txt"
91 cat > expect.txt << EOF
92 <<<<<<< test.txt
93 Dominus regit me, et nihil mihi deerit.
94 =======
95 DOMINUS regit me,
96 et nihil mihi deerit.
97 >>>>>>> new3.txt
98 In loco pascuae ibi me collocavit,
99 super aquam refectionis educavit me;
100 animam meam convertit,
101 deduxit me super semitas jusitiae,
102 propter nomen suum.
103 Nam et si ambulavero in medio umbrae mortis,
104 non timebo mala, quoniam tu mecum es:
105 virga tua et baculus tuus ipsa me consolata sunt.
108 test_expect_success "expected conflict markers" "test_cmp test.txt expect.txt"
110 cp backup.txt test.txt
111 test_expect_success "merge with conflicts, using -L" \
112 "test_must_fail git merge-file -L 1 -L 2 test.txt orig.txt new3.txt"
114 cat > expect.txt << EOF
115 <<<<<<< 1
116 Dominus regit me, et nihil mihi deerit.
117 =======
118 DOMINUS regit me,
119 et nihil mihi deerit.
120 >>>>>>> new3.txt
121 In loco pascuae ibi me collocavit,
122 super aquam refectionis educavit me;
123 animam meam convertit,
124 deduxit me super semitas jusitiae,
125 propter nomen suum.
126 Nam et si ambulavero in medio umbrae mortis,
127 non timebo mala, quoniam tu mecum es:
128 virga tua et baculus tuus ipsa me consolata sunt.
131 test_expect_success "expected conflict markers, with -L" \
132 "test_cmp test.txt expect.txt"
134 sed "s/ tu / TU /" < new1.txt > new5.txt
135 test_expect_success "conflict in removed tail" \
136 "test_must_fail git merge-file -p orig.txt new1.txt new5.txt > out"
138 cat > expect << EOF
139 Dominus regit me,
140 et nihil mihi deerit.
141 In loco pascuae ibi me collocavit,
142 super aquam refectionis educavit me;
143 animam meam convertit,
144 deduxit me super semitas jusitiae,
145 propter nomen suum.
146 <<<<<<< orig.txt
147 =======
148 Nam et si ambulavero in medio umbrae mortis,
149 non timebo mala, quoniam TU mecum es:
150 virga tua et baculus tuus ipsa me consolata sunt.
151 >>>>>>> new5.txt
154 test_expect_success "expected conflict markers" "test_cmp expect out"
156 test_expect_success 'binary files cannot be merged' '
157 test_must_fail git merge-file -p \
158 orig.txt "$TEST_DIRECTORY"/test-binary-1.png new1.txt 2> merge.err &&
159 grep "Cannot merge binary files" merge.err
162 sed -e "s/deerit.\$/deerit;/" -e "s/me;\$/me./" < new5.txt > new6.txt
163 sed -e "s/deerit.\$/deerit,/" -e "s/me;\$/me,/" < new5.txt > new7.txt
165 test_expect_success 'MERGE_ZEALOUS simplifies non-conflicts' '
167 test_must_fail git merge-file -p new6.txt new5.txt new7.txt > output &&
168 test 1 = $(grep ======= < output | wc -l)
172 sed -e 's/deerit./&%%%%/' -e "s/locavit,/locavit;/"< new6.txt | tr '%' '\012' > new8.txt
173 sed -e 's/deerit./&%%%%/' -e "s/locavit,/locavit --/" < new7.txt | tr '%' '\012' > new9.txt
175 test_expect_success 'ZEALOUS_ALNUM' '
177 test_must_fail git merge-file -p \
178 new8.txt new5.txt new9.txt > merge.out &&
179 test 1 = $(grep ======= < merge.out | wc -l)
183 cat >expect <<\EOF
184 Dominus regit me,
185 <<<<<<< new8.txt
186 et nihil mihi deerit;
191 In loco pascuae ibi me collocavit;
192 super aquam refectionis educavit me.
193 ||||||| new5.txt
194 et nihil mihi deerit.
195 In loco pascuae ibi me collocavit,
196 super aquam refectionis educavit me;
197 =======
198 et nihil mihi deerit,
203 In loco pascuae ibi me collocavit --
204 super aquam refectionis educavit me,
205 >>>>>>> new9.txt
206 animam meam convertit,
207 deduxit me super semitas jusitiae,
208 propter nomen suum.
209 Nam et si ambulavero in medio umbrae mortis,
210 non timebo mala, quoniam TU mecum es:
211 virga tua et baculus tuus ipsa me consolata sunt.
214 test_expect_success '"diff3 -m" style output (1)' '
215 test_must_fail git merge-file -p --diff3 \
216 new8.txt new5.txt new9.txt >actual &&
217 test_cmp expect actual
220 test_expect_success '"diff3 -m" style output (2)' '
221 git config merge.conflictstyle diff3 &&
222 test_must_fail git merge-file -p \
223 new8.txt new5.txt new9.txt >actual &&
224 test_cmp expect actual
227 cat >expect <<\EOF
228 Dominus regit me,
229 <<<<<<<<<< new8.txt
230 et nihil mihi deerit;
235 In loco pascuae ibi me collocavit;
236 super aquam refectionis educavit me.
237 |||||||||| new5.txt
238 et nihil mihi deerit.
239 In loco pascuae ibi me collocavit,
240 super aquam refectionis educavit me;
241 ==========
242 et nihil mihi deerit,
247 In loco pascuae ibi me collocavit --
248 super aquam refectionis educavit me,
249 >>>>>>>>>> new9.txt
250 animam meam convertit,
251 deduxit me super semitas jusitiae,
252 propter nomen suum.
253 Nam et si ambulavero in medio umbrae mortis,
254 non timebo mala, quoniam TU mecum es:
255 virga tua et baculus tuus ipsa me consolata sunt.
258 test_expect_success 'marker size' '
259 test_must_fail git merge-file -p --marker-size=10 \
260 new8.txt new5.txt new9.txt >actual &&
261 test_cmp expect actual
264 test_done