3 # Copyright (c) 2010 Johan Herland
6 test_description='Test notes merging with auto-resolving strategies'
10 # Set up a notes merge scenario with all kinds of potential conflicts
11 test_expect_success 'setup commits' '
29 commit_sha1=$(git rev-parse 1st^{commit})
30 commit_sha2=$(git rev-parse 2nd^{commit})
31 commit_sha3=$(git rev-parse 3rd^{commit})
32 commit_sha4=$(git rev-parse 4th^{commit})
33 commit_sha5=$(git rev-parse 5th^{commit})
34 commit_sha6=$(git rev-parse 6th^{commit})
35 commit_sha7=$(git rev-parse 7th^{commit})
36 commit_sha8=$(git rev-parse 8th^{commit})
37 commit_sha9=$(git rev-parse 9th^{commit})
38 commit_sha10=$(git rev-parse 10th^{commit})
39 commit_sha11=$(git rev-parse 11th^{commit})
40 commit_sha12=$(git rev-parse 12th^{commit})
41 commit_sha13=$(git rev-parse 13th^{commit})
42 commit_sha14=$(git rev-parse 14th^{commit})
43 commit_sha15=$(git rev-parse 15th^{commit})
48 git -c core.notesRef="refs/notes/$notes_ref" notes |
49 sort >"output_notes_$suffix" &&
50 test_cmp "expect_notes_$suffix" "output_notes_$suffix" &&
51 git -c core.notesRef="refs/notes/$notes_ref" log --format="%H %s%n%N" \
52 >"output_log_$suffix" &&
53 test_cmp "expect_log_$suffix" "output_log_$suffix"
56 test_expect_success 'setup merge base (x)' '
57 git config core.notesRef refs/notes/x &&
58 git notes add -m "x notes on 6th commit" 6th &&
59 git notes add -m "x notes on 7th commit" 7th &&
60 git notes add -m "x notes on 8th commit" 8th &&
61 git notes add -m "x notes on 9th commit" 9th &&
62 git notes add -m "x notes on 10th commit" 10th &&
63 git notes add -m "x notes on 11th commit" 11th &&
64 git notes add -m "x notes on 12th commit" 12th &&
65 git notes add -m "x notes on 13th commit" 13th &&
66 git notes add -m "x notes on 14th commit" 14th &&
67 git notes add -m "x notes on 15th commit" 15th
70 cat <<EOF | sort >expect_notes_x
71 457a85d6c814ea208550f15fcc48f804ac8dc023 $commit_sha15
72 b0c95b954301d69da2bc3723f4cb1680d355937c $commit_sha14
73 5d30216a129eeffa97d9694ffe8c74317a560315 $commit_sha13
74 dd161bc149470fd890dd4ab52a4cbd79bbd18c36 $commit_sha12
75 7abbc45126d680336fb24294f013a7cdfa3ed545 $commit_sha11
76 b8d03e173f67f6505a76f6e00cf93440200dd9be $commit_sha10
77 20c613c835011c48a5abe29170a2402ca6354910 $commit_sha9
78 a3daf8a1e4e5dc3409a303ad8481d57bfea7f5d6 $commit_sha8
79 897003322b53bc6ca098e9324ee508362347e734 $commit_sha7
80 11d97fdebfa5ceee540a3da07bce6fa0222bc082 $commit_sha6
83 cat >expect_log_x <<EOF
85 x notes on 15th commit
88 x notes on 14th commit
91 x notes on 13th commit
94 x notes on 12th commit
97 x notes on 11th commit
100 x notes on 10th commit
103 x notes on 9th commit
106 x notes on 8th commit
109 x notes on 7th commit
112 x notes on 6th commit
126 test_expect_success 'verify state of merge base (x)' 'verify_notes x x'
128 test_expect_success 'setup local branch (y)' '
129 git update-ref refs/notes/y refs/notes/x &&
130 git config core.notesRef refs/notes/y &&
131 git notes add -f -m "y notes on 3rd commit" 3rd &&
132 git notes add -f -m "y notes on 4th commit" 4th &&
133 git notes add -f -m "y notes on 5th commit" 5th &&
134 git notes remove 6th &&
135 git notes remove 7th &&
136 git notes remove 8th &&
137 git notes add -f -m "y notes on 12th commit" 12th &&
138 git notes add -f -m "y notes on 13th commit" 13th &&
139 git notes add -f -m "y notes on 14th commit" 14th &&
140 git notes add -f -m "y notes on 15th commit" 15th
143 cat <<EOF | sort >expect_notes_y
144 68b8630d25516028bed862719855b3d6768d7833 $commit_sha15
145 5de7ea7ad4f47e7ff91989fb82234634730f75df $commit_sha14
146 3a631fdb6f41b05b55d8f4baf20728ba8f6fccbc $commit_sha13
147 a66055fa82f7a03fe0c02a6aba3287a85abf7c62 $commit_sha12
148 7abbc45126d680336fb24294f013a7cdfa3ed545 $commit_sha11
149 b8d03e173f67f6505a76f6e00cf93440200dd9be $commit_sha10
150 20c613c835011c48a5abe29170a2402ca6354910 $commit_sha9
151 154508c7a0bcad82b6fe4b472bc4c26b3bf0825b $commit_sha5
152 e2bfd06a37dd2031684a59a6e2b033e212239c78 $commit_sha4
153 5772f42408c0dd6f097a7ca2d24de0e78d1c46b1 $commit_sha3
156 cat >expect_log_y <<EOF
158 y notes on 15th commit
161 y notes on 14th commit
164 y notes on 13th commit
167 y notes on 12th commit
170 x notes on 11th commit
173 x notes on 10th commit
176 x notes on 9th commit
185 y notes on 5th commit
188 y notes on 4th commit
191 y notes on 3rd commit
199 test_expect_success 'verify state of local branch (y)' 'verify_notes y y'
201 test_expect_success 'setup remote branch (z)' '
202 git update-ref refs/notes/z refs/notes/x &&
203 git config core.notesRef refs/notes/z &&
204 git notes add -f -m "z notes on 2nd commit" 2nd &&
205 git notes add -f -m "y notes on 4th commit" 4th &&
206 git notes add -f -m "z notes on 5th commit" 5th &&
207 git notes remove 6th &&
208 git notes add -f -m "z notes on 8th commit" 8th &&
209 git notes remove 9th &&
210 git notes add -f -m "z notes on 11th commit" 11th &&
211 git notes remove 12th &&
212 git notes add -f -m "y notes on 14th commit" 14th &&
213 git notes add -f -m "z notes on 15th commit" 15th
216 cat <<EOF | sort >expect_notes_z
217 9b4b2c61f0615412da3c10f98ff85b57c04ec765 $commit_sha15
218 5de7ea7ad4f47e7ff91989fb82234634730f75df $commit_sha14
219 5d30216a129eeffa97d9694ffe8c74317a560315 $commit_sha13
220 7e3c53503a3db8dd996cb62e37c66e070b44b54d $commit_sha11
221 b8d03e173f67f6505a76f6e00cf93440200dd9be $commit_sha10
222 851e1638784a884c7dd26c5d41f3340f6387413a $commit_sha8
223 897003322b53bc6ca098e9324ee508362347e734 $commit_sha7
224 99fc34adfc400b95c67b013115e37e31aa9a6d23 $commit_sha5
225 e2bfd06a37dd2031684a59a6e2b033e212239c78 $commit_sha4
226 283b48219aee9a4105f6cab337e789065c82c2b9 $commit_sha2
229 cat >expect_log_z <<EOF
231 z notes on 15th commit
234 y notes on 14th commit
237 x notes on 13th commit
242 z notes on 11th commit
245 x notes on 10th commit
250 z notes on 8th commit
253 x notes on 7th commit
258 z notes on 5th commit
261 y notes on 4th commit
266 z notes on 2nd commit
272 test_expect_success 'verify state of remote branch (z)' 'verify_notes z z'
274 # At this point, before merging z into y, we have the following status:
276 # commit | base/x | local/y | remote/z | diff from x to y/z | result
277 # -------|---------|---------|----------|----------------------------|-------
278 # 1st | [none] | [none] | [none] | unchanged / unchanged | [none]
279 # 2nd | [none] | [none] | 283b482 | unchanged / added | 283b482
280 # 3rd | [none] | 5772f42 | [none] | added / unchanged | 5772f42
281 # 4th | [none] | e2bfd06 | e2bfd06 | added / added (same) | e2bfd06
282 # 5th | [none] | 154508c | 99fc34a | added / added (diff) | ???
283 # 6th | 11d97fd | [none] | [none] | removed / removed | [none]
284 # 7th | 8970033 | [none] | 8970033 | removed / unchanged | [none]
285 # 8th | a3daf8a | [none] | 851e163 | removed / changed | ???
286 # 9th | 20c613c | 20c613c | [none] | unchanged / removed | [none]
287 # 10th | b8d03e1 | b8d03e1 | b8d03e1 | unchanged / unchanged | b8d03e1
288 # 11th | 7abbc45 | 7abbc45 | 7e3c535 | unchanged / changed | 7e3c535
289 # 12th | dd161bc | a66055f | [none] | changed / removed | ???
290 # 13th | 5d30216 | 3a631fd | 5d30216 | changed / unchanged | 3a631fd
291 # 14th | b0c95b9 | 5de7ea7 | 5de7ea7 | changed / changed (same) | 5de7ea7
292 # 15th | 457a85d | 68b8630 | 9b4b2c6 | changed / changed (diff) | ???
294 test_expect_success 'merge z into y with invalid strategy => Fail/No changes' '
295 git config core.notesRef refs/notes/y &&
296 test_must_fail git notes merge --strategy=foo z &&
297 # Verify no changes (y)
301 test_expect_success 'merge z into y with invalid configuration option => Fail/No changes' '
302 git config core.notesRef refs/notes/y &&
303 test_must_fail git -c notes.mergeStrategy="foo" notes merge z &&
304 # Verify no changes (y)
308 cat <<EOF | sort >expect_notes_ours
309 68b8630d25516028bed862719855b3d6768d7833 $commit_sha15
310 5de7ea7ad4f47e7ff91989fb82234634730f75df $commit_sha14
311 3a631fdb6f41b05b55d8f4baf20728ba8f6fccbc $commit_sha13
312 a66055fa82f7a03fe0c02a6aba3287a85abf7c62 $commit_sha12
313 7e3c53503a3db8dd996cb62e37c66e070b44b54d $commit_sha11
314 b8d03e173f67f6505a76f6e00cf93440200dd9be $commit_sha10
315 154508c7a0bcad82b6fe4b472bc4c26b3bf0825b $commit_sha5
316 e2bfd06a37dd2031684a59a6e2b033e212239c78 $commit_sha4
317 5772f42408c0dd6f097a7ca2d24de0e78d1c46b1 $commit_sha3
318 283b48219aee9a4105f6cab337e789065c82c2b9 $commit_sha2
321 cat >expect_log_ours <<EOF
323 y notes on 15th commit
326 y notes on 14th commit
329 y notes on 13th commit
332 y notes on 12th commit
335 z notes on 11th commit
338 x notes on 10th commit
349 y notes on 5th commit
352 y notes on 4th commit
355 y notes on 3rd commit
358 z notes on 2nd commit
364 test_expect_success 'merge z into y with "ours" strategy => Non-conflicting 3-way merge' '
365 git notes merge --strategy=ours z &&
369 test_expect_success 'reset to pre-merge state (y)' '
370 git update-ref refs/notes/y refs/notes/y^1 &&
371 # Verify pre-merge state
375 test_expect_success 'merge z into y with "ours" configuration option => Non-conflicting 3-way merge' '
376 git -c notes.mergeStrategy="ours" notes merge z &&
380 test_expect_success 'reset to pre-merge state (y)' '
381 git update-ref refs/notes/y refs/notes/y^1 &&
382 # Verify pre-merge state
386 test_expect_success 'merge z into y with "ours" per-ref configuration option => Non-conflicting 3-way merge' '
387 git -c notes.y.mergeStrategy="ours" notes merge z &&
391 test_expect_success 'reset to pre-merge state (y)' '
392 git update-ref refs/notes/y refs/notes/y^1 &&
393 # Verify pre-merge state
397 cat <<EOF | sort >expect_notes_theirs
398 9b4b2c61f0615412da3c10f98ff85b57c04ec765 $commit_sha15
399 5de7ea7ad4f47e7ff91989fb82234634730f75df $commit_sha14
400 3a631fdb6f41b05b55d8f4baf20728ba8f6fccbc $commit_sha13
401 7e3c53503a3db8dd996cb62e37c66e070b44b54d $commit_sha11
402 b8d03e173f67f6505a76f6e00cf93440200dd9be $commit_sha10
403 851e1638784a884c7dd26c5d41f3340f6387413a $commit_sha8
404 99fc34adfc400b95c67b013115e37e31aa9a6d23 $commit_sha5
405 e2bfd06a37dd2031684a59a6e2b033e212239c78 $commit_sha4
406 5772f42408c0dd6f097a7ca2d24de0e78d1c46b1 $commit_sha3
407 283b48219aee9a4105f6cab337e789065c82c2b9 $commit_sha2
410 cat >expect_log_theirs <<EOF
412 z notes on 15th commit
415 y notes on 14th commit
418 y notes on 13th commit
423 z notes on 11th commit
426 x notes on 10th commit
431 z notes on 8th commit
438 z notes on 5th commit
441 y notes on 4th commit
444 y notes on 3rd commit
447 z notes on 2nd commit
453 test_expect_success 'merge z into y with "theirs" strategy => Non-conflicting 3-way merge' '
454 git notes merge --strategy=theirs z &&
455 verify_notes y theirs
458 test_expect_success 'reset to pre-merge state (y)' '
459 git update-ref refs/notes/y refs/notes/y^1 &&
460 # Verify pre-merge state
464 test_expect_success 'merge z into y with "theirs" strategy overriding configuration option "ours" => Non-conflicting 3-way merge' '
465 git -c notes.mergeStrategy="ours" notes merge --strategy=theirs z &&
466 verify_notes y theirs
469 test_expect_success 'reset to pre-merge state (y)' '
470 git update-ref refs/notes/y refs/notes/y^1 &&
471 # Verify pre-merge state
475 cat <<EOF | sort >expect_notes_union
476 7c4e546efd0fe939f876beb262ece02797880b54 $commit_sha15
477 5de7ea7ad4f47e7ff91989fb82234634730f75df $commit_sha14
478 3a631fdb6f41b05b55d8f4baf20728ba8f6fccbc $commit_sha13
479 a66055fa82f7a03fe0c02a6aba3287a85abf7c62 $commit_sha12
480 7e3c53503a3db8dd996cb62e37c66e070b44b54d $commit_sha11
481 b8d03e173f67f6505a76f6e00cf93440200dd9be $commit_sha10
482 851e1638784a884c7dd26c5d41f3340f6387413a $commit_sha8
483 6c841cc36ea496027290967ca96bd2bef54dbb47 $commit_sha5
484 e2bfd06a37dd2031684a59a6e2b033e212239c78 $commit_sha4
485 5772f42408c0dd6f097a7ca2d24de0e78d1c46b1 $commit_sha3
486 283b48219aee9a4105f6cab337e789065c82c2b9 $commit_sha2
489 cat >expect_log_union <<EOF
491 y notes on 15th commit
493 z notes on 15th commit
496 y notes on 14th commit
499 y notes on 13th commit
502 y notes on 12th commit
505 z notes on 11th commit
508 x notes on 10th commit
513 z notes on 8th commit
520 y notes on 5th commit
522 z notes on 5th commit
525 y notes on 4th commit
528 y notes on 3rd commit
531 z notes on 2nd commit
537 test_expect_success 'merge z into y with "union" strategy => Non-conflicting 3-way merge' '
538 git notes merge --strategy=union z &&
542 test_expect_success 'reset to pre-merge state (y)' '
543 git update-ref refs/notes/y refs/notes/y^1 &&
544 # Verify pre-merge state
548 test_expect_success 'merge z into y with "union" strategy overriding per-ref configuration => Non-conflicting 3-way merge' '
549 git -c notes.y.mergeStrategy="theirs" notes merge --strategy=union z &&
553 test_expect_success 'reset to pre-merge state (y)' '
554 git update-ref refs/notes/y refs/notes/y^1 &&
555 # Verify pre-merge state
559 test_expect_success 'merge z into y with "union" per-ref overriding general configuration => Non-conflicting 3-way merge' '
560 git -c notes.y.mergeStrategy="union" -c notes.mergeStrategy="theirs" notes merge z &&
564 test_expect_success 'reset to pre-merge state (y)' '
565 git update-ref refs/notes/y refs/notes/y^1 &&
566 # Verify pre-merge state
570 test_expect_success 'merge z into y with "manual" per-ref only checks specific ref configuration => Conflicting 3-way merge' '
571 test_must_fail git -c notes.z.mergeStrategy="union" notes merge z &&
572 git notes merge --abort &&
576 cat <<EOF | sort >expect_notes_union2
577 d682107b8bf7a7aea1e537a8d5cb6a12b60135f1 $commit_sha15
578 5de7ea7ad4f47e7ff91989fb82234634730f75df $commit_sha14
579 3a631fdb6f41b05b55d8f4baf20728ba8f6fccbc $commit_sha13
580 a66055fa82f7a03fe0c02a6aba3287a85abf7c62 $commit_sha12
581 7e3c53503a3db8dd996cb62e37c66e070b44b54d $commit_sha11
582 b8d03e173f67f6505a76f6e00cf93440200dd9be $commit_sha10
583 851e1638784a884c7dd26c5d41f3340f6387413a $commit_sha8
584 357b6ca14c7afd59b7f8b8aaaa6b8b723771135b $commit_sha5
585 e2bfd06a37dd2031684a59a6e2b033e212239c78 $commit_sha4
586 5772f42408c0dd6f097a7ca2d24de0e78d1c46b1 $commit_sha3
587 283b48219aee9a4105f6cab337e789065c82c2b9 $commit_sha2
590 cat >expect_log_union2 <<EOF
592 z notes on 15th commit
594 y notes on 15th commit
597 y notes on 14th commit
600 y notes on 13th commit
603 y notes on 12th commit
606 z notes on 11th commit
609 x notes on 10th commit
614 z notes on 8th commit
621 z notes on 5th commit
623 y notes on 5th commit
626 y notes on 4th commit
629 y notes on 3rd commit
632 z notes on 2nd commit
638 test_expect_success 'merge y into z with "union" strategy => Non-conflicting 3-way merge' '
639 git config core.notesRef refs/notes/z &&
640 git notes merge --strategy=union y &&
641 verify_notes z union2
644 test_expect_success 'reset to pre-merge state (z)' '
645 git update-ref refs/notes/z refs/notes/z^1 &&
646 # Verify pre-merge state
650 cat <<EOF | sort >expect_notes_cat_sort_uniq
651 6be90240b5f54594203e25d9f2f64b7567175aee $commit_sha15
652 5de7ea7ad4f47e7ff91989fb82234634730f75df $commit_sha14
653 3a631fdb6f41b05b55d8f4baf20728ba8f6fccbc $commit_sha13
654 a66055fa82f7a03fe0c02a6aba3287a85abf7c62 $commit_sha12
655 7e3c53503a3db8dd996cb62e37c66e070b44b54d $commit_sha11
656 b8d03e173f67f6505a76f6e00cf93440200dd9be $commit_sha10
657 851e1638784a884c7dd26c5d41f3340f6387413a $commit_sha8
658 660311d7f78dc53db12ac373a43fca7465381a7e $commit_sha5
659 e2bfd06a37dd2031684a59a6e2b033e212239c78 $commit_sha4
660 5772f42408c0dd6f097a7ca2d24de0e78d1c46b1 $commit_sha3
661 283b48219aee9a4105f6cab337e789065c82c2b9 $commit_sha2
664 cat >expect_log_cat_sort_uniq <<EOF
666 y notes on 15th commit
667 z notes on 15th commit
670 y notes on 14th commit
673 y notes on 13th commit
676 y notes on 12th commit
679 z notes on 11th commit
682 x notes on 10th commit
687 z notes on 8th commit
694 y notes on 5th commit
695 z notes on 5th commit
698 y notes on 4th commit
701 y notes on 3rd commit
704 z notes on 2nd commit
710 test_expect_success 'merge y into z with "cat_sort_uniq" strategy => Non-conflicting 3-way merge' '
711 git notes merge --strategy=cat_sort_uniq y &&
712 verify_notes z cat_sort_uniq
715 test_expect_success 'reset to pre-merge state (z)' '
716 git update-ref refs/notes/z refs/notes/z^1 &&
717 # Verify pre-merge state
721 test_expect_success 'merge y into z with "cat_sort_uniq" strategy configuration option => Non-conflicting 3-way merge' '
722 git -c notes.mergeStrategy="cat_sort_uniq" notes merge y &&
723 verify_notes z cat_sort_uniq