t6036: tests for criss-cross merges with various directory/file conflicts

Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Aug 11, 2011 at 23:19 UTC 827f2b7d297dfbe20809c0be600827834c2c3992
1 file changed +159
t/t6036-recursive-corner-cases.sh
+159
@@ -4,6 +4,12 @@ test_description='recursive merge corner cases involving criss-cross merges'
4
5 . ./test-lib.sh
6
7 +get_clean_checkout () {
8 + git reset --hard &&
9 + git clean -fdqx &&
10 + git checkout "$1"
11 +}
12 +
13 #
14 # L1 L2
15 # o---o
@@ -397,4 +403,157 @@ test_expect_failure 'git detects conflict w/ criss-cross+contrived resolution' '
403 test $(git rev-parse :3:file) = $(git rev-parse E:file)
404 '
405
406 +#
407 +# criss-cross + d/f conflict via add/add:
408 +# Commit A: Neither file 'a' nor directory 'a/' exist.
409 +# Commit B: Introduce 'a'
410 +# Commit C: Introduce 'a/file'
411 +# Commit D: Merge B & C, keeping 'a' and deleting 'a/'
412 +#
413 +# Two different later cases:
414 +# Commit E1: Merge B & C, deleting 'a' but keeping 'a/file'
415 +# Commit E2: Merge B & C, deleting 'a' but keeping a slightly modified 'a/file'
416 +#
417 +# B D
418 +# o---o
419 +# / \ / \
420 +# A o X ? F
421 +# \ / \ /
422 +# o---o
423 +# C E1 or E2
424 +#
425 +# Merging D & E1 requires we first create a virtual merge base X from
426 +# merging A & B in memory. Now, if X could keep both 'a' and 'a/file' in
427 +# the index, then the merge of D & E1 could be resolved cleanly with both
428 +# 'a' and 'a/file' removed. Since git does not currently allow creating
429 +# such a tree, the best we can do is have X contain both 'a~<unique>' and
430 +# 'a/file' resulting in the merge of D and E1 having a rename/delete
431 +# conflict for 'a'. (Although this merge appears to be unsolvable with git
432 +# currently, git could do a lot better than it currently does with these
433 +# d/f conflicts, which is the purpose of this test.)
434 +#
435 +# Merge of D & E2 has similar issues for path 'a', but should always result
436 +# in a modify/delete conflict for path 'a/file'.
437 +#
438 +# We run each merge in both directions, to check for directional issues
439 +# with D/F conflict handling.
440 +#
441 +
442 +test_expect_success 'setup differently handled merges of directory/file conflict' '
443 + git rm -rf . &&
444 + git clean -fdqx &&
445 + rm -rf .git &&
446 + git init &&
447 +
448 + >ignore-me &&
449 + git add ignore-me &&
450 + test_tick &&
451 + git commit -m A &&
452 + git tag A &&
453 +
454 + git branch B &&
455 + git checkout -b C &&
456 + mkdir a &&
457 + echo 10 >a/file &&
458 + git add a/file &&
459 + test_tick &&
460 + git commit -m C &&
461 +
462 + git checkout B &&
463 + echo 5 >a &&
464 + git add a &&
465 + test_tick &&
466 + git commit -m B &&
467 +
468 + git checkout B^0 &&
469 + test_must_fail git merge C &&
470 + git clean -f &&
471 + rm -rf a/ &&
472 + echo 5 >a &&
473 + git add a &&
474 + test_tick &&
475 + git commit -m D &&
476 + git tag D &&
477 +
478 + git checkout C^0 &&
479 + test_must_fail git merge B &&
480 + git clean -f &&
481 + git rm --cached a &&
482 + echo 10 >a/file &&
483 + git add a/file &&
484 + test_tick &&
485 + git commit -m E1 &&
486 + git tag E1 &&
487 +
488 + git checkout C^0 &&
489 + test_must_fail git merge B &&
490 + git clean -f &&
491 + git rm --cached a &&
492 + printf "10\n11\n" >a/file &&
493 + git add a/file &&
494 + test_tick &&
495 + git commit -m E2 &&
496 + git tag E2
497 +'
498 +
499 +test_expect_failure 'merge of D & E1 fails but has appropriate contents' '
500 + get_clean_checkout D^0 &&
501 +
502 + test_must_fail git merge -s recursive E1^0 &&
503 +
504 + test 2 -eq $(git ls-files -s | wc -l) &&
505 + test 1 -eq $(git ls-files -u | wc -l) &&
506 + test 0 -eq $(git ls-files -o | wc -l) &&
507 +
508 + test $(git rev-parse :0:ignore-me) = $(git rev-parse A:ignore-me) &&
509 + test $(git rev-parse :2:a) = $(git rev-parse B:a)
510 +'
511 +
512 +test_expect_failure 'merge of E1 & D fails but has appropriate contents' '
513 + get_clean_checkout E1^0 &&
514 +
515 + test_must_fail git merge -s recursive D^0 &&
516 +
517 + test 2 -eq $(git ls-files -s | wc -l) &&
518 + test 1 -eq $(git ls-files -u | wc -l) &&
519 + test 0 -eq $(git ls-files -o | wc -l) &&
520 +
521 + test $(git rev-parse :0:ignore-me) = $(git rev-parse A:ignore-me) &&
522 + test $(git rev-parse :3:a) = $(git rev-parse B:a)
523 +'
524 +
525 +test_expect_success 'merge of D & E2 fails but has appropriate contents' '
526 + get_clean_checkout D^0 &&
527 +
528 + test_must_fail git merge -s recursive E2^0 &&
529 +
530 + test 4 -eq $(git ls-files -s | wc -l) &&
531 + test 3 -eq $(git ls-files -u | wc -l) &&
532 + test 1 -eq $(git ls-files -o | wc -l) &&
533 +
534 + test $(git rev-parse :2:a) = $(git rev-parse B:a) &&
535 + test $(git rev-parse :3:a/file) = $(git rev-parse E2:a/file) &&
536 + test $(git rev-parse :1:a/file) = $(git rev-parse C:a/file) &&
537 + test $(git rev-parse :0:ignore-me) = $(git rev-parse A:ignore-me) &&
538 +
539 + test -f a~HEAD
540 +'
541 +
542 +test_expect_failure 'merge of E2 & D fails but has appropriate contents' '
543 + get_clean_checkout E2^0 &&
544 +
545 + test_must_fail git merge -s recursive D^0 &&
546 +
547 + test 4 -eq $(git ls-files -s | wc -l) &&
548 + test 3 -eq $(git ls-files -u | wc -l) &&
549 + test 1 -eq $(git ls-files -o | wc -l) &&
550 +
551 + test $(git rev-parse :3:a) = $(git rev-parse B:a) &&
552 + test $(git rev-parse :2:a/file) = $(git rev-parse E2:a/file) &&
553 + test $(git rev-parse :1:a/file) = $(git rev-parse C:a/file)
554 + test $(git rev-parse :0:ignore-me) = $(git rev-parse A:ignore-me) &&
555 +
556 + test -f a~D^0
557 +'
558 +
559 test_done