@matheusbsbs / matheus-bagliano / commits / a85d1b6917
Fork 0

Add test-script for git-merge porcelain

This test-script excercises the porcelainish aspects of git-merge, and does it thoroughly enough to detect a small bug already noticed by Junio: squashing an octopus generates a faulty .git/SQUASH_MSG. Signed-off-by: Lars Hjemli <hjemli@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Lars Hjemli committed Sep 24, 2007 at 00:51 UTC a85d1b69172f397e815e1ce02db41e4b82b86162
1 file changed +344
t/t7600-merge.sh new
+344
@@ -0,0 +1,344 @@
1 +#!/bin/sh
2 +#
3 +# Copyright (c) 2007 Lars Hjemli
4 +#
5 +
6 +test_description='git-merge
7 +
8 +Testing basic merge operations/option parsing.'
9 +
10 +. ./test-lib.sh
11 +
12 +cat >file <<EOF
13 +1
14 +2
15 +3
16 +4
17 +5
18 +6
19 +7
20 +8
21 +9
22 +EOF
23 +
24 +cat >file.1 <<EOF
25 +1 X
26 +2
27 +3
28 +4
29 +5
30 +6
31 +7
32 +8
33 +9
34 +EOF
35 +
36 +cat >file.5 <<EOF
37 +1
38 +2
39 +3
40 +4
41 +5 X
42 +6
43 +7
44 +8
45 +9
46 +EOF
47 +
48 +cat >file.9 <<EOF
49 +1
50 +2
51 +3
52 +4
53 +5
54 +6
55 +7
56 +8
57 +9 X
58 +EOF
59 +
60 +cat >result.1 <<EOF
61 +1 X
62 +2
63 +3
64 +4
65 +5
66 +6
67 +7
68 +8
69 +9
70 +EOF
71 +
72 +cat >result.1-5 <<EOF
73 +1 X
74 +2
75 +3
76 +4
77 +5 X
78 +6
79 +7
80 +8
81 +9
82 +EOF
83 +
84 +cat >result.1-5-9 <<EOF
85 +1 X
86 +2
87 +3
88 +4
89 +5 X
90 +6
91 +7
92 +8
93 +9 X
94 +EOF
95 +
96 +create_merge_msgs() {
97 + echo "Merge commit 'c2'" >msg.1-5 &&
98 + echo "Merge commit 'c2'; commit 'c3'" >msg.1-5-9 &&
99 + echo "Squashed commit of the following:" >squash.1 &&
100 + echo >>squash.1 &&
101 + git log --no-merges ^HEAD c1 >>squash.1 &&
102 + echo "Squashed commit of the following:" >squash.1-5 &&
103 + echo >>squash.1-5 &&
104 + git log --no-merges ^HEAD c2 >>squash.1-5 &&
105 + echo "Squashed commit of the following:" >squash.1-5-9 &&
106 + echo >>squash.1-5-9 &&
107 + git log --no-merges ^HEAD c2 c3 >>squash.1-5-9
108 +}
109 +
110 +verify_diff() {
111 + if ! diff -u "$1" "$2"
112 + then
113 + echo "$3"
114 + false
115 + fi
116 +}
117 +
118 +verify_merge() {
119 + verify_diff "$2" "$1" "[OOPS] bad merge result" &&
120 + if test $(git ls-files -u | wc -l) -gt 0
121 + then
122 + echo "[OOPS] unmerged files"
123 + false
124 + fi &&
125 + if ! git diff --exit-code
126 + then
127 + echo "[OOPS] working tree != index"
128 + false
129 + fi &&
130 + if test -n "$3"
131 + then
132 + git show -s --pretty=format:%s HEAD >msg.act &&
133 + verify_diff "$3" msg.act "[OOPS] bad merge message"
134 + fi
135 +}
136 +
137 +verify_head() {
138 + if test "$1" != "$(git rev-parse HEAD)"
139 + then
140 + echo "[OOPS] HEAD != $1"
141 + false
142 + fi
143 +}
144 +
145 +verify_parents() {
146 + i=1
147 + while test $# -gt 0
148 + do
149 + if test "$1" != "$(git rev-parse HEAD^$i)"
150 + then
151 + echo "[OOPS] HEAD^$i != $1"
152 + return 1
153 + fi
154 + i=$(expr $i + 1)
155 + shift
156 + done
157 +}
158 +
159 +verify_mergeheads() {
160 + i=1
161 + if ! test -f .git/MERGE_HEAD
162 + then
163 + echo "[OOPS] MERGE_HEAD is missing"
164 + false
165 + fi &&
166 + while test $# -gt 0
167 + do
168 + head=$(head -n $i .git/MERGE_HEAD | tail -n 1)
169 + if test "$1" != "$head"
170 + then
171 + echo "[OOPS] MERGE_HEAD $i != $1"
172 + return 1
173 + fi
174 + i=$(expr $i + 1)
175 + shift
176 + done
177 +}
178 +
179 +verify_no_mergehead() {
180 + if test -f .git/MERGE_HEAD
181 + then
182 + echo "[OOPS] MERGE_HEAD exists"
183 + false
184 + fi
185 +}
186 +
187 +
188 +test_expect_success 'setup' '
189 + git add file &&
190 + test_tick &&
191 + git commit -m "commit 0" &&
192 + git tag c0 &&
193 + c0=$(git rev-parse HEAD) &&
194 + cp file.1 file &&
195 + git add file &&
196 + test_tick &&
197 + git commit -m "commit 1" &&
198 + git tag c1 &&
199 + c1=$(git rev-parse HEAD) &&
200 + git reset --hard "$c0" &&
201 + cp file.5 file &&
202 + git add file &&
203 + test_tick &&
204 + git commit -m "commit 2" &&
205 + git tag c2 &&
206 + c2=$(git rev-parse HEAD) &&
207 + git reset --hard "$c0" &&
208 + cp file.9 file &&
209 + git add file &&
210 + test_tick &&
211 + git commit -m "commit 3" &&
212 + git tag c3 &&
213 + c3=$(git rev-parse HEAD)
214 + git reset --hard "$c0" &&
215 + create_merge_msgs
216 +'
217 +
218 +test_debug 'gitk --all'
219 +
220 +test_expect_success 'test option parsing' '
221 + if git merge -$ c1
222 + then
223 + echo "[OOPS] -$ accepted"
224 + false
225 + fi &&
226 + if git merge --no-such c1
227 + then
228 + echo "[OOPS] --no-such accepted"
229 + false
230 + fi &&
231 + if git merge -s foobar c1
232 + then
233 + echo "[OOPS] -s foobar accepted"
234 + false
235 + fi &&
236 + if git merge -s=foobar c1
237 + then
238 + echo "[OOPS] -s=foobar accepted"
239 + false
240 + fi &&
241 + if git merge -m
242 + then
243 + echo "[OOPS] missing commit msg accepted"
244 + false
245 + fi &&
246 + if git merge
247 + then
248 + echo "[OOPS] missing commit references accepted"
249 + false
250 + fi
251 +'
252 +
253 +test_expect_success 'merge c0 with c1' '
254 + git reset --hard c0 &&
255 + git merge c1 &&
256 + verify_merge file result.1 &&
257 + verify_head "$c1"
258 +'
259 +
260 +test_debug 'gitk --all'
261 +
262 +test_expect_success 'merge c1 with c2' '
263 + git reset --hard c1 &&
264 + test_tick &&
265 + git merge c2 &&
266 + verify_merge file result.1-5 msg.1-5 &&
267 + verify_parents $c1 $c2
268 +'
269 +
270 +test_debug 'gitk --all'
271 +
272 +test_expect_success 'merge c1 with c2 and c3' '
273 + git reset --hard c1 &&
274 + test_tick &&
275 + git merge c2 c3 &&
276 + verify_merge file result.1-5-9 msg.1-5-9 &&
277 + verify_parents $c1 $c2 $c3
278 +'
279 +
280 +test_debug 'gitk --all'
281 +
282 +test_expect_success 'merge c0 with c1 (no-commit)' '
283 + git reset --hard c0 &&
284 + git merge --no-commit c1 &&
285 + verify_merge file result.1 &&
286 + verify_head $c1
287 +'
288 +
289 +test_debug 'gitk --all'
290 +
291 +test_expect_success 'merge c1 with c2 (no-commit)' '
292 + git reset --hard c1 &&
293 + git merge --no-commit c2 &&
294 + verify_merge file result.1-5 &&
295 + verify_head $c1 &&
296 + verify_mergeheads $c2
297 +'
298 +
299 +test_debug 'gitk --all'
300 +
301 +test_expect_success 'merge c1 with c2 and c3 (no-commit)' '
302 + git reset --hard c1 &&
303 + git merge --no-commit c2 c3 &&
304 + verify_merge file result.1-5-9 &&
305 + verify_head $c1 &&
306 + verify_mergeheads $c2 $c3
307 +'
308 +
309 +test_debug 'gitk --all'
310 +
311 +test_expect_success 'merge c0 with c1 (squash)' '
312 + git reset --hard c0 &&
313 + git merge --squash c1 &&
314 + verify_merge file result.1 &&
315 + verify_head $c0 &&
316 + verify_no_mergehead &&
317 + verify_diff squash.1 .git/SQUASH_MSG "[OOPS] bad squash message"
318 +'
319 +
320 +test_debug 'gitk --all'
321 +
322 +test_expect_success 'merge c1 with c2 (squash)' '
323 + git reset --hard c1 &&
324 + git merge --squash c2 &&
325 + verify_merge file result.1-5 &&
326 + verify_head $c1 &&
327 + verify_no_mergehead &&
328 + verify_diff squash.1-5 .git/SQUASH_MSG "[OOPS] bad squash message"
329 +'
330 +
331 +test_debug 'gitk --all'
332 +
333 +test_expect_success 'merge c1 with c2 and c3 (squash)' '
334 + git reset --hard c1 &&
335 + git merge --squash c2 c3 &&
336 + verify_merge file result.1-5-9 &&
337 + verify_head $c1 &&
338 + verify_no_mergehead &&
339 + verify_diff squash.1-5-9 .git/SQUASH_MSG "[OOPS] bad squash message"
340 +'
341 +
342 +test_debug 'gitk --all'
343 +
344 +test_done