3 # Copyright (c) 2010 Johan Herland
6 test_description='Test notes merging with manual conflict resolution'
10 # Set up a notes merge scenario with different kinds of conflicts
11 test_expect_success 'setup commits' '
19 commit_sha1=$(git rev-parse 1st^{commit})
20 commit_sha2=$(git rev-parse 2nd^{commit})
21 commit_sha3=$(git rev-parse 3rd^{commit})
22 commit_sha4=$(git rev-parse 4th^{commit})
23 commit_sha5=$(git rev-parse 5th^{commit})
27 git -c core.notesRef="refs/notes/$notes_ref" notes |
28 sort >"output_notes_$notes_ref" &&
29 test_cmp "expect_notes_$notes_ref" "output_notes_$notes_ref" &&
30 git -c core.notesRef="refs/notes/$notes_ref" log --format="%H %s%n%N" \
31 >"output_log_$notes_ref" &&
32 test_cmp "expect_log_$notes_ref" "output_log_$notes_ref"
35 cat <<EOF | sort >expect_notes_x
36 6e8e3febca3c2bb896704335cc4d0c34cb2f8715 $commit_sha4
37 e5388c10860456ee60673025345fe2e153eb8cf8 $commit_sha3
38 ceefa674873670e7ecd131814d909723cce2b669 $commit_sha2
41 cat >expect_log_x <<EOF
57 test_expect_success 'setup merge base (x)' '
58 git config core.notesRef refs/notes/x &&
59 git notes add -m "x notes on 2nd commit" 2nd &&
60 git notes add -m "x notes on 3rd commit" 3rd &&
61 git notes add -m "x notes on 4th commit" 4th &&
65 cat <<EOF | sort >expect_notes_y
66 e2bfd06a37dd2031684a59a6e2b033e212239c78 $commit_sha4
67 5772f42408c0dd6f097a7ca2d24de0e78d1c46b1 $commit_sha3
68 b0a6021ec006d07e80e9b20ec9b444cbd9d560d3 $commit_sha1
71 cat >expect_log_y <<EOF
87 test_expect_success 'setup local branch (y)' '
88 git update-ref refs/notes/y refs/notes/x &&
89 git config core.notesRef refs/notes/y &&
90 git notes add -f -m "y notes on 1st commit" 1st &&
91 git notes remove 2nd &&
92 git notes add -f -m "y notes on 3rd commit" 3rd &&
93 git notes add -f -m "y notes on 4th commit" 4th &&
97 cat <<EOF | sort >expect_notes_z
98 cff59c793c20bb49a4e01bc06fb06bad642e0d54 $commit_sha4
99 283b48219aee9a4105f6cab337e789065c82c2b9 $commit_sha2
100 0a81da8956346e19bcb27a906f04af327e03e31b $commit_sha1
103 cat >expect_log_z <<EOF
107 z notes on 4th commit
112 z notes on 2nd commit
115 z notes on 1st commit
119 test_expect_success 'setup remote branch (z)' '
120 git update-ref refs/notes/z refs/notes/x &&
121 git config core.notesRef refs/notes/z &&
122 git notes add -f -m "z notes on 1st commit" 1st &&
123 git notes add -f -m "z notes on 2nd commit" 2nd &&
124 git notes remove 3rd &&
125 git notes add -f -m "z notes on 4th commit" 4th &&
129 # At this point, before merging z into y, we have the following status:
131 # commit | base/x | local/y | remote/z | diff from x to y/z
132 # -------|---------|---------|----------|---------------------------
133 # 1st | [none] | b0a6021 | 0a81da8 | added / added (diff)
134 # 2nd | ceefa67 | [none] | 283b482 | removed / changed
135 # 3rd | e5388c1 | 5772f42 | [none] | changed / removed
136 # 4th | 6e8e3fe | e2bfd06 | cff59c7 | changed / changed (diff)
137 # 5th | [none] | [none] | [none] | [none]
139 cat <<EOF | sort >expect_conflicts
146 cat >expect_conflict_$commit_sha1 <<EOF
148 y notes on 1st commit
150 z notes on 1st commit
154 cat >expect_conflict_$commit_sha2 <<EOF
155 z notes on 2nd commit
158 cat >expect_conflict_$commit_sha3 <<EOF
159 y notes on 3rd commit
162 cat >expect_conflict_$commit_sha4 <<EOF
164 y notes on 4th commit
166 z notes on 4th commit
170 cp expect_notes_y expect_notes_m
171 cp expect_log_y expect_log_m
173 git rev-parse refs/notes/y > pre_merge_y
174 git rev-parse refs/notes/z > pre_merge_z
176 test_expect_success 'merge z into m (== y) with default ("manual") resolver => Conflicting 3-way merge' '
177 git update-ref refs/notes/m refs/notes/y &&
178 git config core.notesRef refs/notes/m &&
179 test_must_fail git notes merge z >output &&
180 # Output should point to where to resolve conflicts
181 test_i18ngrep "\\.git/NOTES_MERGE_WORKTREE" output &&
182 # Inspect merge conflicts
183 ls .git/NOTES_MERGE_WORKTREE >output_conflicts &&
184 test_cmp expect_conflicts output_conflicts &&
185 ( for f in $(cat expect_conflicts); do
186 test_cmp "expect_conflict_$f" ".git/NOTES_MERGE_WORKTREE/$f" ||
189 # Verify that current notes tree (pre-merge) has not changed (m == y)
192 test "$(git rev-parse refs/notes/m)" = "$(cat pre_merge_y)"
195 cat <<EOF | sort >expect_notes_z
196 00494adecf2d9635a02fa431308d67993f853968 $commit_sha4
197 283b48219aee9a4105f6cab337e789065c82c2b9 $commit_sha2
198 0a81da8956346e19bcb27a906f04af327e03e31b $commit_sha1
201 cat >expect_log_z <<EOF
205 z notes on 4th commit
207 More z notes on 4th commit
212 z notes on 2nd commit
215 z notes on 1st commit
219 test_expect_success 'change notes in z' '
220 git notes --ref z append -m "More z notes on 4th commit" 4th &&
224 test_expect_success 'cannot do merge w/conflicts when previous merge is unfinished' '
225 test -d .git/NOTES_MERGE_WORKTREE &&
226 test_must_fail git notes merge z >output 2>&1 &&
227 # Output should indicate what is wrong
228 test_i18ngrep -q "\\.git/NOTES_MERGE_\\* exists" output
231 # Setup non-conflicting merge between x and new notes ref w
233 cat <<EOF | sort >expect_notes_w
234 ceefa674873670e7ecd131814d909723cce2b669 $commit_sha2
235 f75d1df88cbfe4258d49852f26cfc83f2ad4494b $commit_sha1
238 cat >expect_log_w <<EOF
246 x notes on 2nd commit
249 w notes on 1st commit
253 test_expect_success 'setup unrelated notes ref (w)' '
254 git config core.notesRef refs/notes/w &&
255 git notes add -m "w notes on 1st commit" 1st &&
256 git notes add -m "x notes on 2nd commit" 2nd &&
260 cat <<EOF | sort >expect_notes_w
261 6e8e3febca3c2bb896704335cc4d0c34cb2f8715 $commit_sha4
262 e5388c10860456ee60673025345fe2e153eb8cf8 $commit_sha3
263 ceefa674873670e7ecd131814d909723cce2b669 $commit_sha2
264 f75d1df88cbfe4258d49852f26cfc83f2ad4494b $commit_sha1
267 cat >expect_log_w <<EOF
271 x notes on 4th commit
274 x notes on 3rd commit
277 x notes on 2nd commit
280 w notes on 1st commit
284 test_expect_success 'can do merge without conflicts even if previous merge is unfinished (x => w)' '
285 test -d .git/NOTES_MERGE_WORKTREE &&
288 # Verify that other notes refs has not changed (x and y)
293 cat <<EOF | sort >expect_notes_m
294 021faa20e931fb48986ffc6282b4bb05553ac946 $commit_sha4
295 5772f42408c0dd6f097a7ca2d24de0e78d1c46b1 $commit_sha3
296 283b48219aee9a4105f6cab337e789065c82c2b9 $commit_sha2
297 0a59e787e6d688aa6309e56e8c1b89431a0fc1c1 $commit_sha1
300 cat >expect_log_m <<EOF
304 y and z notes on 4th commit
307 y notes on 3rd commit
310 z notes on 2nd commit
313 y and z notes on 1st commit
317 test_expect_success 'do not allow mixing --commit and --abort' '
318 test_must_fail git notes merge --commit --abort
321 test_expect_success 'do not allow mixing --commit and --strategy' '
322 test_must_fail git notes merge --commit --strategy theirs
325 test_expect_success 'do not allow mixing --abort and --strategy' '
326 test_must_fail git notes merge --abort --strategy theirs
329 test_expect_success 'finalize conflicting merge (z => m)' '
330 # Resolve conflicts and finalize merge
331 cat >.git/NOTES_MERGE_WORKTREE/$commit_sha1 <<EOF &&
332 y and z notes on 1st commit
334 cat >.git/NOTES_MERGE_WORKTREE/$commit_sha4 <<EOF &&
335 y and z notes on 4th commit
337 git notes merge --commit &&
338 # No .git/NOTES_MERGE_* files left
339 test_might_fail ls .git/NOTES_MERGE_* >output 2>/dev/null &&
340 test_cmp /dev/null output &&
341 # Merge commit has pre-merge y and pre-merge z as parents
342 test "$(git rev-parse refs/notes/m^1)" = "$(cat pre_merge_y)" &&
343 test "$(git rev-parse refs/notes/m^2)" = "$(cat pre_merge_z)" &&
344 # Merge commit mentions the notes refs merged
345 git log -1 --format=%B refs/notes/m > merge_commit_msg &&
346 grep -q refs/notes/m merge_commit_msg &&
347 grep -q refs/notes/z merge_commit_msg &&
348 # Merge commit mentions conflicting notes
349 grep -q "Conflicts" merge_commit_msg &&
350 ( for sha1 in $(cat expect_conflicts); do
351 grep -q "$sha1" merge_commit_msg ||
354 # Verify contents of merge result
356 # Verify that other notes refs has not changed (w, x, y and z)
363 cat >expect_conflict_$commit_sha4 <<EOF
365 y notes on 4th commit
367 z notes on 4th commit
369 More z notes on 4th commit
373 cp expect_notes_y expect_notes_m
374 cp expect_log_y expect_log_m
376 git rev-parse refs/notes/y > pre_merge_y
377 git rev-parse refs/notes/z > pre_merge_z
379 test_expect_success 'redo merge of z into m (== y) with default ("manual") resolver => Conflicting 3-way merge' '
380 git update-ref refs/notes/m refs/notes/y &&
381 git config core.notesRef refs/notes/m &&
382 test_must_fail git notes merge z >output &&
383 # Output should point to where to resolve conflicts
384 test_i18ngrep "\\.git/NOTES_MERGE_WORKTREE" output &&
385 # Inspect merge conflicts
386 ls .git/NOTES_MERGE_WORKTREE >output_conflicts &&
387 test_cmp expect_conflicts output_conflicts &&
388 ( for f in $(cat expect_conflicts); do
389 test_cmp "expect_conflict_$f" ".git/NOTES_MERGE_WORKTREE/$f" ||
392 # Verify that current notes tree (pre-merge) has not changed (m == y)
395 test "$(git rev-parse refs/notes/m)" = "$(cat pre_merge_y)"
398 test_expect_success 'abort notes merge' '
399 git notes merge --abort &&
400 # No .git/NOTES_MERGE_* files left
401 test_might_fail ls .git/NOTES_MERGE_* >output 2>/dev/null &&
402 test_cmp /dev/null output &&
403 # m has not moved (still == y)
404 test "$(git rev-parse refs/notes/m)" = "$(cat pre_merge_y)" &&
405 # Verify that other notes refs has not changed (w, x, y and z)
412 git rev-parse refs/notes/y > pre_merge_y
413 git rev-parse refs/notes/z > pre_merge_z
415 test_expect_success 'redo merge of z into m (== y) with default ("manual") resolver => Conflicting 3-way merge' '
416 test_must_fail git notes merge z >output &&
417 # Output should point to where to resolve conflicts
418 test_i18ngrep "\\.git/NOTES_MERGE_WORKTREE" output &&
419 # Inspect merge conflicts
420 ls .git/NOTES_MERGE_WORKTREE >output_conflicts &&
421 test_cmp expect_conflicts output_conflicts &&
422 ( for f in $(cat expect_conflicts); do
423 test_cmp "expect_conflict_$f" ".git/NOTES_MERGE_WORKTREE/$f" ||
426 # Verify that current notes tree (pre-merge) has not changed (m == y)
429 test "$(git rev-parse refs/notes/m)" = "$(cat pre_merge_y)"
432 cat <<EOF | sort >expect_notes_m
433 304dfb4325cf243025b9957486eb605a9b51c199 $commit_sha5
434 283b48219aee9a4105f6cab337e789065c82c2b9 $commit_sha2
435 0a59e787e6d688aa6309e56e8c1b89431a0fc1c1 $commit_sha1
438 cat >expect_log_m <<EOF
440 new note on 5th commit
447 z notes on 2nd commit
450 y and z notes on 1st commit
454 test_expect_success 'add + remove notes in finalized merge (z => m)' '
455 # Resolve one conflict
456 cat >.git/NOTES_MERGE_WORKTREE/$commit_sha1 <<EOF &&
457 y and z notes on 1st commit
459 # Remove another conflict
460 rm .git/NOTES_MERGE_WORKTREE/$commit_sha4 &&
461 # Remove a D/F conflict
462 rm .git/NOTES_MERGE_WORKTREE/$commit_sha3 &&
464 echo "new note on 5th commit" > .git/NOTES_MERGE_WORKTREE/$commit_sha5 &&
466 git notes merge --commit &&
467 # No .git/NOTES_MERGE_* files left
468 test_might_fail ls .git/NOTES_MERGE_* >output 2>/dev/null &&
469 test_cmp /dev/null output &&
470 # Merge commit has pre-merge y and pre-merge z as parents
471 test "$(git rev-parse refs/notes/m^1)" = "$(cat pre_merge_y)" &&
472 test "$(git rev-parse refs/notes/m^2)" = "$(cat pre_merge_z)" &&
473 # Merge commit mentions the notes refs merged
474 git log -1 --format=%B refs/notes/m > merge_commit_msg &&
475 grep -q refs/notes/m merge_commit_msg &&
476 grep -q refs/notes/z merge_commit_msg &&
477 # Merge commit mentions conflicting notes
478 grep -q "Conflicts" merge_commit_msg &&
479 ( for sha1 in $(cat expect_conflicts); do
480 grep -q "$sha1" merge_commit_msg ||
483 # Verify contents of merge result
485 # Verify that other notes refs has not changed (w, x, y and z)
492 cp expect_notes_y expect_notes_m
493 cp expect_log_y expect_log_m
495 test_expect_success 'redo merge of z into m (== y) with default ("manual") resolver => Conflicting 3-way merge' '
496 git update-ref refs/notes/m refs/notes/y &&
497 test_must_fail git notes merge z >output &&
498 # Output should point to where to resolve conflicts
499 test_i18ngrep "\\.git/NOTES_MERGE_WORKTREE" output &&
500 # Inspect merge conflicts
501 ls .git/NOTES_MERGE_WORKTREE >output_conflicts &&
502 test_cmp expect_conflicts output_conflicts &&
503 ( for f in $(cat expect_conflicts); do
504 test_cmp "expect_conflict_$f" ".git/NOTES_MERGE_WORKTREE/$f" ||
507 # Verify that current notes tree (pre-merge) has not changed (m == y)
510 test "$(git rev-parse refs/notes/m)" = "$(cat pre_merge_y)"
513 cp expect_notes_w expect_notes_m
514 cp expect_log_w expect_log_m
516 test_expect_success 'reset notes ref m to somewhere else (w)' '
517 git update-ref refs/notes/m refs/notes/w &&
519 test "$(git rev-parse refs/notes/m)" = "$(git rev-parse refs/notes/w)"
522 test_expect_success 'fail to finalize conflicting merge if underlying ref has moved in the meantime (m != NOTES_MERGE_PARTIAL^1)' '
524 cat >.git/NOTES_MERGE_WORKTREE/$commit_sha1 <<EOF &&
525 y and z notes on 1st commit
527 cat >.git/NOTES_MERGE_WORKTREE/$commit_sha4 <<EOF &&
528 y and z notes on 4th commit
530 # Fail to finalize merge
531 test_must_fail git notes merge --commit >output 2>&1 &&
532 # .git/NOTES_MERGE_* must remain
533 test -f .git/NOTES_MERGE_PARTIAL &&
534 test -f .git/NOTES_MERGE_REF &&
535 test -f .git/NOTES_MERGE_WORKTREE/$commit_sha1 &&
536 test -f .git/NOTES_MERGE_WORKTREE/$commit_sha2 &&
537 test -f .git/NOTES_MERGE_WORKTREE/$commit_sha3 &&
538 test -f .git/NOTES_MERGE_WORKTREE/$commit_sha4 &&
540 test "$(git rev-parse refs/notes/m)" = "$(git rev-parse refs/notes/w)" &&
541 test "$(git rev-parse refs/notes/y)" = "$(git rev-parse NOTES_MERGE_PARTIAL^1)" &&
542 test "$(git rev-parse refs/notes/m)" != "$(git rev-parse NOTES_MERGE_PARTIAL^1)" &&
543 # Mention refs/notes/m, and its current and expected value in output
544 grep -q "refs/notes/m" output &&
545 grep -q "$(git rev-parse refs/notes/m)" output &&
546 grep -q "$(git rev-parse NOTES_MERGE_PARTIAL^1)" output &&
547 # Verify that other notes refs has not changed (w, x, y and z)
554 test_expect_success 'resolve situation by aborting the notes merge' '
555 git notes merge --abort &&
556 # No .git/NOTES_MERGE_* files left
557 test_might_fail ls .git/NOTES_MERGE_* >output 2>/dev/null &&
558 test_cmp /dev/null output &&
559 # m has not moved (still == w)
560 test "$(git rev-parse refs/notes/m)" = "$(git rev-parse refs/notes/w)" &&
561 # Verify that other notes refs has not changed (w, x, y and z)
568 cat >expect_notes <<EOF
573 test_expect_success 'switch cwd before committing notes merge' '
574 git notes add -m foo HEAD &&
575 git notes --ref=other add -m bar HEAD &&
576 test_must_fail git notes merge refs/notes/other &&
578 cd .git/NOTES_MERGE_WORKTREE &&
579 echo "foo" > $(git rev-parse HEAD) &&
580 echo "bar" >> $(git rev-parse HEAD) &&
581 git notes merge --commit
583 git notes show HEAD > actual_notes &&
584 test_cmp expect_notes actual_notes