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 hash04a sha1:6e8e3febca3c2bb896704335cc4d0c34cb2f8715
20 hash03a sha1:e5388c10860456ee60673025345fe2e153eb8cf8
21 hash02a sha1:ceefa674873670e7ecd131814d909723cce2b669
22 hash04b sha1:e2bfd06a37dd2031684a59a6e2b033e212239c78
23 hash03b sha1:5772f42408c0dd6f097a7ca2d24de0e78d1c46b1
24 hash01b sha1:b0a6021ec006d07e80e9b20ec9b444cbd9d560d3
25 hash04c sha1:cff59c793c20bb49a4e01bc06fb06bad642e0d54
26 hash02c sha1:283b48219aee9a4105f6cab337e789065c82c2b9
27 hash01c sha1:0a81da8956346e19bcb27a906f04af327e03e31b
28 hash04d sha1:00494adecf2d9635a02fa431308d67993f853968
29 hash01e sha1:f75d1df88cbfe4258d49852f26cfc83f2ad4494b
30 hash04f sha1:021faa20e931fb48986ffc6282b4bb05553ac946
31 hash01f sha1:0a59e787e6d688aa6309e56e8c1b89431a0fc1c1
32 hash05g sha1:304dfb4325cf243025b9957486eb605a9b51c199
34 hash04a sha256:f18a935e65866345098b3b754071dbf9f3aa3520eb27a7b036b278c5e2f1ed7e
35 hash03a sha256:713035dc94067a64e5fa6e4e1821b7c3bde49a77c7cb3f80eaadefa1ca41b3d2
36 hash02a sha256:f160a67e048b6fa75bec3952184154045076692cf5dccd3da21e3fd34b7a3f0f
37 hash04b sha256:c7fba0d6104917fbf35258f40b9fa4fc697cfa992deecd1570a3b08d0a5587a9
38 hash03b sha256:7287a2d78a3766c181b08df38951d784b08b72a44f571ed6d855bd0be22c70f6
39 hash01b sha256:da96cf778c15d0a2bb76f98b2a62f6c9c01730fa7030e8f08ef0191048e7d620
40 hash04c sha256:cb615d2def4b834d5f55b2351df97dc92bee4f5009d285201427f349081c8aca
41 hash02c sha256:63bb527e0b4e1c8e1dd0d54dd778ca7c3718689fd6e37c473044cfbcf1cacfdb
42 hash01c sha256:5b87237ac1fbae0246256fed9f9a1f077c4140fb7e6444925f8dbfa5ae406cd8
43 hash04d sha256:eeddc9f9f6cb3d6b39b861659853f10891dc373e0b6eecb09e03e39b6ce64714
44 hash01e sha256:108f521b1a74c2e6d0b52a4eda87e09162bf847f7d190cfce496ee1af0b29a5a
45 hash04f sha256:901acda0454502b3bbd281f130c419e6c8de78afcf72a8def8d45ad31462bce4
46 hash01f sha256:a2d99d1b8bf23c8af7d9d91368454adc110dfd5cc068a4cebb486ee8f5a1e16c
47 hash05g sha256:4fef015b01da8efe929a68e3bb9b8fbad81f53995f097befe8ebc93f12ab98ec
51 commit_sha1=$(git rev-parse 1st^{commit})
52 commit_sha2=$(git rev-parse 2nd^{commit})
53 commit_sha3=$(git rev-parse 3rd^{commit})
54 commit_sha4=$(git rev-parse 4th^{commit})
55 commit_sha5=$(git rev-parse 5th^{commit})
59 git -c core.notesRef="refs/notes/$notes_ref" notes |
60 sort >"output_notes_$notes_ref" &&
61 test_cmp "expect_notes_$notes_ref" "output_notes_$notes_ref" &&
62 git -c core.notesRef="refs/notes/$notes_ref" log --format="%H %s%n%N" \
63 >"output_log_$notes_ref" &&
64 test_cmp "expect_log_$notes_ref" "output_log_$notes_ref"
67 cat <<EOF | sort >expect_notes_x
68 $(test_oid hash04a) $commit_sha4
69 $(test_oid hash03a) $commit_sha3
70 $(test_oid hash02a) $commit_sha2
73 cat >expect_log_x <<EOF
89 test_expect_success 'setup merge base (x)' '
90 git config core.notesRef refs/notes/x &&
91 git notes add -m "x notes on 2nd commit" 2nd &&
92 git notes add -m "x notes on 3rd commit" 3rd &&
93 git notes add -m "x notes on 4th commit" 4th &&
97 cat <<EOF | sort >expect_notes_y
98 $(test_oid hash04b) $commit_sha4
99 $(test_oid hash03b) $commit_sha3
100 $(test_oid hash01b) $commit_sha1
103 cat >expect_log_y <<EOF
107 y notes on 4th commit
110 y notes on 3rd commit
115 y notes on 1st commit
119 test_expect_success 'setup local branch (y)' '
120 git update-ref refs/notes/y refs/notes/x &&
121 git config core.notesRef refs/notes/y &&
122 git notes add -f -m "y notes on 1st commit" 1st &&
123 git notes remove 2nd &&
124 git notes add -f -m "y notes on 3rd commit" 3rd &&
125 git notes add -f -m "y notes on 4th commit" 4th &&
129 cat <<EOF | sort >expect_notes_z
130 $(test_oid hash04c) $commit_sha4
131 $(test_oid hash02c) $commit_sha2
132 $(test_oid hash01c) $commit_sha1
135 cat >expect_log_z <<EOF
139 z notes on 4th commit
144 z notes on 2nd commit
147 z notes on 1st commit
151 test_expect_success 'setup remote branch (z)' '
152 git update-ref refs/notes/z refs/notes/x &&
153 git config core.notesRef refs/notes/z &&
154 git notes add -f -m "z notes on 1st commit" 1st &&
155 git notes add -f -m "z notes on 2nd commit" 2nd &&
156 git notes remove 3rd &&
157 git notes add -f -m "z notes on 4th commit" 4th &&
161 # At this point, before merging z into y, we have the following status:
163 # commit | base/x | local/y | remote/z | diff from x to y/z
164 # -------|---------|---------|----------|---------------------------
165 # 1st | [none] | b0a6021 | 0a81da8 | added / added (diff)
166 # 2nd | ceefa67 | [none] | 283b482 | removed / changed
167 # 3rd | e5388c1 | 5772f42 | [none] | changed / removed
168 # 4th | 6e8e3fe | e2bfd06 | cff59c7 | changed / changed (diff)
169 # 5th | [none] | [none] | [none] | [none]
171 cat <<EOF | sort >expect_conflicts
178 cat >expect_conflict_$commit_sha1 <<EOF
180 y notes on 1st commit
182 z notes on 1st commit
186 cat >expect_conflict_$commit_sha2 <<EOF
187 z notes on 2nd commit
190 cat >expect_conflict_$commit_sha3 <<EOF
191 y notes on 3rd commit
194 cat >expect_conflict_$commit_sha4 <<EOF
196 y notes on 4th commit
198 z notes on 4th commit
202 cp expect_notes_y expect_notes_m
203 cp expect_log_y expect_log_m
205 git rev-parse refs/notes/y > pre_merge_y
206 git rev-parse refs/notes/z > pre_merge_z
208 test_expect_success 'merge z into m (== y) with default ("manual") resolver => Conflicting 3-way merge' '
209 git update-ref refs/notes/m refs/notes/y &&
210 git config core.notesRef refs/notes/m &&
211 test_must_fail git notes merge z >output 2>&1 &&
212 # Output should point to where to resolve conflicts
213 test_i18ngrep "\\.git/NOTES_MERGE_WORKTREE" output &&
214 # Inspect merge conflicts
215 ls .git/NOTES_MERGE_WORKTREE >output_conflicts &&
216 test_cmp expect_conflicts output_conflicts &&
217 ( for f in $(cat expect_conflicts); do
218 test_cmp "expect_conflict_$f" ".git/NOTES_MERGE_WORKTREE/$f" ||
221 # Verify that current notes tree (pre-merge) has not changed (m == y)
224 test "$(git rev-parse refs/notes/m)" = "$(cat pre_merge_y)"
227 cat <<EOF | sort >expect_notes_z
228 $(test_oid hash04d) $commit_sha4
229 $(test_oid hash02c) $commit_sha2
230 $(test_oid hash01c) $commit_sha1
233 cat >expect_log_z <<EOF
237 z notes on 4th commit
239 More z notes on 4th commit
244 z notes on 2nd commit
247 z notes on 1st commit
251 test_expect_success 'change notes in z' '
252 git notes --ref z append -m "More z notes on 4th commit" 4th &&
256 test_expect_success 'cannot do merge w/conflicts when previous merge is unfinished' '
257 test -d .git/NOTES_MERGE_WORKTREE &&
258 test_must_fail git notes merge z >output 2>&1 &&
259 # Output should indicate what is wrong
260 test_i18ngrep -q "\\.git/NOTES_MERGE_\\* exists" output
263 # Setup non-conflicting merge between x and new notes ref w
265 cat <<EOF | sort >expect_notes_w
266 $(test_oid hash02a) $commit_sha2
267 $(test_oid hash01e) $commit_sha1
270 cat >expect_log_w <<EOF
278 x notes on 2nd commit
281 w notes on 1st commit
285 test_expect_success 'setup unrelated notes ref (w)' '
286 git config core.notesRef refs/notes/w &&
287 git notes add -m "w notes on 1st commit" 1st &&
288 git notes add -m "x notes on 2nd commit" 2nd &&
292 cat <<EOF | sort >expect_notes_w
293 $(test_oid hash04a) $commit_sha4
294 $(test_oid hash03a) $commit_sha3
295 $(test_oid hash02a) $commit_sha2
296 $(test_oid hash01e) $commit_sha1
299 cat >expect_log_w <<EOF
303 x notes on 4th commit
306 x notes on 3rd commit
309 x notes on 2nd commit
312 w notes on 1st commit
316 test_expect_success 'can do merge without conflicts even if previous merge is unfinished (x => w)' '
317 test -d .git/NOTES_MERGE_WORKTREE &&
320 # Verify that other notes refs has not changed (x and y)
325 cat <<EOF | sort >expect_notes_m
326 $(test_oid hash04f) $commit_sha4
327 $(test_oid hash03b) $commit_sha3
328 $(test_oid hash02c) $commit_sha2
329 $(test_oid hash01f) $commit_sha1
332 cat >expect_log_m <<EOF
336 y and z notes on 4th commit
339 y notes on 3rd commit
342 z notes on 2nd commit
345 y and z notes on 1st commit
349 test_expect_success 'do not allow mixing --commit and --abort' '
350 test_must_fail git notes merge --commit --abort
353 test_expect_success 'do not allow mixing --commit and --strategy' '
354 test_must_fail git notes merge --commit --strategy theirs
357 test_expect_success 'do not allow mixing --abort and --strategy' '
358 test_must_fail git notes merge --abort --strategy theirs
361 test_expect_success 'finalize conflicting merge (z => m)' '
362 # Resolve conflicts and finalize merge
363 cat >.git/NOTES_MERGE_WORKTREE/$commit_sha1 <<EOF &&
364 y and z notes on 1st commit
366 cat >.git/NOTES_MERGE_WORKTREE/$commit_sha4 <<EOF &&
367 y and z notes on 4th commit
369 git notes merge --commit &&
370 # No .git/NOTES_MERGE_* files left
371 test_might_fail ls .git/NOTES_MERGE_* >output 2>/dev/null &&
372 test_must_be_empty output &&
373 # Merge commit has pre-merge y and pre-merge z as parents
374 test "$(git rev-parse refs/notes/m^1)" = "$(cat pre_merge_y)" &&
375 test "$(git rev-parse refs/notes/m^2)" = "$(cat pre_merge_z)" &&
376 # Merge commit mentions the notes refs merged
377 git log -1 --format=%B refs/notes/m > merge_commit_msg &&
378 grep -q refs/notes/m merge_commit_msg &&
379 grep -q refs/notes/z merge_commit_msg &&
380 # Merge commit mentions conflicting notes
381 grep -q "Conflicts" merge_commit_msg &&
382 ( for sha1 in $(cat expect_conflicts); do
383 grep -q "$sha1" merge_commit_msg ||
386 # Verify contents of merge result
388 # Verify that other notes refs has not changed (w, x, y and z)
395 cat >expect_conflict_$commit_sha4 <<EOF
397 y notes on 4th commit
399 z notes on 4th commit
401 More z notes on 4th commit
405 cp expect_notes_y expect_notes_m
406 cp expect_log_y expect_log_m
408 git rev-parse refs/notes/y > pre_merge_y
409 git rev-parse refs/notes/z > pre_merge_z
411 test_expect_success 'redo merge of z into m (== y) with default ("manual") resolver => Conflicting 3-way merge' '
412 git update-ref refs/notes/m refs/notes/y &&
413 git config core.notesRef refs/notes/m &&
414 test_must_fail git notes merge z >output 2>&1 &&
415 # Output should point to where to resolve conflicts
416 test_i18ngrep "\\.git/NOTES_MERGE_WORKTREE" output &&
417 # Inspect merge conflicts
418 ls .git/NOTES_MERGE_WORKTREE >output_conflicts &&
419 test_cmp expect_conflicts output_conflicts &&
420 ( for f in $(cat expect_conflicts); do
421 test_cmp "expect_conflict_$f" ".git/NOTES_MERGE_WORKTREE/$f" ||
424 # Verify that current notes tree (pre-merge) has not changed (m == y)
427 test "$(git rev-parse refs/notes/m)" = "$(cat pre_merge_y)"
430 test_expect_success 'abort notes merge' '
431 git notes merge --abort &&
432 # No .git/NOTES_MERGE_* files left
433 test_might_fail ls .git/NOTES_MERGE_* >output 2>/dev/null &&
434 test_must_be_empty output &&
435 # m has not moved (still == y)
436 test "$(git rev-parse refs/notes/m)" = "$(cat pre_merge_y)" &&
437 # Verify that other notes refs has not changed (w, x, y and z)
444 git rev-parse refs/notes/y > pre_merge_y
445 git rev-parse refs/notes/z > pre_merge_z
447 test_expect_success 'redo merge of z into m (== y) with default ("manual") resolver => Conflicting 3-way merge' '
448 test_must_fail git notes merge z >output 2>&1 &&
449 # Output should point to where to resolve conflicts
450 test_i18ngrep "\\.git/NOTES_MERGE_WORKTREE" output &&
451 # Inspect merge conflicts
452 ls .git/NOTES_MERGE_WORKTREE >output_conflicts &&
453 test_cmp expect_conflicts output_conflicts &&
454 ( for f in $(cat expect_conflicts); do
455 test_cmp "expect_conflict_$f" ".git/NOTES_MERGE_WORKTREE/$f" ||
458 # Verify that current notes tree (pre-merge) has not changed (m == y)
461 test "$(git rev-parse refs/notes/m)" = "$(cat pre_merge_y)"
464 cat <<EOF | sort >expect_notes_m
465 $(test_oid hash05g) $commit_sha5
466 $(test_oid hash02c) $commit_sha2
467 $(test_oid hash01f) $commit_sha1
470 cat >expect_log_m <<EOF
472 new note on 5th commit
479 z notes on 2nd commit
482 y and z notes on 1st commit
486 test_expect_success 'add + remove notes in finalized merge (z => m)' '
487 # Resolve one conflict
488 cat >.git/NOTES_MERGE_WORKTREE/$commit_sha1 <<EOF &&
489 y and z notes on 1st commit
491 # Remove another conflict
492 rm .git/NOTES_MERGE_WORKTREE/$commit_sha4 &&
493 # Remove a D/F conflict
494 rm .git/NOTES_MERGE_WORKTREE/$commit_sha3 &&
496 echo "new note on 5th commit" > .git/NOTES_MERGE_WORKTREE/$commit_sha5 &&
498 git notes merge --commit &&
499 # No .git/NOTES_MERGE_* files left
500 test_might_fail ls .git/NOTES_MERGE_* >output 2>/dev/null &&
501 test_must_be_empty output &&
502 # Merge commit has pre-merge y and pre-merge z as parents
503 test "$(git rev-parse refs/notes/m^1)" = "$(cat pre_merge_y)" &&
504 test "$(git rev-parse refs/notes/m^2)" = "$(cat pre_merge_z)" &&
505 # Merge commit mentions the notes refs merged
506 git log -1 --format=%B refs/notes/m > merge_commit_msg &&
507 grep -q refs/notes/m merge_commit_msg &&
508 grep -q refs/notes/z merge_commit_msg &&
509 # Merge commit mentions conflicting notes
510 grep -q "Conflicts" merge_commit_msg &&
511 ( for sha1 in $(cat expect_conflicts); do
512 grep -q "$sha1" merge_commit_msg ||
515 # Verify contents of merge result
517 # Verify that other notes refs has not changed (w, x, y and z)
524 cp expect_notes_y expect_notes_m
525 cp expect_log_y expect_log_m
527 test_expect_success 'redo merge of z into m (== y) with default ("manual") resolver => Conflicting 3-way merge' '
528 git update-ref refs/notes/m refs/notes/y &&
529 test_must_fail git notes merge z >output 2>&1 &&
530 # Output should point to where to resolve conflicts
531 test_i18ngrep "\\.git/NOTES_MERGE_WORKTREE" output &&
532 # Inspect merge conflicts
533 ls .git/NOTES_MERGE_WORKTREE >output_conflicts &&
534 test_cmp expect_conflicts output_conflicts &&
535 ( for f in $(cat expect_conflicts); do
536 test_cmp "expect_conflict_$f" ".git/NOTES_MERGE_WORKTREE/$f" ||
539 # Verify that current notes tree (pre-merge) has not changed (m == y)
542 test "$(git rev-parse refs/notes/m)" = "$(cat pre_merge_y)"
545 cp expect_notes_w expect_notes_m
546 cp expect_log_w expect_log_m
548 test_expect_success 'reset notes ref m to somewhere else (w)' '
549 git update-ref refs/notes/m refs/notes/w &&
551 test "$(git rev-parse refs/notes/m)" = "$(git rev-parse refs/notes/w)"
554 test_expect_success 'fail to finalize conflicting merge if underlying ref has moved in the meantime (m != NOTES_MERGE_PARTIAL^1)' '
556 cat >.git/NOTES_MERGE_WORKTREE/$commit_sha1 <<EOF &&
557 y and z notes on 1st commit
559 cat >.git/NOTES_MERGE_WORKTREE/$commit_sha4 <<EOF &&
560 y and z notes on 4th commit
562 # Fail to finalize merge
563 test_must_fail git notes merge --commit >output 2>&1 &&
564 # .git/NOTES_MERGE_* must remain
565 test -f .git/NOTES_MERGE_PARTIAL &&
566 test -f .git/NOTES_MERGE_REF &&
567 test -f .git/NOTES_MERGE_WORKTREE/$commit_sha1 &&
568 test -f .git/NOTES_MERGE_WORKTREE/$commit_sha2 &&
569 test -f .git/NOTES_MERGE_WORKTREE/$commit_sha3 &&
570 test -f .git/NOTES_MERGE_WORKTREE/$commit_sha4 &&
572 test "$(git rev-parse refs/notes/m)" = "$(git rev-parse refs/notes/w)" &&
573 test "$(git rev-parse refs/notes/y)" = "$(git rev-parse NOTES_MERGE_PARTIAL^1)" &&
574 test "$(git rev-parse refs/notes/m)" != "$(git rev-parse NOTES_MERGE_PARTIAL^1)" &&
575 # Mention refs/notes/m, and its current and expected value in output
576 test_i18ngrep -q "refs/notes/m" output &&
577 test_i18ngrep -q "$(git rev-parse refs/notes/m)" output &&
578 test_i18ngrep -q "$(git rev-parse NOTES_MERGE_PARTIAL^1)" output &&
579 # Verify that other notes refs has not changed (w, x, y and z)
586 test_expect_success 'resolve situation by aborting the notes merge' '
587 git notes merge --abort &&
588 # No .git/NOTES_MERGE_* files left
589 test_might_fail ls .git/NOTES_MERGE_* >output 2>/dev/null &&
590 test_must_be_empty output &&
591 # m has not moved (still == w)
592 test "$(git rev-parse refs/notes/m)" = "$(git rev-parse refs/notes/w)" &&
593 # Verify that other notes refs has not changed (w, x, y and z)
600 cat >expect_notes <<EOF
605 test_expect_success 'switch cwd before committing notes merge' '
606 git notes add -m foo HEAD &&
607 git notes --ref=other add -m bar HEAD &&
608 test_must_fail git notes merge refs/notes/other &&
610 cd .git/NOTES_MERGE_WORKTREE &&
611 echo "foo" > $(git rev-parse HEAD) &&
612 echo "bar" >> $(git rev-parse HEAD) &&
613 git notes merge --commit
615 git notes show HEAD > actual_notes &&
616 test_cmp expect_notes actual_notes