3 # Copyright (c) 2007 Lars Hjemli
6 test_description
='git-merge
8 Testing basic merge operations/option parsing.'
84 cat >result
.1-5-9 <<EOF
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 &&
101 git log
--no-merges ^HEAD c1
>>squash
.1 &&
102 echo "Squashed commit of the following:" >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 &&
109 echo "* commit 'c3':" >msg.log
&&
110 echo " commit 3" >>msg.log
&&
115 if ! test_cmp
"$1" "$2"
123 verify_diff
"$2" "$1" "[OOPS] bad merge result" &&
124 if test $
(git ls-files
-u |
wc -l) -gt 0
126 echo "[OOPS] unmerged files"
129 if test_must_fail git
diff --exit-code
131 echo "[OOPS] working tree != index"
136 git show
-s --pretty=format
:%s HEAD
>msg.act
&&
137 verify_diff
"$3" msg.act
"[OOPS] bad merge message"
142 if test "$1" != "$(git rev-parse HEAD)"
144 echo "[OOPS] HEAD != $1"
153 if test "$1" != "$(git rev-parse HEAD^$i)"
155 echo "[OOPS] HEAD^$i != $1"
163 verify_mergeheads
() {
165 if ! test -f .git
/MERGE_HEAD
167 echo "[OOPS] MERGE_HEAD is missing"
172 head=$
(head -n $i .git
/MERGE_HEAD |
sed -ne \
$p)
173 if test "$1" != "$head"
175 echo "[OOPS] MERGE_HEAD $i != $1"
183 verify_no_mergehead
() {
184 if test -f .git
/MERGE_HEAD
186 echo "[OOPS] MERGE_HEAD exists"
192 test_expect_success
'setup' '
195 git commit -m "commit 0" &&
197 c0=$(git rev-parse HEAD) &&
201 git commit -m "commit 1" &&
203 c1=$(git rev-parse HEAD) &&
204 git reset --hard "$c0" &&
208 git commit -m "commit 2" &&
210 c2=$(git rev-parse HEAD) &&
211 git reset --hard "$c0" &&
215 git commit -m "commit 3" &&
217 c3=$(git rev-parse HEAD)
218 git reset --hard "$c0" &&
222 test_debug
'gitk --all'
224 test_expect_success
'test option parsing' '
225 test_must_fail git merge -$ c1 &&
226 test_must_fail git merge --no-such c1 &&
227 test_must_fail git merge -s foobar c1 &&
228 test_must_fail git merge -s=foobar c1 &&
229 test_must_fail git merge -m &&
230 test_must_fail git merge
233 test_expect_success
'reject non-strategy with a git-merge-foo name' '
234 test_must_fail git merge -s index c1
237 test_expect_success
'merge c0 with c1' '
238 git reset --hard c0 &&
240 verify_merge file result.1 &&
244 test_debug
'gitk --all'
246 test_expect_success
'merge c1 with c2' '
247 git reset --hard c1 &&
250 verify_merge file result.1-5 msg.1-5 &&
251 verify_parents $c1 $c2
254 test_debug
'gitk --all'
256 test_expect_success
'merge c1 with c2 and c3' '
257 git reset --hard c1 &&
260 verify_merge file result.1-5-9 msg.1-5-9 &&
261 verify_parents $c1 $c2 $c3
264 test_debug
'gitk --all'
266 test_expect_success
'merge c0 with c1 (no-commit)' '
267 git reset --hard c0 &&
268 git merge --no-commit c1 &&
269 verify_merge file result.1 &&
273 test_debug
'gitk --all'
275 test_expect_success
'merge c1 with c2 (no-commit)' '
276 git reset --hard c1 &&
277 git merge --no-commit c2 &&
278 verify_merge file result.1-5 &&
280 verify_mergeheads $c2
283 test_debug
'gitk --all'
285 test_expect_success
'merge c1 with c2 and c3 (no-commit)' '
286 git reset --hard c1 &&
287 git merge --no-commit c2 c3 &&
288 verify_merge file result.1-5-9 &&
290 verify_mergeheads $c2 $c3
293 test_debug
'gitk --all'
295 test_expect_success
'merge c0 with c1 (squash)' '
296 git reset --hard c0 &&
297 git merge --squash c1 &&
298 verify_merge file result.1 &&
300 verify_no_mergehead &&
301 verify_diff squash.1 .git/SQUASH_MSG "[OOPS] bad squash message"
304 test_debug
'gitk --all'
306 test_expect_success
'merge c1 with c2 (squash)' '
307 git reset --hard c1 &&
308 git merge --squash c2 &&
309 verify_merge file result.1-5 &&
311 verify_no_mergehead &&
312 verify_diff squash.1-5 .git/SQUASH_MSG "[OOPS] bad squash message"
315 test_debug
'gitk --all'
317 test_expect_success
'merge c1 with c2 and c3 (squash)' '
318 git reset --hard c1 &&
319 git merge --squash c2 c3 &&
320 verify_merge file result.1-5-9 &&
322 verify_no_mergehead &&
323 verify_diff squash.1-5-9 .git/SQUASH_MSG "[OOPS] bad squash message"
326 test_debug
'gitk --all'
328 test_expect_success
'merge c1 with c2 (no-commit in config)' '
329 git reset --hard c1 &&
330 git config branch.master.mergeoptions "--no-commit" &&
332 verify_merge file result.1-5 &&
334 verify_mergeheads $c2
337 test_debug
'gitk --all'
339 test_expect_success
'merge c1 with c2 (squash in config)' '
340 git reset --hard c1 &&
341 git config branch.master.mergeoptions "--squash" &&
343 verify_merge file result.1-5 &&
345 verify_no_mergehead &&
346 verify_diff squash.1-5 .git/SQUASH_MSG "[OOPS] bad squash message"
349 test_debug
'gitk --all'
351 test_expect_success
'override config option -n with --summary' '
352 git reset --hard c1 &&
353 git config branch.master.mergeoptions "-n" &&
355 git merge --summary c2 >diffstat.txt &&
356 verify_merge file result.1-5 msg.1-5 &&
357 verify_parents $c1 $c2 &&
358 if ! grep "^ file | *2 +-$" diffstat.txt
360 echo "[OOPS] diffstat was not generated with --summary"
365 test_expect_success
'override config option -n with --stat' '
366 git reset --hard c1 &&
367 git config branch.master.mergeoptions "-n" &&
369 git merge --stat c2 >diffstat.txt &&
370 verify_merge file result.1-5 msg.1-5 &&
371 verify_parents $c1 $c2 &&
372 if ! grep "^ file | *2 +-$" diffstat.txt
374 echo "[OOPS] diffstat was not generated with --stat"
379 test_debug
'gitk --all'
381 test_expect_success
'override config option --stat' '
382 git reset --hard c1 &&
383 git config branch.master.mergeoptions "--stat" &&
385 git merge -n c2 >diffstat.txt &&
386 verify_merge file result.1-5 msg.1-5 &&
387 verify_parents $c1 $c2 &&
388 if grep "^ file | *2 +-$" diffstat.txt
390 echo "[OOPS] diffstat was generated"
395 test_debug
'gitk --all'
397 test_expect_success
'merge c1 with c2 (override --no-commit)' '
398 git reset --hard c1 &&
399 git config branch.master.mergeoptions "--no-commit" &&
401 git merge --commit c2 &&
402 verify_merge file result.1-5 msg.1-5 &&
403 verify_parents $c1 $c2
406 test_debug
'gitk --all'
408 test_expect_success
'merge c1 with c2 (override --squash)' '
409 git reset --hard c1 &&
410 git config branch.master.mergeoptions "--squash" &&
412 git merge --no-squash c2 &&
413 verify_merge file result.1-5 msg.1-5 &&
414 verify_parents $c1 $c2
417 test_debug
'gitk --all'
419 test_expect_success
'merge c0 with c1 (no-ff)' '
420 git reset --hard c0 &&
421 git config branch.master.mergeoptions "" &&
423 git merge --no-ff c1 &&
424 verify_merge file result.1 &&
425 verify_parents $c0 $c1
428 test_debug
'gitk --all'
430 test_expect_success
'combining --squash and --no-ff is refused' '
431 test_must_fail git merge --squash --no-ff c1 &&
432 test_must_fail git merge --no-ff --squash c1
435 test_expect_success
'merge c0 with c1 (ff overrides no-ff)' '
436 git reset --hard c0 &&
437 git config branch.master.mergeoptions "--no-ff" &&
439 verify_merge file result.1 &&
443 test_expect_success
'merge log message' '
444 git reset --hard c0 &&
445 git merge --no-log c2 &&
446 git show -s --pretty=format:%b HEAD >msg.act &&
447 verify_diff msg.nolog msg.act "[OOPS] bad merge log message" &&
449 git merge --log c3 &&
450 git show -s --pretty=format:%b HEAD >msg.act &&
451 verify_diff msg.log msg.act "[OOPS] bad merge log message" &&
453 git reset --hard HEAD^ &&
454 git config merge.log yes &&
456 git show -s --pretty=format:%b HEAD >msg.act &&
457 verify_diff msg.log msg.act "[OOPS] bad merge log message"
460 test_debug
'gitk --all'
462 test_expect_success
'merge c1 with c0, c2, c0, and c1' '
463 git reset --hard c1 &&
464 git config branch.master.mergeoptions "" &&
466 git merge c0 c2 c0 c1 &&
467 verify_merge file result.1-5 &&
468 verify_parents $c1 $c2
471 test_debug
'gitk --all'
473 test_expect_success
'merge c1 with c0, c2, c0, and c1' '
474 git reset --hard c1 &&
475 git config branch.master.mergeoptions "" &&
477 git merge c0 c2 c0 c1 &&
478 verify_merge file result.1-5 &&
479 verify_parents $c1 $c2
482 test_debug
'gitk --all'
484 test_expect_success
'merge c1 with c1 and c2' '
485 git reset --hard c1 &&
486 git config branch.master.mergeoptions "" &&
489 verify_merge file result.1-5 &&
490 verify_parents $c1 $c2
493 test_debug
'gitk --all'