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 ! 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' '
227 echo "[OOPS] -$ accepted"
230 if git merge --no-such c1
232 echo "[OOPS] --no-such accepted"
235 if git merge -s foobar c1
237 echo "[OOPS] -s foobar accepted"
240 if git merge -s=foobar c1
242 echo "[OOPS] -s=foobar accepted"
247 echo "[OOPS] missing commit msg accepted"
252 echo "[OOPS] missing commit references accepted"
257 test_expect_success
'merge c0 with c1' '
258 git reset --hard c0 &&
260 verify_merge file result.1 &&
264 test_debug
'gitk --all'
266 test_expect_success
'merge c1 with c2' '
267 git reset --hard c1 &&
270 verify_merge file result.1-5 msg.1-5 &&
271 verify_parents $c1 $c2
274 test_debug
'gitk --all'
276 test_expect_success
'merge c1 with c2 and c3' '
277 git reset --hard c1 &&
280 verify_merge file result.1-5-9 msg.1-5-9 &&
281 verify_parents $c1 $c2 $c3
284 test_debug
'gitk --all'
286 test_expect_success
'merge c0 with c1 (no-commit)' '
287 git reset --hard c0 &&
288 git merge --no-commit c1 &&
289 verify_merge file result.1 &&
293 test_debug
'gitk --all'
295 test_expect_success
'merge c1 with c2 (no-commit)' '
296 git reset --hard c1 &&
297 git merge --no-commit c2 &&
298 verify_merge file result.1-5 &&
300 verify_mergeheads $c2
303 test_debug
'gitk --all'
305 test_expect_success
'merge c1 with c2 and c3 (no-commit)' '
306 git reset --hard c1 &&
307 git merge --no-commit c2 c3 &&
308 verify_merge file result.1-5-9 &&
310 verify_mergeheads $c2 $c3
313 test_debug
'gitk --all'
315 test_expect_success
'merge c0 with c1 (squash)' '
316 git reset --hard c0 &&
317 git merge --squash c1 &&
318 verify_merge file result.1 &&
320 verify_no_mergehead &&
321 verify_diff squash.1 .git/SQUASH_MSG "[OOPS] bad squash message"
324 test_debug
'gitk --all'
326 test_expect_success
'merge c1 with c2 (squash)' '
327 git reset --hard c1 &&
328 git merge --squash c2 &&
329 verify_merge file result.1-5 &&
331 verify_no_mergehead &&
332 verify_diff squash.1-5 .git/SQUASH_MSG "[OOPS] bad squash message"
335 test_debug
'gitk --all'
337 test_expect_success
'merge c1 with c2 and c3 (squash)' '
338 git reset --hard c1 &&
339 git merge --squash c2 c3 &&
340 verify_merge file result.1-5-9 &&
342 verify_no_mergehead &&
343 verify_diff squash.1-5-9 .git/SQUASH_MSG "[OOPS] bad squash message"
346 test_debug
'gitk --all'
348 test_expect_success
'merge c1 with c2 (no-commit in config)' '
349 git reset --hard c1 &&
350 git config branch.master.mergeoptions "--no-commit" &&
352 verify_merge file result.1-5 &&
354 verify_mergeheads $c2
357 test_debug
'gitk --all'
359 test_expect_success
'merge c1 with c2 (squash in config)' '
360 git reset --hard c1 &&
361 git config branch.master.mergeoptions "--squash" &&
363 verify_merge file result.1-5 &&
365 verify_no_mergehead &&
366 verify_diff squash.1-5 .git/SQUASH_MSG "[OOPS] bad squash message"
369 test_debug
'gitk --all'
371 test_expect_success
'override config option -n with --summary' '
372 git reset --hard c1 &&
373 git config branch.master.mergeoptions "-n" &&
375 git merge --summary c2 >diffstat.txt &&
376 verify_merge file result.1-5 msg.1-5 &&
377 verify_parents $c1 $c2 &&
378 if ! grep "^ file | *2 +-$" diffstat.txt
380 echo "[OOPS] diffstat was not generated with --summary"
385 test_expect_success
'override config option -n with --stat' '
386 git reset --hard c1 &&
387 git config branch.master.mergeoptions "-n" &&
389 git merge --stat c2 >diffstat.txt &&
390 verify_merge file result.1-5 msg.1-5 &&
391 verify_parents $c1 $c2 &&
392 if ! grep "^ file | *2 +-$" diffstat.txt
394 echo "[OOPS] diffstat was not generated with --stat"
399 test_debug
'gitk --all'
401 test_expect_success
'override config option --stat' '
402 git reset --hard c1 &&
403 git config branch.master.mergeoptions "--stat" &&
405 git merge -n c2 >diffstat.txt &&
406 verify_merge file result.1-5 msg.1-5 &&
407 verify_parents $c1 $c2 &&
408 if grep "^ file | *2 +-$" diffstat.txt
410 echo "[OOPS] diffstat was generated"
415 test_debug
'gitk --all'
417 test_expect_success
'merge c1 with c2 (override --no-commit)' '
418 git reset --hard c1 &&
419 git config branch.master.mergeoptions "--no-commit" &&
421 git merge --commit c2 &&
422 verify_merge file result.1-5 msg.1-5 &&
423 verify_parents $c1 $c2
426 test_debug
'gitk --all'
428 test_expect_success
'merge c1 with c2 (override --squash)' '
429 git reset --hard c1 &&
430 git config branch.master.mergeoptions "--squash" &&
432 git merge --no-squash c2 &&
433 verify_merge file result.1-5 msg.1-5 &&
434 verify_parents $c1 $c2
437 test_debug
'gitk --all'
439 test_expect_success
'merge c0 with c1 (no-ff)' '
440 git reset --hard c0 &&
441 git config branch.master.mergeoptions "" &&
443 git merge --no-ff c1 &&
444 verify_merge file result.1 &&
445 verify_parents $c0 $c1
448 test_debug
'gitk --all'
450 test_expect_success
'combining --squash and --no-ff is refused' '
451 test_must_fail git merge --squash --no-ff c1 &&
452 test_must_fail git merge --no-ff --squash c1
455 test_expect_success
'merge c0 with c1 (ff overrides no-ff)' '
456 git reset --hard c0 &&
457 git config branch.master.mergeoptions "--no-ff" &&
459 verify_merge file result.1 &&
463 test_expect_success
'merge log message' '
464 git reset --hard c0 &&
465 git merge --no-log c2 &&
466 git show -s --pretty=format:%b HEAD >msg.act &&
467 verify_diff msg.nolog msg.act "[OOPS] bad merge log message" &&
469 git merge --log c3 &&
470 git show -s --pretty=format:%b HEAD >msg.act &&
471 verify_diff msg.log msg.act "[OOPS] bad merge log message" &&
473 git reset --hard HEAD^ &&
474 git config merge.log yes &&
476 git show -s --pretty=format:%b HEAD >msg.act &&
477 verify_diff msg.log msg.act "[OOPS] bad merge log message"
480 test_debug
'gitk --all'
482 test_expect_success
'merge c1 with c0, c2, c0, and c1' '
483 git reset --hard c1 &&
484 git config branch.master.mergeoptions "" &&
486 git merge c0 c2 c0 c1 &&
487 verify_merge file result.1-5 &&
488 verify_parents $c1 $c2
491 test_debug
'gitk --all'
493 test_expect_success
'merge c1 with c0, c2, c0, and c1' '
494 git reset --hard c1 &&
495 git config branch.master.mergeoptions "" &&
497 git merge c0 c2 c0 c1 &&
498 verify_merge file result.1-5 &&
499 verify_parents $c1 $c2
502 test_debug
'gitk --all'
504 test_expect_success
'merge c1 with c1 and c2' '
505 git reset --hard c1 &&
506 git config branch.master.mergeoptions "" &&
509 verify_merge file result.1-5 &&
510 verify_parents $c1 $c2
513 test_debug
'gitk --all'