t4200: rerere a merge with two identical conflicts

When the context of multiple identical conflicts are different, two seemingly the same conflict resolution cannot be safely applied. In such a case, at least we should be able to record these two resolutions separately in the rerere database, and reuse them when we see the same conflict later. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Jun 24, 2015 at 14:58 UTC 82efa6e27e76ecd0f52a93886bcee1b8e517a662
1 file changed +74
t/t4200-rerere.sh
+74
@@ -406,4 +406,78 @@ test_expect_success 'rerere -h' '
406 test_i18ngrep [Uu]sage help
407 '
408
409 +concat_insert () {
410 + last=$1
411 + shift
412 + cat early && printf "%s\n" "$@" && cat late "$last"
413 +}
414 +
415 +test_expect_failure 'multiple identical conflicts' '
416 + git reset --hard &&
417 +
418 + test_seq 1 6 >early &&
419 + >late &&
420 + test_seq 11 15 >short &&
421 + test_seq 111 120 >long &&
422 + concat_insert short >file1 &&
423 + concat_insert long >file2 &&
424 + git add file1 file2 &&
425 + git commit -m base &&
426 + git tag base &&
427 + git checkout -b six.1 &&
428 + concat_insert short 6.1 >file1 &&
429 + concat_insert long 6.1 >file2 &&
430 + git add file1 file2 &&
431 + git commit -m 6.1 &&
432 + git checkout -b six.2 HEAD^ &&
433 + concat_insert short 6.2 >file1 &&
434 + concat_insert long 6.2 >file2 &&
435 + git add file1 file2 &&
436 + git commit -m 6.2 &&
437 +
438 + # At this point, six.1 and six.2
439 + # - derive from common ancestor that has two files
440 + # 1...6 7 11..15 (file1) and 1...6 7 111..120 (file2)
441 + # - six.1 replaces these 7s with 6.1
442 + # - six.2 replaces these 7s with 6.2
443 +
444 + test_must_fail git merge six.1 &&
445 +
446 + # Check that rerere knows that file1 and file2 have conflicts
447 +
448 + printf "%s\n" file1 file2 >expect &&
449 + git ls-files -u | sed -e "s/^.* //" | sort -u >actual &&
450 + test_cmp expect actual &&
451 +
452 + git rerere status | sort >actual &&
453 + test_cmp expect actual &&
454 +
455 + # Resolution is to replace 7 with 6.1 and 6.2 (i.e. take both)
456 + concat_insert short 6.1 6.2 >file1 &&
457 + concat_insert long 6.1 6.2 >file2 &&
458 +
459 + git rerere remaining >actual &&
460 + test_cmp expect actual &&
461 +
462 + # We resolved file1 and file2
463 + git rerere &&
464 + >expect &&
465 + git rerere remaining >actual &&
466 + test_cmp expect actual &&
467 +
468 + # Now we should be able to resolve them both
469 + git reset --hard &&
470 + test_must_fail git merge six.1 &&
471 + git rerere &&
472 +
473 + >expect &&
474 + git rerere remaining >actual &&
475 + test_cmp expect actual &&
476 +
477 + concat_insert short 6.1 6.2 >file1.expect &&
478 + concat_insert long 6.1 6.2 >file2.expect &&
479 + test_cmp file1.expect file1 &&
480 + test_cmp file2.expect file2
481 +'
482 +
483 test_done