3 test_description="merge cases"
5 # The setup for all of them, pictorially, is:
15 # To help make it easier to follow the flow of tests, they have been
16 # divided into sections and each test will start with a quick explanation
17 # of what commits O, A, and B contain.
20 # z/{b,c} means files z/b and z/c both exist
21 # x/d_1 means file x/d exists with content d1. (Purpose of the
22 # underscore notation is to differentiate different
23 # files that might be renamed into each other's paths.)
26 . "$TEST_DIRECTORY"/lib-merge.sh
29 ###########################################################################
30 # SECTION 1: Cases involving no renames (one side has subset of changes of
32 ###########################################################################
34 # Testcase 1a, Changes on A, subset of changes on B
41 test_create_repo 1a_$1 &&
45 test_write_lines 1 2 3 4 5 6 7 8 9 10 >b &&
55 test_write_lines 1 2 3 4 5 5.5 6 7 8 9 10 10.5 >b &&
61 test_write_lines 1 2 3 4 5 5.5 6 7 8 9 10 >b &&
68 test_expect_success '1a-L: Modify(A)/Modify(B), change on B subset of A' '
75 test-tool chmtime --get -3600 b >old-mtime &&
77 GIT_MERGE_VERBOSITY=3 git merge -s recursive B^0 >out 2>err &&
79 test_must_be_empty err &&
81 # Make sure b was NOT updated
82 test-tool chmtime --get b >new-mtime &&
83 test_cmp old-mtime new-mtime &&
85 git ls-files -s >index_files &&
86 test_line_count = 1 index_files &&
88 git rev-parse >actual HEAD:b &&
89 git rev-parse >expect A:b &&
90 test_cmp expect actual &&
92 git hash-object b >actual &&
93 git rev-parse A:b >expect &&
94 test_cmp expect actual
98 test_expect_success '1a-R: Modify(A)/Modify(B), change on B subset of A' '
105 test-tool chmtime --get -3600 b >old-mtime &&
106 GIT_MERGE_VERBOSITY=3 git merge -s recursive A^0 >out 2>err &&
108 # Make sure b WAS updated
109 test-tool chmtime --get b >new-mtime &&
110 test $(cat old-mtime) -lt $(cat new-mtime) &&
112 test_must_be_empty err &&
114 git ls-files -s >index_files &&
115 test_line_count = 1 index_files &&
117 git rev-parse >actual HEAD:b &&
118 git rev-parse >expect A:b &&
119 test_cmp expect actual &&
121 git hash-object b >actual &&
122 git rev-parse A:b >expect &&
123 test_cmp expect actual
128 ###########################################################################
129 # SECTION 2: Cases involving basic renames
130 ###########################################################################
132 # Testcase 2a, Changes on A, rename on B
139 test_create_repo 2a_$1 &&
165 test_expect_success '2a-L: Modify/rename, merge into modify side' '
172 test_path_is_missing c &&
173 GIT_MERGE_VERBOSITY=3 git merge -s recursive B^0 >out 2>err &&
175 test_path_is_file c &&
177 git ls-files -s >index_files &&
178 test_line_count = 1 index_files &&
180 git rev-parse >actual HEAD:c &&
181 git rev-parse >expect A:b &&
182 test_cmp expect actual &&
184 git hash-object c >actual &&
185 git rev-parse A:b >expect &&
186 test_cmp expect actual &&
188 test_must_fail git rev-parse HEAD:b &&
189 test_path_is_missing b
193 test_expect_success '2a-R: Modify/rename, merge into rename side' '
200 test-tool chmtime --get -3600 c >old-mtime &&
201 GIT_MERGE_VERBOSITY=3 git merge -s recursive A^0 >out 2>err &&
203 # Make sure c WAS updated
204 test-tool chmtime --get c >new-mtime &&
205 test $(cat old-mtime) -lt $(cat new-mtime) &&
207 test_must_be_empty err &&
209 git ls-files -s >index_files &&
210 test_line_count = 1 index_files &&
212 git rev-parse >actual HEAD:c &&
213 git rev-parse >expect A:b &&
214 test_cmp expect actual &&
216 git hash-object c >actual &&
217 git rev-parse A:b >expect &&
218 test_cmp expect actual &&
220 test_must_fail git rev-parse HEAD:b &&
221 test_path_is_missing b
225 # Testcase 2b, Changed and renamed on A, subset of changes on B
232 test_create_repo 2b_$1 &&
236 test_write_lines 1 2 3 4 5 6 7 8 9 10 >b &&
246 test_write_lines 1 2 3 4 5 5.5 6 7 8 9 10 10.5 >b &&
253 test_write_lines 1 2 3 4 5 5.5 6 7 8 9 10 >b &&
260 test_expect_success '2b-L: Rename+Mod(A)/Mod(B), B mods subset of A' '
267 test-tool chmtime --get -3600 c >old-mtime &&
268 GIT_MERGE_VERBOSITY=3 git merge -s recursive B^0 >out 2>err &&
270 test_must_be_empty err &&
272 # Make sure c WAS updated
273 test-tool chmtime --get c >new-mtime &&
274 test_cmp old-mtime new-mtime &&
276 git ls-files -s >index_files &&
277 test_line_count = 1 index_files &&
279 git rev-parse >actual HEAD:c &&
280 git rev-parse >expect A:c &&
281 test_cmp expect actual &&
283 git hash-object c >actual &&
284 git rev-parse A:c >expect &&
285 test_cmp expect actual &&
287 test_must_fail git rev-parse HEAD:b &&
288 test_path_is_missing b
292 test_expect_success '2b-R: Rename+Mod(A)/Mod(B), B mods subset of A' '
299 test_path_is_missing c &&
300 GIT_MERGE_VERBOSITY=3 git merge -s recursive A^0 >out 2>err &&
302 # Make sure c now present (and thus was updated)
303 test_path_is_file c &&
305 test_must_be_empty err &&
307 git ls-files -s >index_files &&
308 test_line_count = 1 index_files &&
310 git rev-parse >actual HEAD:c &&
311 git rev-parse >expect A:c &&
312 test_cmp expect actual &&
314 git hash-object c >actual &&
315 git rev-parse A:c >expect &&
316 test_cmp expect actual &&
318 test_must_fail git rev-parse HEAD:b &&
319 test_path_is_missing b
323 # Testcase 2c, Changes on A, rename on B
327 # Expected: rename/add conflict c_2 vs c_3
329 # NOTE: Since A modified b_1->b_2, and B renamed b_1->c_1, the threeway
330 # merge of those files should result in c_2. We then should have a
331 # rename/add conflict between c_2 and c_3. However, if we note in
332 # merge_content() that A had the right contents (b_2 has same
333 # contents as c_2, just at a different name), and that A had the
334 # right path present (c_3 existed) and thus decides that it can
335 # skip the update, then we're in trouble. This test verifies we do
336 # not make that particular mistake.
339 test_create_repo 2c &&
366 test_expect_success '2c: Modify b & add c VS rename b->c' '
373 test-tool chmtime --get -3600 c >old-mtime &&
374 GIT_MERGE_VERBOSITY=3 &&
375 export GIT_MERGE_VERBOSITY &&
376 test_must_fail git merge -s recursive B^0 >out 2>err &&
378 test_i18ngrep "CONFLICT (.*/add):" out &&
379 test_must_be_empty err &&
381 # Make sure c WAS updated
382 test-tool chmtime --get c >new-mtime &&
383 test $(cat old-mtime) -lt $(cat new-mtime)
385 # FIXME: rename/add conflicts are horribly broken right now;
386 # when I get back to my patch series fixing it and
387 # rename/rename(2to1) conflicts to bring them in line with
388 # how add/add conflicts behave, then checks like the below
389 # could be added. But that patch series is waiting until
390 # the rename-directory-detection series lands, which this
391 # is part of. And in the mean time, I do not want to further
392 # enforce broken behavior. So for now, the main test is the
393 # one above that err is an empty file.
395 #git ls-files -s >index_files &&
396 #test_line_count = 2 index_files &&
398 #git rev-parse >actual :2:c :3:c &&
399 #git rev-parse >expect A:b A:c &&
400 #test_cmp expect actual &&
402 #git cat-file -p A:b >>merged &&
403 #git cat-file -p A:c >>merge-me &&
405 #test_must_fail git merge-file \
406 # -L "Temporary merge branch 1" \
408 # -L "Temporary merge branch 2" \
409 # merged empty merge-me &&
410 #sed -e "s/^\([<=>]\)/\1\1\1/" merged >merged-internal &&
412 #git hash-object c >actual &&
413 #git hash-object merged-internal >expect &&
414 #test_cmp expect actual &&
416 #test_path_is_missing b
421 ###########################################################################
422 # SECTION 3: Cases involving directory renames
425 # Directory renames only apply when one side renames a directory, and the
426 # other side adds or renames a path into that directory. Applying the
427 # directory rename to that new path creates a new pathname that didn't
428 # exist on either side of history. Thus, it is impossible for the
429 # merge contents to already be at the right path, so all of these checks
430 # exist just to make sure that updates are not skipped.
431 ###########################################################################
433 # Testcase 3a, Change + rename into dir foo on A, dir rename foo->bar on B
434 # Commit O: bq_1, foo/whatever
435 # Commit A: foo/{bq_2, whatever}
436 # Commit B: bq_1, bar/whatever
437 # Expected: bar/{bq_2, whatever}
440 test_create_repo 3a_$1 &&
446 test_write_lines a b c d e f g h i j k >foo/whatever &&
447 git add bq foo/whatever &&
469 test_expect_success '3a-L: bq_1->foo/bq_2 on A, foo/->bar/ on B' '
476 test_path_is_missing bar/bq &&
477 GIT_MERGE_VERBOSITY=3 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
479 test_must_be_empty err &&
481 test_path_is_file bar/bq &&
483 git ls-files -s >index_files &&
484 test_line_count = 2 index_files &&
486 git rev-parse >actual HEAD:bar/bq HEAD:bar/whatever &&
487 git rev-parse >expect A:foo/bq A:foo/whatever &&
488 test_cmp expect actual &&
490 git hash-object bar/bq bar/whatever >actual &&
491 git rev-parse A:foo/bq A:foo/whatever >expect &&
492 test_cmp expect actual &&
494 test_must_fail git rev-parse HEAD:bq HEAD:foo/bq &&
495 test_path_is_missing bq foo/bq foo/whatever
499 test_expect_success '3a-R: bq_1->foo/bq_2 on A, foo/->bar/ on B' '
506 test_path_is_missing bar/bq &&
507 GIT_MERGE_VERBOSITY=3 git -c merge.directoryRenames=true merge -s recursive A^0 >out 2>err &&
509 test_must_be_empty err &&
511 test_path_is_file bar/bq &&
513 git ls-files -s >index_files &&
514 test_line_count = 2 index_files &&
516 git rev-parse >actual HEAD:bar/bq HEAD:bar/whatever &&
517 git rev-parse >expect A:foo/bq A:foo/whatever &&
518 test_cmp expect actual &&
520 git hash-object bar/bq bar/whatever >actual &&
521 git rev-parse A:foo/bq A:foo/whatever >expect &&
522 test_cmp expect actual &&
524 test_must_fail git rev-parse HEAD:bq HEAD:foo/bq &&
525 test_path_is_missing bq foo/bq foo/whatever
529 # Testcase 3b, rename into dir foo on A, dir rename foo->bar + change on B
530 # Commit O: bq_1, foo/whatever
531 # Commit A: foo/{bq_1, whatever}
532 # Commit B: bq_2, bar/whatever
533 # Expected: bar/{bq_2, whatever}
536 test_create_repo 3b_$1 &&
542 test_write_lines a b c d e f g h i j k >foo/whatever &&
543 git add bq foo/whatever &&
565 test_expect_success '3b-L: bq_1->foo/bq_2 on A, foo/->bar/ on B' '
572 test_path_is_missing bar/bq &&
573 GIT_MERGE_VERBOSITY=3 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
575 test_must_be_empty err &&
577 test_path_is_file bar/bq &&
579 git ls-files -s >index_files &&
580 test_line_count = 2 index_files &&
582 git rev-parse >actual HEAD:bar/bq HEAD:bar/whatever &&
583 git rev-parse >expect B:bq A:foo/whatever &&
584 test_cmp expect actual &&
586 git hash-object bar/bq bar/whatever >actual &&
587 git rev-parse B:bq A:foo/whatever >expect &&
588 test_cmp expect actual &&
590 test_must_fail git rev-parse HEAD:bq HEAD:foo/bq &&
591 test_path_is_missing bq foo/bq foo/whatever
595 test_expect_success '3b-R: bq_1->foo/bq_2 on A, foo/->bar/ on B' '
602 test_path_is_missing bar/bq &&
603 GIT_MERGE_VERBOSITY=3 git -c merge.directoryRenames=true merge -s recursive A^0 >out 2>err &&
605 test_must_be_empty err &&
607 test_path_is_file bar/bq &&
609 git ls-files -s >index_files &&
610 test_line_count = 2 index_files &&
612 git rev-parse >actual HEAD:bar/bq HEAD:bar/whatever &&
613 git rev-parse >expect B:bq A:foo/whatever &&
614 test_cmp expect actual &&
616 git hash-object bar/bq bar/whatever >actual &&
617 git rev-parse B:bq A:foo/whatever >expect &&
618 test_cmp expect actual &&
620 test_must_fail git rev-parse HEAD:bq HEAD:foo/bq &&
621 test_path_is_missing bq foo/bq foo/whatever
625 ###########################################################################
626 # SECTION 4: Cases involving dirty changes
627 ###########################################################################
629 # Testcase 4a, Changed on A, subset of changes on B, locally modified
634 # Expected: b_2 for merge, b_4 in working copy
637 test_create_repo 4a &&
641 test_write_lines 1 2 3 4 5 6 7 8 9 10 >b &&
651 test_write_lines 1 2 3 4 5 5.5 6 7 8 9 10 10.5 >b &&
657 test_write_lines 1 2 3 4 5 5.5 6 7 8 9 10 >b &&
664 # NOTE: For as long as we continue using unpack_trees() without index_only
665 # set to true, it will error out on a case like this claiming that the locally
666 # modified file would be overwritten by the merge. Getting this testcase
667 # correct requires doing the merge in-memory first, then realizing that no
668 # updates to the file are necessary, and thus that we can just leave the path
670 test_expect_merge_algorithm failure success '4a: Change on A, change on B subset of A, dirty mods present' '
676 echo "File rewritten" >b &&
678 test-tool chmtime --get -3600 b >old-mtime &&
680 GIT_MERGE_VERBOSITY=3 git merge -s recursive B^0 >out 2>err &&
682 test_must_be_empty err &&
684 # Make sure b was NOT updated
685 test-tool chmtime --get b >new-mtime &&
686 test_cmp old-mtime new-mtime &&
688 git ls-files -s >index_files &&
689 test_line_count = 1 index_files &&
691 git rev-parse >actual :0:b &&
692 git rev-parse >expect A:b &&
693 test_cmp expect actual &&
695 git hash-object b >actual &&
696 echo "File rewritten" | git hash-object --stdin >expect &&
697 test_cmp expect actual
701 # Testcase 4b, Changed+renamed on A, subset of changes on B, locally modified
709 test_create_repo 4b &&
713 test_write_lines 1 2 3 4 5 6 7 8 9 10 >b &&
723 test_write_lines 1 2 3 4 5 5.5 6 7 8 9 10 10.5 >b &&
730 test_write_lines 1 2 3 4 5 5.5 6 7 8 9 10 >b &&
737 test_expect_success '4b: Rename+Mod(A)/Mod(B), change on B subset of A, dirty mods present' '
743 echo "File rewritten" >c &&
745 test-tool chmtime --get -3600 c >old-mtime &&
747 GIT_MERGE_VERBOSITY=3 git merge -s recursive B^0 >out 2>err &&
749 test_must_be_empty err &&
751 # Make sure c was NOT updated
752 test-tool chmtime --get c >new-mtime &&
753 test_cmp old-mtime new-mtime &&
755 git ls-files -s >index_files &&
756 test_line_count = 1 index_files &&
758 git rev-parse >actual :0:c &&
759 git rev-parse >expect A:c &&
760 test_cmp expect actual &&
762 git hash-object c >actual &&
763 echo "File rewritten" | git hash-object --stdin >expect &&
764 test_cmp expect actual &&
766 test_must_fail git rev-parse HEAD:b &&
767 test_path_is_missing b