#!/bin/sh # # Copyright (c) 2010 Johan Herland # test_description='Test notes merging with manual conflict resolution' . ./test-lib.sh # Set up a notes merge scenario with different kinds of conflicts test_expect_success 'setup commits' ' test_commit 1st && test_commit 2nd && test_commit 3rd && test_commit 4th && test_commit 5th ' commit_sha1=$(git rev-parse 1st^{commit}) commit_sha2=$(git rev-parse 2nd^{commit}) commit_sha3=$(git rev-parse 3rd^{commit}) commit_sha4=$(git rev-parse 4th^{commit}) commit_sha5=$(git rev-parse 5th^{commit}) verify_notes () { notes_ref="$1" git -c core.notesRef="refs/notes/$notes_ref" notes | sort >"output_notes_$notes_ref" && test_cmp "expect_notes_$notes_ref" "output_notes_$notes_ref" && git -c core.notesRef="refs/notes/$notes_ref" log --format="%H %s%n%N" \ >"output_log_$notes_ref" && test_cmp "expect_log_$notes_ref" "output_log_$notes_ref" } cat <expect_notes_x 6e8e3febca3c2bb896704335cc4d0c34cb2f8715 $commit_sha4 e5388c10860456ee60673025345fe2e153eb8cf8 $commit_sha3 ceefa674873670e7ecd131814d909723cce2b669 $commit_sha2 EOF cat >expect_log_x <expect_notes_y e2bfd06a37dd2031684a59a6e2b033e212239c78 $commit_sha4 5772f42408c0dd6f097a7ca2d24de0e78d1c46b1 $commit_sha3 b0a6021ec006d07e80e9b20ec9b444cbd9d560d3 $commit_sha1 EOF cat >expect_log_y <expect_notes_z cff59c793c20bb49a4e01bc06fb06bad642e0d54 $commit_sha4 283b48219aee9a4105f6cab337e789065c82c2b9 $commit_sha2 0a81da8956346e19bcb27a906f04af327e03e31b $commit_sha1 EOF cat >expect_log_z <expect_conflicts $commit_sha1 $commit_sha2 $commit_sha3 $commit_sha4 EOF cat >expect_conflict_$commit_sha1 <>>>>>> refs/notes/z EOF cat >expect_conflict_$commit_sha2 <expect_conflict_$commit_sha3 <expect_conflict_$commit_sha4 <>>>>>> refs/notes/z EOF cp expect_notes_y expect_notes_m cp expect_log_y expect_log_m git rev-parse refs/notes/y > pre_merge_y git rev-parse refs/notes/z > pre_merge_z test_expect_success 'merge z into m (== y) with default ("manual") resolver => Conflicting 3-way merge' ' git update-ref refs/notes/m refs/notes/y && git config core.notesRef refs/notes/m && test_must_fail git notes merge z >output 2>&1 && # Output should point to where to resolve conflicts test_i18ngrep "\\.git/NOTES_MERGE_WORKTREE" output && # Inspect merge conflicts ls .git/NOTES_MERGE_WORKTREE >output_conflicts && test_cmp expect_conflicts output_conflicts && ( for f in $(cat expect_conflicts); do test_cmp "expect_conflict_$f" ".git/NOTES_MERGE_WORKTREE/$f" || exit 1 done ) && # Verify that current notes tree (pre-merge) has not changed (m == y) verify_notes y && verify_notes m && test "$(git rev-parse refs/notes/m)" = "$(cat pre_merge_y)" ' cat <expect_notes_z 00494adecf2d9635a02fa431308d67993f853968 $commit_sha4 283b48219aee9a4105f6cab337e789065c82c2b9 $commit_sha2 0a81da8956346e19bcb27a906f04af327e03e31b $commit_sha1 EOF cat >expect_log_z <output 2>&1 && # Output should indicate what is wrong test_i18ngrep -q "\\.git/NOTES_MERGE_\\* exists" output ' # Setup non-conflicting merge between x and new notes ref w cat <expect_notes_w ceefa674873670e7ecd131814d909723cce2b669 $commit_sha2 f75d1df88cbfe4258d49852f26cfc83f2ad4494b $commit_sha1 EOF cat >expect_log_w <expect_notes_w 6e8e3febca3c2bb896704335cc4d0c34cb2f8715 $commit_sha4 e5388c10860456ee60673025345fe2e153eb8cf8 $commit_sha3 ceefa674873670e7ecd131814d909723cce2b669 $commit_sha2 f75d1df88cbfe4258d49852f26cfc83f2ad4494b $commit_sha1 EOF cat >expect_log_w < w)' ' test -d .git/NOTES_MERGE_WORKTREE && git notes merge x && verify_notes w && # Verify that other notes refs has not changed (x and y) verify_notes x && verify_notes y ' cat <expect_notes_m 021faa20e931fb48986ffc6282b4bb05553ac946 $commit_sha4 5772f42408c0dd6f097a7ca2d24de0e78d1c46b1 $commit_sha3 283b48219aee9a4105f6cab337e789065c82c2b9 $commit_sha2 0a59e787e6d688aa6309e56e8c1b89431a0fc1c1 $commit_sha1 EOF cat >expect_log_m < m)' ' # Resolve conflicts and finalize merge cat >.git/NOTES_MERGE_WORKTREE/$commit_sha1 <.git/NOTES_MERGE_WORKTREE/$commit_sha4 <output 2>/dev/null && test_cmp /dev/null output && # Merge commit has pre-merge y and pre-merge z as parents test "$(git rev-parse refs/notes/m^1)" = "$(cat pre_merge_y)" && test "$(git rev-parse refs/notes/m^2)" = "$(cat pre_merge_z)" && # Merge commit mentions the notes refs merged git log -1 --format=%B refs/notes/m > merge_commit_msg && grep -q refs/notes/m merge_commit_msg && grep -q refs/notes/z merge_commit_msg && # Merge commit mentions conflicting notes grep -q "Conflicts" merge_commit_msg && ( for sha1 in $(cat expect_conflicts); do grep -q "$sha1" merge_commit_msg || exit 1 done ) && # Verify contents of merge result verify_notes m && # Verify that other notes refs has not changed (w, x, y and z) verify_notes w && verify_notes x && verify_notes y && verify_notes z ' cat >expect_conflict_$commit_sha4 <>>>>>> refs/notes/z EOF cp expect_notes_y expect_notes_m cp expect_log_y expect_log_m git rev-parse refs/notes/y > pre_merge_y git rev-parse refs/notes/z > pre_merge_z test_expect_success 'redo merge of z into m (== y) with default ("manual") resolver => Conflicting 3-way merge' ' git update-ref refs/notes/m refs/notes/y && git config core.notesRef refs/notes/m && test_must_fail git notes merge z >output 2>&1 && # Output should point to where to resolve conflicts test_i18ngrep "\\.git/NOTES_MERGE_WORKTREE" output && # Inspect merge conflicts ls .git/NOTES_MERGE_WORKTREE >output_conflicts && test_cmp expect_conflicts output_conflicts && ( for f in $(cat expect_conflicts); do test_cmp "expect_conflict_$f" ".git/NOTES_MERGE_WORKTREE/$f" || exit 1 done ) && # Verify that current notes tree (pre-merge) has not changed (m == y) verify_notes y && verify_notes m && test "$(git rev-parse refs/notes/m)" = "$(cat pre_merge_y)" ' test_expect_success 'abort notes merge' ' git notes merge --abort && # No .git/NOTES_MERGE_* files left test_might_fail ls .git/NOTES_MERGE_* >output 2>/dev/null && test_cmp /dev/null output && # m has not moved (still == y) test "$(git rev-parse refs/notes/m)" = "$(cat pre_merge_y)" && # Verify that other notes refs has not changed (w, x, y and z) verify_notes w && verify_notes x && verify_notes y && verify_notes z ' git rev-parse refs/notes/y > pre_merge_y git rev-parse refs/notes/z > pre_merge_z test_expect_success 'redo merge of z into m (== y) with default ("manual") resolver => Conflicting 3-way merge' ' test_must_fail git notes merge z >output 2>&1 && # Output should point to where to resolve conflicts test_i18ngrep "\\.git/NOTES_MERGE_WORKTREE" output && # Inspect merge conflicts ls .git/NOTES_MERGE_WORKTREE >output_conflicts && test_cmp expect_conflicts output_conflicts && ( for f in $(cat expect_conflicts); do test_cmp "expect_conflict_$f" ".git/NOTES_MERGE_WORKTREE/$f" || exit 1 done ) && # Verify that current notes tree (pre-merge) has not changed (m == y) verify_notes y && verify_notes m && test "$(git rev-parse refs/notes/m)" = "$(cat pre_merge_y)" ' cat <expect_notes_m 304dfb4325cf243025b9957486eb605a9b51c199 $commit_sha5 283b48219aee9a4105f6cab337e789065c82c2b9 $commit_sha2 0a59e787e6d688aa6309e56e8c1b89431a0fc1c1 $commit_sha1 EOF cat >expect_log_m < m)' ' # Resolve one conflict cat >.git/NOTES_MERGE_WORKTREE/$commit_sha1 < .git/NOTES_MERGE_WORKTREE/$commit_sha5 && # Finalize merge git notes merge --commit && # No .git/NOTES_MERGE_* files left test_might_fail ls .git/NOTES_MERGE_* >output 2>/dev/null && test_cmp /dev/null output && # Merge commit has pre-merge y and pre-merge z as parents test "$(git rev-parse refs/notes/m^1)" = "$(cat pre_merge_y)" && test "$(git rev-parse refs/notes/m^2)" = "$(cat pre_merge_z)" && # Merge commit mentions the notes refs merged git log -1 --format=%B refs/notes/m > merge_commit_msg && grep -q refs/notes/m merge_commit_msg && grep -q refs/notes/z merge_commit_msg && # Merge commit mentions conflicting notes grep -q "Conflicts" merge_commit_msg && ( for sha1 in $(cat expect_conflicts); do grep -q "$sha1" merge_commit_msg || exit 1 done ) && # Verify contents of merge result verify_notes m && # Verify that other notes refs has not changed (w, x, y and z) verify_notes w && verify_notes x && verify_notes y && verify_notes z ' cp expect_notes_y expect_notes_m cp expect_log_y expect_log_m test_expect_success 'redo merge of z into m (== y) with default ("manual") resolver => Conflicting 3-way merge' ' git update-ref refs/notes/m refs/notes/y && test_must_fail git notes merge z >output 2>&1 && # Output should point to where to resolve conflicts test_i18ngrep "\\.git/NOTES_MERGE_WORKTREE" output && # Inspect merge conflicts ls .git/NOTES_MERGE_WORKTREE >output_conflicts && test_cmp expect_conflicts output_conflicts && ( for f in $(cat expect_conflicts); do test_cmp "expect_conflict_$f" ".git/NOTES_MERGE_WORKTREE/$f" || exit 1 done ) && # Verify that current notes tree (pre-merge) has not changed (m == y) verify_notes y && verify_notes m && test "$(git rev-parse refs/notes/m)" = "$(cat pre_merge_y)" ' cp expect_notes_w expect_notes_m cp expect_log_w expect_log_m test_expect_success 'reset notes ref m to somewhere else (w)' ' git update-ref refs/notes/m refs/notes/w && verify_notes m && test "$(git rev-parse refs/notes/m)" = "$(git rev-parse refs/notes/w)" ' test_expect_success 'fail to finalize conflicting merge if underlying ref has moved in the meantime (m != NOTES_MERGE_PARTIAL^1)' ' # Resolve conflicts cat >.git/NOTES_MERGE_WORKTREE/$commit_sha1 <.git/NOTES_MERGE_WORKTREE/$commit_sha4 <output 2>&1 && # .git/NOTES_MERGE_* must remain test -f .git/NOTES_MERGE_PARTIAL && test -f .git/NOTES_MERGE_REF && test -f .git/NOTES_MERGE_WORKTREE/$commit_sha1 && test -f .git/NOTES_MERGE_WORKTREE/$commit_sha2 && test -f .git/NOTES_MERGE_WORKTREE/$commit_sha3 && test -f .git/NOTES_MERGE_WORKTREE/$commit_sha4 && # Refs are unchanged test "$(git rev-parse refs/notes/m)" = "$(git rev-parse refs/notes/w)" && test "$(git rev-parse refs/notes/y)" = "$(git rev-parse NOTES_MERGE_PARTIAL^1)" && test "$(git rev-parse refs/notes/m)" != "$(git rev-parse NOTES_MERGE_PARTIAL^1)" && # Mention refs/notes/m, and its current and expected value in output grep -q "refs/notes/m" output && grep -q "$(git rev-parse refs/notes/m)" output && grep -q "$(git rev-parse NOTES_MERGE_PARTIAL^1)" output && # Verify that other notes refs has not changed (w, x, y and z) verify_notes w && verify_notes x && verify_notes y && verify_notes z ' test_expect_success 'resolve situation by aborting the notes merge' ' git notes merge --abort && # No .git/NOTES_MERGE_* files left test_might_fail ls .git/NOTES_MERGE_* >output 2>/dev/null && test_cmp /dev/null output && # m has not moved (still == w) test "$(git rev-parse refs/notes/m)" = "$(git rev-parse refs/notes/w)" && # Verify that other notes refs has not changed (w, x, y and z) verify_notes w && verify_notes x && verify_notes y && verify_notes z ' cat >expect_notes < $(git rev-parse HEAD) && echo "bar" >> $(git rev-parse HEAD) && git notes merge --commit ) && git notes show HEAD > actual_notes && test_cmp expect_notes actual_notes ' test_done