Merge branch 'mg/diff-uiconfig-doc' into maint
[git] / t / t3309-notes-merge-auto-resolve.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2010 Johan Herland
4 #
5
6 test_description='Test notes merging with auto-resolving strategies'
7
8 . ./test-lib.sh
9
10 # Set up a notes merge scenario with all kinds of potential conflicts
11 test_expect_success 'setup commits' '
12         test_commit 1st &&
13         test_commit 2nd &&
14         test_commit 3rd &&
15         test_commit 4th &&
16         test_commit 5th &&
17         test_commit 6th &&
18         test_commit 7th &&
19         test_commit 8th &&
20         test_commit 9th &&
21         test_commit 10th &&
22         test_commit 11th &&
23         test_commit 12th &&
24         test_commit 13th &&
25         test_commit 14th &&
26         test_commit 15th
27 '
28
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})
44
45 verify_notes () {
46         notes_ref="$1"
47         suffix="$2"
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"
54 }
55
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
68 '
69
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
81 EOF
82
83 cat >expect_log_x <<EOF
84 $commit_sha15 15th
85 x notes on 15th commit
86
87 $commit_sha14 14th
88 x notes on 14th commit
89
90 $commit_sha13 13th
91 x notes on 13th commit
92
93 $commit_sha12 12th
94 x notes on 12th commit
95
96 $commit_sha11 11th
97 x notes on 11th commit
98
99 $commit_sha10 10th
100 x notes on 10th commit
101
102 $commit_sha9 9th
103 x notes on 9th commit
104
105 $commit_sha8 8th
106 x notes on 8th commit
107
108 $commit_sha7 7th
109 x notes on 7th commit
110
111 $commit_sha6 6th
112 x notes on 6th commit
113
114 $commit_sha5 5th
115
116 $commit_sha4 4th
117
118 $commit_sha3 3rd
119
120 $commit_sha2 2nd
121
122 $commit_sha1 1st
123
124 EOF
125
126 test_expect_success 'verify state of merge base (x)' 'verify_notes x x'
127
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
141 '
142
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
154 EOF
155
156 cat >expect_log_y <<EOF
157 $commit_sha15 15th
158 y notes on 15th commit
159
160 $commit_sha14 14th
161 y notes on 14th commit
162
163 $commit_sha13 13th
164 y notes on 13th commit
165
166 $commit_sha12 12th
167 y notes on 12th commit
168
169 $commit_sha11 11th
170 x notes on 11th commit
171
172 $commit_sha10 10th
173 x notes on 10th commit
174
175 $commit_sha9 9th
176 x notes on 9th commit
177
178 $commit_sha8 8th
179
180 $commit_sha7 7th
181
182 $commit_sha6 6th
183
184 $commit_sha5 5th
185 y notes on 5th commit
186
187 $commit_sha4 4th
188 y notes on 4th commit
189
190 $commit_sha3 3rd
191 y notes on 3rd commit
192
193 $commit_sha2 2nd
194
195 $commit_sha1 1st
196
197 EOF
198
199 test_expect_success 'verify state of local branch (y)' 'verify_notes y y'
200
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
214 '
215
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
227 EOF
228
229 cat >expect_log_z <<EOF
230 $commit_sha15 15th
231 z notes on 15th commit
232
233 $commit_sha14 14th
234 y notes on 14th commit
235
236 $commit_sha13 13th
237 x notes on 13th commit
238
239 $commit_sha12 12th
240
241 $commit_sha11 11th
242 z notes on 11th commit
243
244 $commit_sha10 10th
245 x notes on 10th commit
246
247 $commit_sha9 9th
248
249 $commit_sha8 8th
250 z notes on 8th commit
251
252 $commit_sha7 7th
253 x notes on 7th commit
254
255 $commit_sha6 6th
256
257 $commit_sha5 5th
258 z notes on 5th commit
259
260 $commit_sha4 4th
261 y notes on 4th commit
262
263 $commit_sha3 3rd
264
265 $commit_sha2 2nd
266 z notes on 2nd commit
267
268 $commit_sha1 1st
269
270 EOF
271
272 test_expect_success 'verify state of remote branch (z)' 'verify_notes z z'
273
274 # At this point, before merging z into y, we have the following status:
275 #
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) | ???
293
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)
298         verify_notes y y
299 '
300
301 cat <<EOF | sort >expect_notes_ours
302 68b8630d25516028bed862719855b3d6768d7833 $commit_sha15
303 5de7ea7ad4f47e7ff91989fb82234634730f75df $commit_sha14
304 3a631fdb6f41b05b55d8f4baf20728ba8f6fccbc $commit_sha13
305 a66055fa82f7a03fe0c02a6aba3287a85abf7c62 $commit_sha12
306 7e3c53503a3db8dd996cb62e37c66e070b44b54d $commit_sha11
307 b8d03e173f67f6505a76f6e00cf93440200dd9be $commit_sha10
308 154508c7a0bcad82b6fe4b472bc4c26b3bf0825b $commit_sha5
309 e2bfd06a37dd2031684a59a6e2b033e212239c78 $commit_sha4
310 5772f42408c0dd6f097a7ca2d24de0e78d1c46b1 $commit_sha3
311 283b48219aee9a4105f6cab337e789065c82c2b9 $commit_sha2
312 EOF
313
314 cat >expect_log_ours <<EOF
315 $commit_sha15 15th
316 y notes on 15th commit
317
318 $commit_sha14 14th
319 y notes on 14th commit
320
321 $commit_sha13 13th
322 y notes on 13th commit
323
324 $commit_sha12 12th
325 y notes on 12th commit
326
327 $commit_sha11 11th
328 z notes on 11th commit
329
330 $commit_sha10 10th
331 x notes on 10th commit
332
333 $commit_sha9 9th
334
335 $commit_sha8 8th
336
337 $commit_sha7 7th
338
339 $commit_sha6 6th
340
341 $commit_sha5 5th
342 y notes on 5th commit
343
344 $commit_sha4 4th
345 y notes on 4th commit
346
347 $commit_sha3 3rd
348 y notes on 3rd commit
349
350 $commit_sha2 2nd
351 z notes on 2nd commit
352
353 $commit_sha1 1st
354
355 EOF
356
357 test_expect_success 'merge z into y with "ours" strategy => Non-conflicting 3-way merge' '
358         git notes merge --strategy=ours z &&
359         verify_notes y ours
360 '
361
362 test_expect_success 'reset to pre-merge state (y)' '
363         git update-ref refs/notes/y refs/notes/y^1 &&
364         # Verify pre-merge state
365         verify_notes y y
366 '
367
368 cat <<EOF | sort >expect_notes_theirs
369 9b4b2c61f0615412da3c10f98ff85b57c04ec765 $commit_sha15
370 5de7ea7ad4f47e7ff91989fb82234634730f75df $commit_sha14
371 3a631fdb6f41b05b55d8f4baf20728ba8f6fccbc $commit_sha13
372 7e3c53503a3db8dd996cb62e37c66e070b44b54d $commit_sha11
373 b8d03e173f67f6505a76f6e00cf93440200dd9be $commit_sha10
374 851e1638784a884c7dd26c5d41f3340f6387413a $commit_sha8
375 99fc34adfc400b95c67b013115e37e31aa9a6d23 $commit_sha5
376 e2bfd06a37dd2031684a59a6e2b033e212239c78 $commit_sha4
377 5772f42408c0dd6f097a7ca2d24de0e78d1c46b1 $commit_sha3
378 283b48219aee9a4105f6cab337e789065c82c2b9 $commit_sha2
379 EOF
380
381 cat >expect_log_theirs <<EOF
382 $commit_sha15 15th
383 z notes on 15th commit
384
385 $commit_sha14 14th
386 y notes on 14th commit
387
388 $commit_sha13 13th
389 y notes on 13th commit
390
391 $commit_sha12 12th
392
393 $commit_sha11 11th
394 z notes on 11th commit
395
396 $commit_sha10 10th
397 x notes on 10th commit
398
399 $commit_sha9 9th
400
401 $commit_sha8 8th
402 z notes on 8th commit
403
404 $commit_sha7 7th
405
406 $commit_sha6 6th
407
408 $commit_sha5 5th
409 z notes on 5th commit
410
411 $commit_sha4 4th
412 y notes on 4th commit
413
414 $commit_sha3 3rd
415 y notes on 3rd commit
416
417 $commit_sha2 2nd
418 z notes on 2nd commit
419
420 $commit_sha1 1st
421
422 EOF
423
424 test_expect_success 'merge z into y with "theirs" strategy => Non-conflicting 3-way merge' '
425         git notes merge --strategy=theirs z &&
426         verify_notes y theirs
427 '
428
429 test_expect_success 'reset to pre-merge state (y)' '
430         git update-ref refs/notes/y refs/notes/y^1 &&
431         # Verify pre-merge state
432         verify_notes y y
433 '
434
435 cat <<EOF | sort >expect_notes_union
436 7c4e546efd0fe939f876beb262ece02797880b54 $commit_sha15
437 5de7ea7ad4f47e7ff91989fb82234634730f75df $commit_sha14
438 3a631fdb6f41b05b55d8f4baf20728ba8f6fccbc $commit_sha13
439 a66055fa82f7a03fe0c02a6aba3287a85abf7c62 $commit_sha12
440 7e3c53503a3db8dd996cb62e37c66e070b44b54d $commit_sha11
441 b8d03e173f67f6505a76f6e00cf93440200dd9be $commit_sha10
442 851e1638784a884c7dd26c5d41f3340f6387413a $commit_sha8
443 6c841cc36ea496027290967ca96bd2bef54dbb47 $commit_sha5
444 e2bfd06a37dd2031684a59a6e2b033e212239c78 $commit_sha4
445 5772f42408c0dd6f097a7ca2d24de0e78d1c46b1 $commit_sha3
446 283b48219aee9a4105f6cab337e789065c82c2b9 $commit_sha2
447 EOF
448
449 cat >expect_log_union <<EOF
450 $commit_sha15 15th
451 y notes on 15th commit
452
453 z notes on 15th commit
454
455 $commit_sha14 14th
456 y notes on 14th commit
457
458 $commit_sha13 13th
459 y notes on 13th commit
460
461 $commit_sha12 12th
462 y notes on 12th commit
463
464 $commit_sha11 11th
465 z notes on 11th commit
466
467 $commit_sha10 10th
468 x notes on 10th commit
469
470 $commit_sha9 9th
471
472 $commit_sha8 8th
473 z notes on 8th commit
474
475 $commit_sha7 7th
476
477 $commit_sha6 6th
478
479 $commit_sha5 5th
480 y notes on 5th commit
481
482 z notes on 5th commit
483
484 $commit_sha4 4th
485 y notes on 4th commit
486
487 $commit_sha3 3rd
488 y notes on 3rd commit
489
490 $commit_sha2 2nd
491 z notes on 2nd commit
492
493 $commit_sha1 1st
494
495 EOF
496
497 test_expect_success 'merge z into y with "union" strategy => Non-conflicting 3-way merge' '
498         git notes merge --strategy=union z &&
499         verify_notes y union
500 '
501
502 test_expect_success 'reset to pre-merge state (y)' '
503         git update-ref refs/notes/y refs/notes/y^1 &&
504         # Verify pre-merge state
505         verify_notes y y
506 '
507
508 cat <<EOF | sort >expect_notes_union2
509 d682107b8bf7a7aea1e537a8d5cb6a12b60135f1 $commit_sha15
510 5de7ea7ad4f47e7ff91989fb82234634730f75df $commit_sha14
511 3a631fdb6f41b05b55d8f4baf20728ba8f6fccbc $commit_sha13
512 a66055fa82f7a03fe0c02a6aba3287a85abf7c62 $commit_sha12
513 7e3c53503a3db8dd996cb62e37c66e070b44b54d $commit_sha11
514 b8d03e173f67f6505a76f6e00cf93440200dd9be $commit_sha10
515 851e1638784a884c7dd26c5d41f3340f6387413a $commit_sha8
516 357b6ca14c7afd59b7f8b8aaaa6b8b723771135b $commit_sha5
517 e2bfd06a37dd2031684a59a6e2b033e212239c78 $commit_sha4
518 5772f42408c0dd6f097a7ca2d24de0e78d1c46b1 $commit_sha3
519 283b48219aee9a4105f6cab337e789065c82c2b9 $commit_sha2
520 EOF
521
522 cat >expect_log_union2 <<EOF
523 $commit_sha15 15th
524 z notes on 15th commit
525
526 y notes on 15th commit
527
528 $commit_sha14 14th
529 y notes on 14th commit
530
531 $commit_sha13 13th
532 y notes on 13th commit
533
534 $commit_sha12 12th
535 y notes on 12th commit
536
537 $commit_sha11 11th
538 z notes on 11th commit
539
540 $commit_sha10 10th
541 x notes on 10th commit
542
543 $commit_sha9 9th
544
545 $commit_sha8 8th
546 z notes on 8th commit
547
548 $commit_sha7 7th
549
550 $commit_sha6 6th
551
552 $commit_sha5 5th
553 z notes on 5th commit
554
555 y notes on 5th commit
556
557 $commit_sha4 4th
558 y notes on 4th commit
559
560 $commit_sha3 3rd
561 y notes on 3rd commit
562
563 $commit_sha2 2nd
564 z notes on 2nd commit
565
566 $commit_sha1 1st
567
568 EOF
569
570 test_expect_success 'merge y into z with "union" strategy => Non-conflicting 3-way merge' '
571         git config core.notesRef refs/notes/z &&
572         git notes merge --strategy=union y &&
573         verify_notes z union2
574 '
575
576 test_expect_success 'reset to pre-merge state (z)' '
577         git update-ref refs/notes/z refs/notes/z^1 &&
578         # Verify pre-merge state
579         verify_notes z z
580 '
581
582 cat <<EOF | sort >expect_notes_cat_sort_uniq
583 6be90240b5f54594203e25d9f2f64b7567175aee $commit_sha15
584 5de7ea7ad4f47e7ff91989fb82234634730f75df $commit_sha14
585 3a631fdb6f41b05b55d8f4baf20728ba8f6fccbc $commit_sha13
586 a66055fa82f7a03fe0c02a6aba3287a85abf7c62 $commit_sha12
587 7e3c53503a3db8dd996cb62e37c66e070b44b54d $commit_sha11
588 b8d03e173f67f6505a76f6e00cf93440200dd9be $commit_sha10
589 851e1638784a884c7dd26c5d41f3340f6387413a $commit_sha8
590 660311d7f78dc53db12ac373a43fca7465381a7e $commit_sha5
591 e2bfd06a37dd2031684a59a6e2b033e212239c78 $commit_sha4
592 5772f42408c0dd6f097a7ca2d24de0e78d1c46b1 $commit_sha3
593 283b48219aee9a4105f6cab337e789065c82c2b9 $commit_sha2
594 EOF
595
596 cat >expect_log_cat_sort_uniq <<EOF
597 $commit_sha15 15th
598 y notes on 15th commit
599 z notes on 15th commit
600
601 $commit_sha14 14th
602 y notes on 14th commit
603
604 $commit_sha13 13th
605 y notes on 13th commit
606
607 $commit_sha12 12th
608 y notes on 12th commit
609
610 $commit_sha11 11th
611 z notes on 11th commit
612
613 $commit_sha10 10th
614 x notes on 10th commit
615
616 $commit_sha9 9th
617
618 $commit_sha8 8th
619 z notes on 8th commit
620
621 $commit_sha7 7th
622
623 $commit_sha6 6th
624
625 $commit_sha5 5th
626 y notes on 5th commit
627 z notes on 5th commit
628
629 $commit_sha4 4th
630 y notes on 4th commit
631
632 $commit_sha3 3rd
633 y notes on 3rd commit
634
635 $commit_sha2 2nd
636 z notes on 2nd commit
637
638 $commit_sha1 1st
639
640 EOF
641
642 test_expect_success 'merge y into z with "cat_sort_uniq" strategy => Non-conflicting 3-way merge' '
643         git notes merge --strategy=cat_sort_uniq y &&
644         verify_notes z cat_sort_uniq
645 '
646
647 test_done