Git 1.7.0.6
[git/mingw/4msysgit/kblees.git] / t / t6023-merge-file.sh
blob6291307cd03e4e374e640dc82ddc8f26dbb8ff1d
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 cp new1.txt test2.txt
68 test_expect_success "merge without conflict (missing LF at EOF)" \
69 "git merge-file test2.txt orig.txt new2.txt"
71 test_expect_success "merge result added missing LF" \
72 "test_cmp test.txt test2.txt"
74 cp test.txt backup.txt
75 test_expect_success "merge with conflicts" \
76 "test_must_fail git merge-file test.txt orig.txt new3.txt"
78 cat > expect.txt << EOF
79 <<<<<<< test.txt
80 Dominus regit me, et nihil mihi deerit.
81 =======
82 DOMINUS regit me,
83 et nihil mihi deerit.
84 >>>>>>> new3.txt
85 In loco pascuae ibi me collocavit,
86 super aquam refectionis educavit me;
87 animam meam convertit,
88 deduxit me super semitas jusitiae,
89 propter nomen suum.
90 Nam et si ambulavero in medio umbrae mortis,
91 non timebo mala, quoniam tu mecum es:
92 virga tua et baculus tuus ipsa me consolata sunt.
93 EOF
95 test_expect_success "expected conflict markers" "test_cmp test.txt expect.txt"
97 cp backup.txt test.txt
98 test_expect_success "merge with conflicts, using -L" \
99 "test_must_fail git merge-file -L 1 -L 2 test.txt orig.txt new3.txt"
101 cat > expect.txt << EOF
102 <<<<<<< 1
103 Dominus regit me, et nihil mihi deerit.
104 =======
105 DOMINUS regit me,
106 et nihil mihi deerit.
107 >>>>>>> new3.txt
108 In loco pascuae ibi me collocavit,
109 super aquam refectionis educavit me;
110 animam meam convertit,
111 deduxit me super semitas jusitiae,
112 propter nomen suum.
113 Nam et si ambulavero in medio umbrae mortis,
114 non timebo mala, quoniam tu mecum es:
115 virga tua et baculus tuus ipsa me consolata sunt.
118 test_expect_success "expected conflict markers, with -L" \
119 "test_cmp test.txt expect.txt"
121 sed "s/ tu / TU /" < new1.txt > new5.txt
122 test_expect_success "conflict in removed tail" \
123 "test_must_fail git merge-file -p orig.txt new1.txt new5.txt > out"
125 cat > expect << EOF
126 Dominus regit me,
127 et nihil mihi deerit.
128 In loco pascuae ibi me collocavit,
129 super aquam refectionis educavit me;
130 animam meam convertit,
131 deduxit me super semitas jusitiae,
132 propter nomen suum.
133 <<<<<<< orig.txt
134 =======
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.
138 >>>>>>> new5.txt
141 test_expect_success "expected conflict markers" "test_cmp expect out"
143 test_expect_success 'binary files cannot be merged' '
144 test_must_fail git merge-file -p \
145 orig.txt "$TEST_DIRECTORY"/test4012.png new1.txt 2> merge.err &&
146 grep "Cannot merge binary files" merge.err
149 sed -e "s/deerit.\$/deerit;/" -e "s/me;\$/me./" < new5.txt > new6.txt
150 sed -e "s/deerit.\$/deerit,/" -e "s/me;\$/me,/" < new5.txt > new7.txt
152 test_expect_success 'MERGE_ZEALOUS simplifies non-conflicts' '
154 test_must_fail git merge-file -p new6.txt new5.txt new7.txt > output &&
155 test 1 = $(grep ======= < output | wc -l)
159 sed -e 's/deerit./&%%%%/' -e "s/locavit,/locavit;/"< new6.txt | tr '%' '\012' > new8.txt
160 sed -e 's/deerit./&%%%%/' -e "s/locavit,/locavit --/" < new7.txt | tr '%' '\012' > new9.txt
162 test_expect_success 'ZEALOUS_ALNUM' '
164 test_must_fail git merge-file -p \
165 new8.txt new5.txt new9.txt > merge.out &&
166 test 1 = $(grep ======= < merge.out | wc -l)
170 cat >expect <<\EOF
171 Dominus regit me,
172 <<<<<<< new8.txt
173 et nihil mihi deerit;
178 In loco pascuae ibi me collocavit;
179 super aquam refectionis educavit me.
180 |||||||
181 et nihil mihi deerit.
182 In loco pascuae ibi me collocavit,
183 super aquam refectionis educavit me;
184 =======
185 et nihil mihi deerit,
190 In loco pascuae ibi me collocavit --
191 super aquam refectionis educavit me,
192 >>>>>>> new9.txt
193 animam meam convertit,
194 deduxit me super semitas jusitiae,
195 propter nomen suum.
196 Nam et si ambulavero in medio umbrae mortis,
197 non timebo mala, quoniam TU mecum es:
198 virga tua et baculus tuus ipsa me consolata sunt.
201 test_expect_success '"diff3 -m" style output (1)' '
202 test_must_fail git merge-file -p --diff3 \
203 new8.txt new5.txt new9.txt >actual &&
204 test_cmp expect actual
207 test_expect_success '"diff3 -m" style output (2)' '
208 git config merge.conflictstyle diff3 &&
209 test_must_fail git merge-file -p \
210 new8.txt new5.txt new9.txt >actual &&
211 test_cmp expect actual
214 test_done