23c3b6dffa220a8d88ec16d3089199485c20b6ba
1#!/bin/sh
2
3test_description="recursive merge corner cases w/ renames but not criss-crosses"
4# t6036 has corner cases that involve both criss-cross merges and renames
5
6. ./test-lib.sh
7
8test_expect_success 'setup rename/delete + untracked file' '
9 test_create_repo rename-delete-untracked &&
10 (
11 cd rename-delete-untracked &&
12
13 echo "A pretty inscription" >ring &&
14 git add ring &&
15 test_tick &&
16 git commit -m beginning &&
17
18 git branch people &&
19 git checkout -b rename-the-ring &&
20 git mv ring one-ring-to-rule-them-all &&
21 test_tick &&
22 git commit -m fullname &&
23
24 git checkout people &&
25 git rm ring &&
26 echo gollum >owner &&
27 git add owner &&
28 test_tick &&
29 git commit -m track-people-instead-of-objects &&
30 echo "Myyy PRECIOUSSS" >ring
31 )
32'
33
34test_expect_success "Does git preserve Gollum's precious artifact?" '
35 (
36 cd rename-delete-untracked &&
37
38 test_must_fail git merge -s recursive rename-the-ring &&
39
40 # Make sure git did not delete an untracked file
41 test_path_is_file ring
42 )
43'
44
45# Testcase setup for rename/modify/add-source:
46# Commit A: new file: a
47# Commit B: modify a slightly
48# Commit C: rename a->b, add completely different a
49#
50# We should be able to merge B & C cleanly
51
52test_expect_success 'setup rename/modify/add-source conflict' '
53 test_create_repo rename-modify-add-source &&
54 (
55 cd rename-modify-add-source &&
56
57 printf "1\n2\n3\n4\n5\n6\n7\n" >a &&
58 git add a &&
59 git commit -m A &&
60 git tag A &&
61
62 git checkout -b B A &&
63 echo 8 >>a &&
64 git add a &&
65 git commit -m B &&
66
67 git checkout -b C A &&
68 git mv a b &&
69 echo something completely different >a &&
70 git add a &&
71 git commit -m C
72 )
73'
74
75test_expect_failure 'rename/modify/add-source conflict resolvable' '
76 (
77 cd rename-modify-add-source &&
78
79 git checkout B^0 &&
80
81 git merge -s recursive C^0 &&
82
83 git rev-parse >expect \
84 B:a C:a &&
85 git rev-parse >actual \
86 b c &&
87 test_cmp expect actual
88 )
89'
90
91test_expect_success 'setup resolvable conflict missed if rename missed' '
92 test_create_repo break-detection-1 &&
93 (
94 cd break-detection-1 &&
95
96 printf "1\n2\n3\n4\n5\n" >a &&
97 echo foo >b &&
98 git add a b &&
99 git commit -m A &&
100 git tag A &&
101
102 git checkout -b B A &&
103 git mv a c &&
104 echo "Completely different content" >a &&
105 git add a &&
106 git commit -m B &&
107
108 git checkout -b C A &&
109 echo 6 >>a &&
110 git add a &&
111 git commit -m C
112 )
113'
114
115test_expect_failure 'conflict caused if rename not detected' '
116 (
117 cd break-detection-1 &&
118
119 git checkout -q C^0 &&
120 git merge -s recursive B^0 &&
121
122 git ls-files -s >out &&
123 test_line_count = 3 out &&
124 git ls-files -u >out &&
125 test_line_count = 0 out &&
126 git ls-files -o >out &&
127 test_line_count = 1 out &&
128
129 test_line_count = 6 c &&
130 git rev-parse >expect \
131 B:a A:b &&
132 git rev-parse >actual \
133 :0:a :0:b &&
134 test_cmp expect actual
135 )
136'
137
138test_expect_success 'setup conflict resolved wrong if rename missed' '
139 test_create_repo break-detection-2 &&
140 (
141 cd break-detection-2 &&
142
143 printf "1\n2\n3\n4\n5\n" >a &&
144 echo foo >b &&
145 git add a b &&
146 git commit -m A &&
147 git tag A &&
148
149 git checkout -b D A &&
150 echo 7 >>a &&
151 git add a &&
152 git mv a c &&
153 echo "Completely different content" >a &&
154 git add a &&
155 git commit -m D &&
156
157 git checkout -b E A &&
158 git rm a &&
159 echo "Completely different content" >>a &&
160 git add a &&
161 git commit -m E
162 )
163'
164
165test_expect_failure 'missed conflict if rename not detected' '
166 (
167 cd break-detection-2 &&
168
169 git checkout -q E^0 &&
170 test_must_fail git merge -s recursive D^0
171 )
172'
173
174# Tests for undetected rename/add-source causing a file to erroneously be
175# deleted (and for mishandled rename/rename(1to1) causing the same issue).
176#
177# This test uses a rename/rename(1to1)+add-source conflict (1to1 means the
178# same file is renamed on both sides to the same thing; it should trigger
179# the 1to2 logic, which it would do if the add-source didn't cause issues
180# for git's rename detection):
181# Commit A: new file: a
182# Commit B: rename a->b
183# Commit C: rename a->b, add unrelated a
184
185test_expect_success 'setup undetected rename/add-source causes data loss' '
186 test_create_repo break-detection-3 &&
187 (
188 cd break-detection-3 &&
189
190 printf "1\n2\n3\n4\n5\n" >a &&
191 git add a &&
192 git commit -m A &&
193 git tag A &&
194
195 git checkout -b B A &&
196 git mv a b &&
197 git commit -m B &&
198
199 git checkout -b C A &&
200 git mv a b &&
201 echo foobar >a &&
202 git add a &&
203 git commit -m C
204 )
205'
206
207test_expect_failure 'detect rename/add-source and preserve all data' '
208 (
209 cd break-detection-3 &&
210
211 git checkout B^0 &&
212
213 git merge -s recursive C^0 &&
214
215 git ls-files -s >out &&
216 test_line_count = 2 out &&
217 git ls-files -u >out &&
218 test_line_count = 2 out &&
219 git ls-files -o >out &&
220 test_line_count = 1 out &&
221
222 test_path_is_file a &&
223 test_path_is_file b &&
224
225 git rev-parse >expect \
226 A:a C:a &&
227 git rev-parse >actual \
228 :0:b :0:a &&
229 test_cmp expect actual
230 )
231'
232
233test_expect_failure 'detect rename/add-source and preserve all data, merge other way' '
234 (
235 cd break-detection-3 &&
236
237 git checkout C^0 &&
238
239 git merge -s recursive B^0 &&
240
241 git ls-files -s >out &&
242 test_line_count = 2 out &&
243 git ls-files -u >out &&
244 test_line_count = 2 out &&
245 git ls-files -o >out &&
246 test_line_count = 1 out &&
247
248 test_path_is_file a &&
249 test_path_is_file b &&
250
251 git rev-parse >expect \
252 A:a C:a &&
253 git rev-parse >actual \
254 :0:b :0:a &&
255 test_cmp expect actual
256 )
257'
258
259test_expect_success 'setup content merge + rename/directory conflict' '
260 test_create_repo rename-directory-1 &&
261 (
262 cd rename-directory-1 &&
263
264 printf "1\n2\n3\n4\n5\n6\n" >file &&
265 git add file &&
266 test_tick &&
267 git commit -m base &&
268 git tag base &&
269
270 git checkout -b right &&
271 echo 7 >>file &&
272 mkdir newfile &&
273 echo junk >newfile/realfile &&
274 git add file newfile/realfile &&
275 test_tick &&
276 git commit -m right &&
277
278 git checkout -b left-conflict base &&
279 echo 8 >>file &&
280 git add file &&
281 git mv file newfile &&
282 test_tick &&
283 git commit -m left &&
284
285 git checkout -b left-clean base &&
286 echo 0 >newfile &&
287 cat file >>newfile &&
288 git add newfile &&
289 git rm file &&
290 test_tick &&
291 git commit -m left
292 )
293'
294
295test_expect_success 'rename/directory conflict + clean content merge' '
296 (
297 cd rename-directory-1 &&
298
299 git checkout left-clean^0 &&
300
301 test_must_fail git merge -s recursive right^0 &&
302
303 git ls-files -s >out &&
304 test_line_count = 2 out &&
305 git ls-files -u >out &&
306 test_line_count = 1 out &&
307 git ls-files -o >out &&
308 test_line_count = 2 out &&
309
310 echo 0 >expect &&
311 git cat-file -p base:file >>expect &&
312 echo 7 >>expect &&
313 test_cmp expect newfile~HEAD &&
314
315 test $(git rev-parse :2:newfile) = $(git hash-object expect) &&
316
317 test_path_is_file newfile/realfile &&
318 test_path_is_file newfile~HEAD
319 )
320'
321
322test_expect_success 'rename/directory conflict + content merge conflict' '
323 (
324 cd rename-directory-1 &&
325
326 git reset --hard &&
327 git clean -fdqx &&
328
329 git checkout left-conflict^0 &&
330
331 test_must_fail git merge -s recursive right^0 &&
332
333 git ls-files -s >out &&
334 test_line_count = 4 out &&
335 git ls-files -u >out &&
336 test_line_count = 3 out &&
337 git ls-files -o >out &&
338 test_line_count = 2 out &&
339
340 git cat-file -p left-conflict:newfile >left &&
341 git cat-file -p base:file >base &&
342 git cat-file -p right:file >right &&
343 test_must_fail git merge-file \
344 -L "HEAD:newfile" \
345 -L "" \
346 -L "right^0:file" \
347 left base right &&
348 test_cmp left newfile~HEAD &&
349
350 git rev-parse >expect \
351 base:file left-conflict:newfile right:file &&
352 git rev-parse >actual \
353 :1:newfile :2:newfile :3:newfile &&
354 test_cmp expect actual &&
355
356 test_path_is_file newfile/realfile &&
357 test_path_is_file newfile~HEAD
358 )
359'
360
361test_expect_success 'setup content merge + rename/directory conflict w/ disappearing dir' '
362 test_create_repo rename-directory-2 &&
363 (
364 cd rename-directory-2 &&
365
366 mkdir sub &&
367 printf "1\n2\n3\n4\n5\n6\n" >sub/file &&
368 git add sub/file &&
369 test_tick &&
370 git commit -m base &&
371 git tag base &&
372
373 git checkout -b right &&
374 echo 7 >>sub/file &&
375 git add sub/file &&
376 test_tick &&
377 git commit -m right &&
378
379 git checkout -b left base &&
380 echo 0 >newfile &&
381 cat sub/file >>newfile &&
382 git rm sub/file &&
383 mv newfile sub &&
384 git add sub &&
385 test_tick &&
386 git commit -m left
387 )
388'
389
390test_expect_success 'disappearing dir in rename/directory conflict handled' '
391 (
392 cd rename-directory-2 &&
393
394 git checkout left^0 &&
395
396 git merge -s recursive right^0 &&
397
398 git ls-files -s >out &&
399 test_line_count = 1 out &&
400 git ls-files -u >out &&
401 test_line_count = 0 out &&
402 git ls-files -o >out &&
403 test_line_count = 1 out &&
404
405 echo 0 >expect &&
406 git cat-file -p base:sub/file >>expect &&
407 echo 7 >>expect &&
408 test_cmp expect sub &&
409
410 test_path_is_file sub
411 )
412'
413
414# Test for all kinds of things that can go wrong with rename/rename (2to1):
415# Commit A: new files: a & b
416# Commit B: rename a->c, modify b
417# Commit C: rename b->c, modify a
418#
419# Merging of B & C should NOT be clean. Questions:
420# * Both a & b should be removed by the merge; are they?
421# * The two c's should contain modifications to a & b; do they?
422# * The index should contain two files, both for c; does it?
423# * The working copy should have two files, both of form c~<unique>; does it?
424# * Nothing else should be present. Is anything?
425
426test_expect_success 'setup rename/rename (2to1) + modify/modify' '
427 test_create_repo rename-rename-2to1 &&
428 (
429 cd rename-rename-2to1 &&
430
431 printf "1\n2\n3\n4\n5\n" >a &&
432 printf "5\n4\n3\n2\n1\n" >b &&
433 git add a b &&
434 git commit -m A &&
435 git tag A &&
436
437 git checkout -b B A &&
438 git mv a c &&
439 echo 0 >>b &&
440 git add b &&
441 git commit -m B &&
442
443 git checkout -b C A &&
444 git mv b c &&
445 echo 6 >>a &&
446 git add a &&
447 git commit -m C
448 )
449'
450
451test_expect_success 'handle rename/rename (2to1) conflict correctly' '
452 (
453 cd rename-rename-2to1 &&
454
455 git checkout B^0 &&
456
457 test_must_fail git merge -s recursive C^0 >out &&
458 test_i18ngrep "CONFLICT (rename/rename)" out &&
459
460 git ls-files -s >out &&
461 test_line_count = 2 out &&
462 git ls-files -u >out &&
463 test_line_count = 2 out &&
464 git ls-files -u c >out &&
465 test_line_count = 2 out &&
466 git ls-files -o >out &&
467 test_line_count = 3 out &&
468
469 test_path_is_missing a &&
470 test_path_is_missing b &&
471 test_path_is_file c~HEAD &&
472 test_path_is_file c~C^0 &&
473
474 git rev-parse >expect \
475 C:a B:b &&
476 git hash-object >actual \
477 c~HEAD c~C^0 &&
478 test_cmp expect actual
479 )
480'
481
482# Testcase setup for simple rename/rename (1to2) conflict:
483# Commit A: new file: a
484# Commit B: rename a->b
485# Commit C: rename a->c
486test_expect_success 'setup simple rename/rename (1to2) conflict' '
487 test_create_repo rename-rename-1to2 &&
488 (
489 cd rename-rename-1to2 &&
490
491 echo stuff >a &&
492 git add a &&
493 test_tick &&
494 git commit -m A &&
495 git tag A &&
496
497 git checkout -b B A &&
498 git mv a b &&
499 test_tick &&
500 git commit -m B &&
501
502 git checkout -b C A &&
503 git mv a c &&
504 test_tick &&
505 git commit -m C
506 )
507'
508
509test_expect_success 'merge has correct working tree contents' '
510 (
511 cd rename-rename-1to2 &&
512
513 git checkout C^0 &&
514
515 test_must_fail git merge -s recursive B^0 &&
516
517 git ls-files -s >out &&
518 test_line_count = 3 out &&
519 git ls-files -u >out &&
520 test_line_count = 3 out &&
521 git ls-files -o >out &&
522 test_line_count = 1 out &&
523
524 test_path_is_missing a &&
525 git rev-parse >expect \
526 A:a A:a A:a \
527 A:a A:a &&
528 git rev-parse >actual \
529 :1:a :3:b :2:c &&
530 git hash-object >>actual \
531 b c &&
532 test_cmp expect actual
533 )
534'
535
536# Testcase setup for rename/rename(1to2)/add-source conflict:
537# Commit A: new file: a
538# Commit B: rename a->b
539# Commit C: rename a->c, add completely different a
540#
541# Merging of B & C should NOT be clean; there's a rename/rename conflict
542
543test_expect_success 'setup rename/rename(1to2)/add-source conflict' '
544 test_create_repo rename-rename-1to2-add-source-1 &&
545 (
546 cd rename-rename-1to2-add-source-1 &&
547
548 printf "1\n2\n3\n4\n5\n6\n7\n" >a &&
549 git add a &&
550 git commit -m A &&
551 git tag A &&
552
553 git checkout -b B A &&
554 git mv a b &&
555 git commit -m B &&
556
557 git checkout -b C A &&
558 git mv a c &&
559 echo something completely different >a &&
560 git add a &&
561 git commit -m C
562 )
563'
564
565test_expect_failure 'detect conflict with rename/rename(1to2)/add-source merge' '
566 (
567 cd rename-rename-1to2-add-source-1 &&
568
569 git checkout B^0 &&
570
571 test_must_fail git merge -s recursive C^0 &&
572
573 git ls-files -s >out &&
574 test_line_count = 4 out &&
575 git ls-files -o >out &&
576 test_line_count = 1 out &&
577
578 git rev-parse >expect \
579 C:a A:a B:b C:C &&
580 git rev-parse >actual \
581 :3:a :1:a :2:b :3:c &&
582 test_cmp expect actual &&
583
584 test_path_is_file a &&
585 test_path_is_file b &&
586 test_path_is_file c
587 )
588'
589
590test_expect_success 'setup rename/rename(1to2)/add-source resolvable conflict' '
591 test_create_repo rename-rename-1to2-add-source-2 &&
592 (
593 cd rename-rename-1to2-add-source-2 &&
594
595 >a &&
596 git add a &&
597 test_tick &&
598 git commit -m base &&
599 git tag A &&
600
601 git checkout -b B A &&
602 git mv a b &&
603 test_tick &&
604 git commit -m one &&
605
606 git checkout -b C A &&
607 git mv a b &&
608 echo important-info >a &&
609 git add a &&
610 test_tick &&
611 git commit -m two
612 )
613'
614
615test_expect_failure 'rename/rename/add-source still tracks new a file' '
616 (
617 cd rename-rename-1to2-add-source-2 &&
618
619 git checkout C^0 &&
620 git merge -s recursive B^0 &&
621
622 git ls-files -s >out &&
623 test_line_count = 2 out &&
624 git ls-files -o >out &&
625 test_line_count = 1 out &&
626
627 git rev-parse >expect \
628 C:a A:a &&
629 git rev-parse >actual \
630 :0:a :0:b &&
631 test_cmp expect actual
632 )
633'
634
635test_expect_success 'setup rename/rename(1to2)/add-dest conflict' '
636 test_create_repo rename-rename-1to2-add-dest &&
637 (
638 cd rename-rename-1to2-add-dest &&
639
640 echo stuff >a &&
641 git add a &&
642 test_tick &&
643 git commit -m base &&
644 git tag A &&
645
646 git checkout -b B A &&
647 git mv a b &&
648 echo precious-data >c &&
649 git add c &&
650 test_tick &&
651 git commit -m one &&
652
653 git checkout -b C A &&
654 git mv a c &&
655 echo important-info >b &&
656 git add b &&
657 test_tick &&
658 git commit -m two
659 )
660'
661
662test_expect_success 'rename/rename/add-dest merge still knows about conflicting file versions' '
663 (
664 cd rename-rename-1to2-add-dest &&
665
666 git checkout C^0 &&
667 test_must_fail git merge -s recursive B^0 &&
668
669 git ls-files -s >out &&
670 test_line_count = 5 out &&
671 git ls-files -u b >out &&
672 test_line_count = 2 out &&
673 git ls-files -u c >out &&
674 test_line_count = 2 out &&
675 git ls-files -o >out &&
676 test_line_count = 5 out &&
677
678 git rev-parse >expect \
679 A:a C:b B:b C:c B:c &&
680 git rev-parse >actual \
681 :1:a :2:b :3:b :2:c :3:c &&
682 test_cmp expect actual &&
683
684 git rev-parse >expect \
685 C:c B:c C:b B:b &&
686 git hash-object >actual \
687 c~HEAD c~B\^0 b~HEAD b~B\^0 &&
688 test_cmp expect actual &&
689
690 test_path_is_missing b &&
691 test_path_is_missing c
692 )
693'
694
695# Testcase rad, rename/add/delete
696# Commit O: foo
697# Commit A: rm foo, add different bar
698# Commit B: rename foo->bar
699# Expected: CONFLICT (rename/add/delete), two-way merged bar
700
701test_expect_success 'rad-setup: rename/add/delete conflict' '
702 test_create_repo rad &&
703 (
704 cd rad &&
705 echo "original file" >foo &&
706 git add foo &&
707 git commit -m "original" &&
708
709 git branch O &&
710 git branch A &&
711 git branch B &&
712
713 git checkout A &&
714 git rm foo &&
715 echo "different file" >bar &&
716 git add bar &&
717 git commit -m "Remove foo, add bar" &&
718
719 git checkout B &&
720 git mv foo bar &&
721 git commit -m "rename foo to bar"
722 )
723'
724
725test_expect_failure 'rad-check: rename/add/delete conflict' '
726 (
727 cd rad &&
728
729 git checkout B^0 &&
730 test_must_fail git merge -s recursive A^0 >out 2>err &&
731
732 # Not sure whether the output should contain just one
733 # "CONFLICT (rename/add/delete)" line, or if it should break
734 # it into a pair of "CONFLICT (rename/delete)" and
735 # "CONFLICT (rename/add)"; allow for either.
736 test_i18ngrep "CONFLICT (rename.*add)" out &&
737 test_i18ngrep "CONFLICT (rename.*delete)" out &&
738 test_must_be_empty err &&
739
740 git ls-files -s >file_count &&
741 test_line_count = 2 file_count &&
742 git ls-files -u >file_count &&
743 test_line_count = 2 file_count &&
744 git ls-files -o >file_count &&
745 test_line_count = 2 file_count &&
746
747 git rev-parse >actual \
748 :2:bar :3:bar &&
749 git rev-parse >expect \
750 B:bar A:bar &&
751
752 test_cmp file_is_missing foo &&
753 # bar should have two-way merged contents of the different
754 # versions of bar; check that content from both sides is
755 # present.
756 grep original bar &&
757 grep different bar
758 )
759'
760
761# Testcase rrdd, rename/rename(2to1)/delete/delete
762# Commit O: foo, bar
763# Commit A: rename foo->baz, rm bar
764# Commit B: rename bar->baz, rm foo
765# Expected: CONFLICT (rename/rename/delete/delete), two-way merged baz
766
767test_expect_success 'rrdd-setup: rename/rename(2to1)/delete/delete conflict' '
768 test_create_repo rrdd &&
769 (
770 cd rrdd &&
771 echo foo >foo &&
772 echo bar >bar &&
773 git add foo bar &&
774 git commit -m O &&
775
776 git branch O &&
777 git branch A &&
778 git branch B &&
779
780 git checkout A &&
781 git mv foo baz &&
782 git rm bar &&
783 git commit -m "Rename foo, remove bar" &&
784
785 git checkout B &&
786 git mv bar baz &&
787 git rm foo &&
788 git commit -m "Rename bar, remove foo"
789 )
790'
791
792test_expect_failure 'rrdd-check: rename/rename(2to1)/delete/delete conflict' '
793 (
794 cd rrdd &&
795
796 git checkout A^0 &&
797 test_must_fail git merge -s recursive B^0 >out 2>err &&
798
799 # Not sure whether the output should contain just one
800 # "CONFLICT (rename/rename/delete/delete)" line, or if it
801 # should break it into three: "CONFLICT (rename/rename)" and
802 # two "CONFLICT (rename/delete)" lines; allow for either.
803 test_i18ngrep "CONFLICT (rename/rename)" out &&
804 test_i18ngrep "CONFLICT (rename.*delete)" out &&
805 test_must_be_empty err &&
806
807 git ls-files -s >file_count &&
808 test_line_count = 2 file_count &&
809 git ls-files -u >file_count &&
810 test_line_count = 2 file_count &&
811 git ls-files -o >file_count &&
812 test_line_count = 2 file_count &&
813
814 git rev-parse >actual \
815 :2:baz :3:baz &&
816 git rev-parse >expect \
817 O:foo O:bar &&
818
819 test_cmp file_is_missing foo &&
820 test_cmp file_is_missing bar &&
821 # baz should have two-way merged contents of the original
822 # contents of foo and bar; check that content from both sides
823 # is present.
824 grep foo baz &&
825 grep bar baz
826 )
827'
828
829# Testcase mod6, chains of rename/rename(1to2) and rename/rename(2to1)
830# Commit O: one, three, five
831# Commit A: one->two, three->four, five->six
832# Commit B: one->six, three->two, five->four
833# Expected: six CONFLICT(rename/rename) messages, each path in two of the
834# multi-way merged contents found in two, four, six
835
836test_expect_success 'mod6-setup: chains of rename/rename(1to2) and rename/rename(2to1)' '
837 test_create_repo mod6 &&
838 (
839 cd mod6 &&
840 test_seq 11 19 >one &&
841 test_seq 31 39 >three &&
842 test_seq 51 59 >five &&
843 git add . &&
844 test_tick &&
845 git commit -m "O" &&
846
847 git branch O &&
848 git branch A &&
849 git branch B &&
850
851 git checkout A &&
852 test_seq 10 19 >one &&
853 echo 40 >>three &&
854 git add one three &&
855 git mv one two &&
856 git mv three four &&
857 git mv five six &&
858 test_tick &&
859 git commit -m "A" &&
860
861 git checkout B &&
862 echo 20 >>one &&
863 echo forty >>three &&
864 echo 60 >>five &&
865 git add one three five &&
866 git mv one six &&
867 git mv three two &&
868 git mv five four &&
869 test_tick &&
870 git commit -m "B"
871 )
872'
873
874test_expect_failure 'mod6-check: chains of rename/rename(1to2) and rename/rename(2to1)' '
875 (
876 cd mod6 &&
877
878 git checkout A^0 &&
879
880 test_must_fail git merge -s recursive B^0 >out 2>err &&
881
882 test_i18ngrep "CONFLICT (rename/rename)" out &&
883 test_must_be_empty err &&
884
885 git ls-files -s >file_count &&
886 test_line_count = 6 file_count &&
887 git ls-files -u >file_count &&
888 test_line_count = 6 file_count &&
889 git ls-files -o >file_count &&
890 test_line_count = 3 file_count &&
891
892 test_seq 10 20 >merged-one &&
893 test_seq 51 60 >merged-five &&
894 # Determine what the merge of three would give us.
895 test_seq 30 40 >three-side-A &&
896 test_seq 31 39 >three-side-B &&
897 echo forty >three-side-B &&
898 >empty &&
899 test_must_fail git merge-file \
900 -L "HEAD" \
901 -L "" \
902 -L "B^0" \
903 three-side-A empty three-side-B &&
904 sed -e "s/^\([<=>]\)/\1\1\1/" three-side-A >merged-three &&
905
906 # Verify the index is as expected
907 git rev-parse >actual \
908 :2:two :3:two \
909 :2:four :3:four \
910 :2:six :3:six &&
911 git hash-object >expect \
912 merged-one merged-three \
913 merged-three merged-five \
914 merged-five merged-one &&
915 test_cmp expect actual &&
916
917 git cat-file -p :2:two >expect &&
918 git cat-file -p :3:two >other &&
919 test_must_fail git merge-file \
920 -L "HEAD" -L "" -L "B^0" \
921 expect empty other &&
922 test_cmp expect two &&
923
924 git cat-file -p :2:four >expect &&
925 git cat-file -p :3:four >other &&
926 test_must_fail git merge-file \
927 -L "HEAD" -L "" -L "B^0" \
928 expect empty other &&
929 test_cmp expect four &&
930
931 git cat-file -p :2:six >expect &&
932 git cat-file -p :3:six >other &&
933 test_must_fail git merge-file \
934 -L "HEAD" -L "" -L "B^0" \
935 expect empty other &&
936 test_cmp expect six
937 )
938'
939
940test_conflicts_with_adds_and_renames() {
941 sideL=$1
942 sideR=$2
943 expect=$3
944
945 # Setup:
946 # L
947 # / \
948 # master ?
949 # \ /
950 # R
951 #
952 # Where:
953 # Both L and R have files named 'three' which collide. Each of
954 # the colliding files could have been involved in a rename, in
955 # which case there was a file named 'one' or 'two' that was
956 # modified on the opposite side of history and renamed into the
957 # collision on this side of history.
958 #
959 # Questions:
960 # 1) The index should contain both a stage 2 and stage 3 entry
961 # for the colliding file. Does it?
962 # 2) When renames are involved, the content merges are clean, so
963 # the index should reflect the content merges, not merely the
964 # version of the colliding file from the prior commit. Does
965 # it?
966 # 3) There should be a file in the worktree named 'three'
967 # containing the two-way merged contents of the content-merged
968 # versions of 'three' from each of the two colliding
969 # files. Is it present?
970 # 4) There should not be any three~* files in the working
971 # tree
972 test_expect_success "setup simple $sideL/$sideR conflict" '
973 test_create_repo simple_${sideL}_${sideR} &&
974 (
975 cd simple_${sideL}_${sideR} &&
976
977 # Create some related files now
978 for i in $(test_seq 1 10)
979 do
980 echo Random base content line $i
981 done >file_v1 &&
982 cp file_v1 file_v2 &&
983 echo modification >>file_v2 &&
984
985 cp file_v1 file_v3 &&
986 echo more stuff >>file_v3 &&
987 cp file_v3 file_v4 &&
988 echo yet more stuff >>file_v4 &&
989
990 # Use a tag to record both these files for simple
991 # access, and clean out these untracked files
992 git tag file_v1 $(git hash-object -w file_v1) &&
993 git tag file_v2 $(git hash-object -w file_v2) &&
994 git tag file_v3 $(git hash-object -w file_v3) &&
995 git tag file_v4 $(git hash-object -w file_v4) &&
996 git clean -f &&
997
998 # Setup original commit (or merge-base), consisting of
999 # files named "one" and "two" if renames were involved.
1000 touch irrelevant_file &&
1001 git add irrelevant_file &&
1002 if [ $sideL = "rename" ]
1003 then
1004 git show file_v1 >one &&
1005 git add one
1006 fi &&
1007 if [ $sideR = "rename" ]
1008 then
1009 git show file_v3 >two &&
1010 git add two
1011 fi &&
1012 test_tick && git commit -m initial &&
1013
1014 git branch L &&
1015 git branch R &&
1016
1017 # Handle the left side
1018 git checkout L &&
1019 if [ $sideL = "rename" ]
1020 then
1021 git mv one three
1022 else
1023 git show file_v2 >three &&
1024 git add three
1025 fi &&
1026 if [ $sideR = "rename" ]
1027 then
1028 git show file_v4 >two &&
1029 git add two
1030 fi &&
1031 test_tick && git commit -m L &&
1032
1033 # Handle the right side
1034 git checkout R &&
1035 if [ $sideL = "rename" ]
1036 then
1037 git show file_v2 >one &&
1038 git add one
1039 fi &&
1040 if [ $sideR = "rename" ]
1041 then
1042 git mv two three
1043 else
1044 git show file_v4 >three &&
1045 git add three
1046 fi &&
1047 test_tick && git commit -m R
1048 )
1049 '
1050
1051 test_expect_$expect "check simple $sideL/$sideR conflict" '
1052 (
1053 cd simple_${sideL}_${sideR} &&
1054
1055 git checkout L^0 &&
1056
1057 # Merge must fail; there is a conflict
1058 test_must_fail git merge -s recursive R^0 &&
1059
1060 # Make sure the index has the right number of entries
1061 git ls-files -s >out &&
1062 test_line_count = 3 out &&
1063 git ls-files -u >out &&
1064 test_line_count = 2 out &&
1065 # Ensure we have the correct number of untracked files
1066 git ls-files -o >out &&
1067 test_line_count = 1 out &&
1068
1069 # Nothing should have touched irrelevant_file
1070 git rev-parse >actual \
1071 :0:irrelevant_file \
1072 :2:three \
1073 :3:three &&
1074 git rev-parse >expected \
1075 master:irrelevant_file \
1076 file_v2 \
1077 file_v4 &&
1078 test_cmp expected actual &&
1079
1080 # Make sure we have the correct merged contents for
1081 # three
1082 git show file_v1 >expected &&
1083 cat <<-\EOF >>expected &&
1084 <<<<<<< HEAD
1085 modification
1086 =======
1087 more stuff
1088 yet more stuff
1089 >>>>>>> R^0
1090 EOF
1091
1092 test_cmp expected three
1093 )
1094 '
1095}
1096
1097test_conflicts_with_adds_and_renames rename rename failure
1098test_conflicts_with_adds_and_renames rename add failure
1099test_conflicts_with_adds_and_renames add rename failure
1100test_conflicts_with_adds_and_renames add add success
1101
1102# Setup:
1103# L
1104# / \
1105# master ?
1106# \ /
1107# R
1108#
1109# Where:
1110# master has two files, named 'one' and 'two'.
1111# branches L and R both modify 'one', in conflicting ways.
1112# branches L and R both modify 'two', in conflicting ways.
1113# branch L also renames 'one' to 'three'.
1114# branch R also renames 'two' to 'three'.
1115#
1116# So, we have four different conflicting files that all end up at path
1117# 'three'.
1118test_expect_success 'setup nested conflicts from rename/rename(2to1)' '
1119 test_create_repo nested_conflicts_from_rename_rename &&
1120 (
1121 cd nested_conflicts_from_rename_rename &&
1122
1123 # Create some related files now
1124 for i in $(test_seq 1 10)
1125 do
1126 echo Random base content line $i
1127 done >file_v1 &&
1128
1129 cp file_v1 file_v2 &&
1130 cp file_v1 file_v3 &&
1131 cp file_v1 file_v4 &&
1132 cp file_v1 file_v5 &&
1133 cp file_v1 file_v6 &&
1134
1135 echo one >>file_v1 &&
1136 echo uno >>file_v2 &&
1137 echo eins >>file_v3 &&
1138
1139 echo two >>file_v4 &&
1140 echo dos >>file_v5 &&
1141 echo zwei >>file_v6 &&
1142
1143 # Setup original commit (or merge-base), consisting of
1144 # files named "one" and "two".
1145 mv file_v1 one &&
1146 mv file_v4 two &&
1147 git add one two &&
1148 test_tick && git commit -m english &&
1149
1150 git branch L &&
1151 git branch R &&
1152
1153 # Handle the left side
1154 git checkout L &&
1155 git mv one three &&
1156 mv -f file_v2 three &&
1157 mv -f file_v5 two &&
1158 git add two three &&
1159 test_tick && git commit -m spanish &&
1160
1161 # Handle the right side
1162 git checkout R &&
1163 git mv two three &&
1164 mv -f file_v3 one &&
1165 mv -f file_v6 three &&
1166 git add one three &&
1167 test_tick && git commit -m german
1168 )
1169'
1170
1171test_expect_failure 'check nested conflicts from rename/rename(2to1)' '
1172 (
1173 cd nested_conflicts_from_rename_rename &&
1174
1175 git checkout L^0 &&
1176
1177 # Merge must fail; there is a conflict
1178 test_must_fail git merge -s recursive R^0 &&
1179
1180 # Make sure the index has the right number of entries
1181 git ls-files -s >out &&
1182 test_line_count = 2 out &&
1183 git ls-files -u >out &&
1184 test_line_count = 2 out &&
1185 # Ensure we have the correct number of untracked files
1186 git ls-files -o >out &&
1187 test_line_count = 1 out &&
1188
1189 # Compare :2:three to expected values
1190 git cat-file -p master:one >base &&
1191 git cat-file -p L:three >ours &&
1192 git cat-file -p R:one >theirs &&
1193 test_must_fail git merge-file \
1194 -L "HEAD:three" -L "" -L "R^0:one" \
1195 ours base theirs &&
1196 sed -e "s/^\([<=>]\)/\1\1/" ours >L-three &&
1197 git cat-file -p :2:three >expect &&
1198 test_cmp expect L-three &&
1199
1200 # Compare :2:three to expected values
1201 git cat-file -p master:two >base &&
1202 git cat-file -p L:two >ours &&
1203 git cat-file -p R:three >theirs &&
1204 test_must_fail git merge-file \
1205 -L "HEAD:two" -L "" -L "R^0:three" \
1206 ours base theirs &&
1207 sed -e "s/^\([<=>]\)/\1\1/" ours >R-three &&
1208 git cat-file -p :3:three >expect &&
1209 test_cmp expect R-three &&
1210
1211 # Compare three to expected contents
1212 >empty &&
1213 test_must_fail git merge-file \
1214 -L "HEAD" -L "" -L "R^0" \
1215 L-three empty R-three &&
1216 test_cmp three L-three
1217 )
1218'
1219
1220test_done