477
verify_notes z
478
'
479
480
+cp expect_notes_y expect_notes_m
481
+cp expect_log_y expect_log_m
482
+
483
+test_expect_success 'redo merge of z into m (== y) with default ("manual") resolver => Conflicting 3-way merge' '
484
+ git update-ref refs/notes/m refs/notes/y &&
485
+ test_must_fail git notes merge z >output &&
486
+ # Output should point to where to resolve conflicts
487
+ grep -q "\\.git/NOTES_MERGE_WORKTREE" output &&
488
+ # Inspect merge conflicts
489
+ ls .git/NOTES_MERGE_WORKTREE >output_conflicts &&
490
+ test_cmp expect_conflicts output_conflicts &&
491
+ ( for f in $(cat expect_conflicts); do
492
+ test_cmp "expect_conflict_$f" ".git/NOTES_MERGE_WORKTREE/$f" ||
493
+ exit 1
494
+ done ) &&
495
+ # Verify that current notes tree (pre-merge) has not changed (m == y)
496
+ verify_notes y &&
497
+ verify_notes m &&
498
+ test "$(git rev-parse refs/notes/m)" = "$(cat pre_merge_y)"
499
+'
500
+
501
+cp expect_notes_w expect_notes_m
502
+cp expect_log_w expect_log_m
503
+
504
+test_expect_success 'reset notes ref m to somewhere else (w)' '
505
+ git update-ref refs/notes/m refs/notes/w &&
506
+ verify_notes m &&
507
+ test "$(git rev-parse refs/notes/m)" = "$(git rev-parse refs/notes/w)"
508
+'
509
+
510
+test_expect_success 'fail to finalize conflicting merge if underlying ref has moved in the meantime (m != NOTES_MERGE_PARTIAL^1)' '
511
+ # Resolve conflicts
512
+ cat >.git/NOTES_MERGE_WORKTREE/$commit_sha1 <<EOF &&
513
+y and z notes on 1st commit
514
+EOF
515
+ cat >.git/NOTES_MERGE_WORKTREE/$commit_sha4 <<EOF &&
516
+y and z notes on 4th commit
517
+EOF
518
+ # Fail to finalize merge
519
+ test_must_fail git notes merge --commit >output 2>&1 &&
520
+ # .git/NOTES_MERGE_* must remain
521
+ test -f .git/NOTES_MERGE_PARTIAL &&
522
+ test -f .git/NOTES_MERGE_REF &&
523
+ test -f .git/NOTES_MERGE_WORKTREE/$commit_sha1 &&
524
+ test -f .git/NOTES_MERGE_WORKTREE/$commit_sha2 &&
525
+ test -f .git/NOTES_MERGE_WORKTREE/$commit_sha3 &&
526
+ test -f .git/NOTES_MERGE_WORKTREE/$commit_sha4 &&
527
+ # Refs are unchanged
528
+ test "$(git rev-parse refs/notes/m)" = "$(git rev-parse refs/notes/w)"
529
+ test "$(git rev-parse refs/notes/y)" = "$(git rev-parse NOTES_MERGE_PARTIAL^1)"
530
+ test "$(git rev-parse refs/notes/m)" != "$(git rev-parse NOTES_MERGE_PARTIAL^1)"
531
+ # Mention refs/notes/m, and its current and expected value in output
532
+ grep -q "refs/notes/m" output &&
533
+ grep -q "$(git rev-parse refs/notes/m)" output &&
534
+ grep -q "$(git rev-parse NOTES_MERGE_PARTIAL^1)" output &&
535
+ # Verify that other notes refs has not changed (w, x, y and z)
536
+ verify_notes w &&
537
+ verify_notes x &&
538
+ verify_notes y &&
539
+ verify_notes z
540
+'
541
+
542
+test_expect_success 'resolve situation by aborting the notes merge' '
543
+ git notes merge --abort &&
544
+ # No .git/NOTES_MERGE_* files left
545
+ test_must_fail ls .git/NOTES_MERGE_* >output 2>/dev/null &&
546
+ test_cmp /dev/null output &&
547
+ # m has not moved (still == w)
548
+ test "$(git rev-parse refs/notes/m)" = "$(git rev-parse refs/notes/w)"
549
+ # Verify that other notes refs has not changed (w, x, y and z)
550
+ verify_notes w &&
551
+ verify_notes x &&
552
+ verify_notes y &&
553
+ verify_notes z
554
+'
555
+
556
test_done