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 'merge c0 with c1' '
234 git reset --hard c0 &&
236 verify_merge file result.1 &&
240 test_debug 'gitk --all'
242 test_expect_success 'merge c1 with c2' '
243 git reset --hard c1 &&
246 verify_merge file result.1-5 msg.1-5 &&
247 verify_parents $c1 $c2
250 test_debug 'gitk --all'
252 test_expect_success 'merge c1 with c2 and c3' '
253 git reset --hard c1 &&
256 verify_merge file result.1-5-9 msg.1-5-9 &&
257 verify_parents $c1 $c2 $c3
260 test_debug 'gitk --all'
262 test_expect_success 'merge c0 with c1 (no-commit)' '
263 git reset --hard c0 &&
264 git merge --no-commit c1 &&
265 verify_merge file result.1 &&
269 test_debug 'gitk --all'
271 test_expect_success 'merge c1 with c2 (no-commit)' '
272 git reset --hard c1 &&
273 git merge --no-commit c2 &&
274 verify_merge file result.1-5 &&
276 verify_mergeheads $c2
279 test_debug 'gitk --all'
281 test_expect_success 'merge c1 with c2 and c3 (no-commit)' '
282 git reset --hard c1 &&
283 git merge --no-commit c2 c3 &&
284 verify_merge file result.1-5-9 &&
286 verify_mergeheads $c2 $c3
289 test_debug 'gitk --all'
291 test_expect_success 'merge c0 with c1 (squash)' '
292 git reset --hard c0 &&
293 git merge --squash c1 &&
294 verify_merge file result.1 &&
296 verify_no_mergehead &&
297 verify_diff squash.1 .git/SQUASH_MSG "[OOPS] bad squash message"
300 test_debug 'gitk --all'
302 test_expect_success 'merge c1 with c2 (squash)' '
303 git reset --hard c1 &&
304 git merge --squash c2 &&
305 verify_merge file result.1-5 &&
307 verify_no_mergehead &&
308 verify_diff squash.1-5 .git/SQUASH_MSG "[OOPS] bad squash message"
311 test_debug 'gitk --all'
313 test_expect_success 'merge c1 with c2 and c3 (squash)' '
314 git reset --hard c1 &&
315 git merge --squash c2 c3 &&
316 verify_merge file result.1-5-9 &&
318 verify_no_mergehead &&
319 verify_diff squash.1-5-9 .git/SQUASH_MSG "[OOPS] bad squash message"
322 test_debug 'gitk --all'
324 test_expect_success 'merge c1 with c2 (no-commit in config)' '
325 git reset --hard c1 &&
326 git config branch.master.mergeoptions "--no-commit" &&
328 verify_merge file result.1-5 &&
330 verify_mergeheads $c2
333 test_debug 'gitk --all'
335 test_expect_success 'merge c1 with c2 (squash in config)' '
336 git reset --hard c1 &&
337 git config branch.master.mergeoptions "--squash" &&
339 verify_merge file result.1-5 &&
341 verify_no_mergehead &&
342 verify_diff squash.1-5 .git/SQUASH_MSG "[OOPS] bad squash message"
345 test_debug 'gitk --all'
347 test_expect_success 'override config option -n with --summary' '
348 git reset --hard c1 &&
349 git config branch.master.mergeoptions "-n" &&
351 git merge --summary c2 >diffstat.txt &&
352 verify_merge file result.1-5 msg.1-5 &&
353 verify_parents $c1 $c2 &&
354 if ! grep "^ file | *2 +-$" diffstat.txt
356 echo "[OOPS] diffstat was not generated with --summary"
361 test_expect_success 'override config option -n with --stat' '
362 git reset --hard c1 &&
363 git config branch.master.mergeoptions "-n" &&
365 git merge --stat c2 >diffstat.txt &&
366 verify_merge file result.1-5 msg.1-5 &&
367 verify_parents $c1 $c2 &&
368 if ! grep "^ file | *2 +-$" diffstat.txt
370 echo "[OOPS] diffstat was not generated with --stat"
375 test_debug 'gitk --all'
377 test_expect_success 'override config option --stat' '
378 git reset --hard c1 &&
379 git config branch.master.mergeoptions "--stat" &&
381 git merge -n c2 >diffstat.txt &&
382 verify_merge file result.1-5 msg.1-5 &&
383 verify_parents $c1 $c2 &&
384 if grep "^ file | *2 +-$" diffstat.txt
386 echo "[OOPS] diffstat was generated"
391 test_debug 'gitk --all'
393 test_expect_success 'merge c1 with c2 (override --no-commit)' '
394 git reset --hard c1 &&
395 git config branch.master.mergeoptions "--no-commit" &&
397 git merge --commit c2 &&
398 verify_merge file result.1-5 msg.1-5 &&
399 verify_parents $c1 $c2
402 test_debug 'gitk --all'
404 test_expect_success 'merge c1 with c2 (override --squash)' '
405 git reset --hard c1 &&
406 git config branch.master.mergeoptions "--squash" &&
408 git merge --no-squash c2 &&
409 verify_merge file result.1-5 msg.1-5 &&
410 verify_parents $c1 $c2
413 test_debug 'gitk --all'
415 test_expect_success 'merge c0 with c1 (no-ff)' '
416 git reset --hard c0 &&
417 git config branch.master.mergeoptions "" &&
419 git merge --no-ff c1 &&
420 verify_merge file result.1 &&
421 verify_parents $c0 $c1
424 test_debug 'gitk --all'
426 test_expect_success 'combining --squash and --no-ff is refused' '
427 test_must_fail git merge --squash --no-ff c1 &&
428 test_must_fail git merge --no-ff --squash c1
431 test_expect_success 'merge c0 with c1 (ff overrides no-ff)' '
432 git reset --hard c0 &&
433 git config branch.master.mergeoptions "--no-ff" &&
435 verify_merge file result.1 &&
439 test_expect_success 'merge log message' '
440 git reset --hard c0 &&
441 git merge --no-log c2 &&
442 git show -s --pretty=format:%b HEAD >msg.act &&
443 verify_diff msg.nolog msg.act "[OOPS] bad merge log message" &&
445 git merge --log c3 &&
446 git show -s --pretty=format:%b HEAD >msg.act &&
447 verify_diff msg.log msg.act "[OOPS] bad merge log message" &&
449 git reset --hard HEAD^ &&
450 git config merge.log yes &&
452 git show -s --pretty=format:%b HEAD >msg.act &&
453 verify_diff msg.log msg.act "[OOPS] bad merge log message"
456 test_debug 'gitk --all'
458 test_expect_success 'merge c1 with c0, c2, c0, and c1' '
459 git reset --hard c1 &&
460 git config branch.master.mergeoptions "" &&
462 git merge c0 c2 c0 c1 &&
463 verify_merge file result.1-5 &&
464 verify_parents $c1 $c2
467 test_debug 'gitk --all'
469 test_expect_success 'merge c1 with c0, c2, c0, and c1' '
470 git reset --hard c1 &&
471 git config branch.master.mergeoptions "" &&
473 git merge c0 c2 c0 c1 &&
474 verify_merge file result.1-5 &&
475 verify_parents $c1 $c2
478 test_debug 'gitk --all'
480 test_expect_success 'merge c1 with c1 and c2' '
481 git reset --hard c1 &&
482 git config branch.master.mergeoptions "" &&
485 verify_merge file result.1-5 &&
486 verify_parents $c1 $c2
489 test_debug 'gitk --all'