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.)
28 ###########################################################################
29 # SECTION 1: Cases involving no renames (one side has subset of changes of
31 ###########################################################################
33 # Testcase 1a, Changes on A, subset of changes on B
40 test_create_repo 1a_$1 &&
44 test_write_lines 1 2 3 4 5 6 7 8 9 10 >b &&
54 test_write_lines 1 2 3 4 5 5.5 6 7 8 9 10 10.5 >b &&
60 test_write_lines 1 2 3 4 5 5.5 6 7 8 9 10 >b &&
67 test_expect_success '1a-L: Modify(A)/Modify(B), change on B subset of A' '
74 test-tool chmtime --get -3600 b >old-mtime &&
76 GIT_MERGE_VERBOSITY=3 git merge -s recursive B^0 >out 2>err &&
78 test_must_be_empty err &&
80 # Make sure b was NOT updated
81 test-tool chmtime --get b >new-mtime &&
82 test_cmp old-mtime new-mtime &&
84 git ls-files -s >index_files &&
85 test_line_count = 1 index_files &&
87 git rev-parse >actual HEAD:b &&
88 git rev-parse >expect A:b &&
89 test_cmp expect actual &&
91 git hash-object b >actual &&
92 git rev-parse A:b >expect &&
93 test_cmp expect actual
97 test_expect_success '1a-R: Modify(A)/Modify(B), change on B subset of A' '
104 test-tool chmtime --get -3600 b >old-mtime &&
105 GIT_MERGE_VERBOSITY=3 git merge -s recursive A^0 >out 2>err &&
107 # Make sure b WAS updated
108 test-tool chmtime --get b >new-mtime &&
109 test $(cat old-mtime) -lt $(cat new-mtime) &&
111 test_must_be_empty err &&
113 git ls-files -s >index_files &&
114 test_line_count = 1 index_files &&
116 git rev-parse >actual HEAD:b &&
117 git rev-parse >expect A:b &&
118 test_cmp expect actual &&
120 git hash-object b >actual &&
121 git rev-parse A:b >expect &&
122 test_cmp expect actual
127 ###########################################################################
128 # SECTION 2: Cases involving basic renames
129 ###########################################################################
131 # Testcase 2a, Changes on A, rename on B
138 test_create_repo 2a_$1 &&
164 test_expect_success '2a-L: Modify/rename, merge into modify side' '
171 test_path_is_missing c &&
172 GIT_MERGE_VERBOSITY=3 git merge -s recursive B^0 >out 2>err &&
174 test_path_is_file c &&
176 git ls-files -s >index_files &&
177 test_line_count = 1 index_files &&
179 git rev-parse >actual HEAD:c &&
180 git rev-parse >expect A:b &&
181 test_cmp expect actual &&
183 git hash-object c >actual &&
184 git rev-parse A:b >expect &&
185 test_cmp expect actual &&
187 test_must_fail git rev-parse HEAD:b &&
188 test_path_is_missing b
192 test_expect_success '2a-R: Modify/rename, merge into rename side' '
199 test-tool chmtime --get -3600 c >old-mtime &&
200 GIT_MERGE_VERBOSITY=3 git merge -s recursive A^0 >out 2>err &&
202 # Make sure c WAS updated
203 test-tool chmtime --get c >new-mtime &&
204 test $(cat old-mtime) -lt $(cat new-mtime) &&
206 test_must_be_empty err &&
208 git ls-files -s >index_files &&
209 test_line_count = 1 index_files &&
211 git rev-parse >actual HEAD:c &&
212 git rev-parse >expect A:b &&
213 test_cmp expect actual &&
215 git hash-object c >actual &&
216 git rev-parse A:b >expect &&
217 test_cmp expect actual &&
219 test_must_fail git rev-parse HEAD:b &&
220 test_path_is_missing b
224 # Testcase 2b, Changed and renamed on A, subset of changes on B
231 test_create_repo 2b_$1 &&
235 test_write_lines 1 2 3 4 5 6 7 8 9 10 >b &&
245 test_write_lines 1 2 3 4 5 5.5 6 7 8 9 10 10.5 >b &&
252 test_write_lines 1 2 3 4 5 5.5 6 7 8 9 10 >b &&
259 test_expect_success '2b-L: Rename+Mod(A)/Mod(B), B mods subset of A' '
266 test-tool chmtime --get -3600 c >old-mtime &&
267 GIT_MERGE_VERBOSITY=3 git merge -s recursive B^0 >out 2>err &&
269 test_must_be_empty err &&
271 # Make sure c WAS updated
272 test-tool chmtime --get c >new-mtime &&
273 test_cmp old-mtime new-mtime &&
275 git ls-files -s >index_files &&
276 test_line_count = 1 index_files &&
278 git rev-parse >actual HEAD:c &&
279 git rev-parse >expect A:c &&
280 test_cmp expect actual &&
282 git hash-object c >actual &&
283 git rev-parse A:c >expect &&
284 test_cmp expect actual &&
286 test_must_fail git rev-parse HEAD:b &&
287 test_path_is_missing b
291 test_expect_success '2b-R: Rename+Mod(A)/Mod(B), B mods subset of A' '
298 test_path_is_missing c &&
299 GIT_MERGE_VERBOSITY=3 git merge -s recursive A^0 >out 2>err &&
301 # Make sure c now present (and thus was updated)
302 test_path_is_file c &&
304 test_must_be_empty err &&
306 git ls-files -s >index_files &&
307 test_line_count = 1 index_files &&
309 git rev-parse >actual HEAD:c &&
310 git rev-parse >expect A:c &&
311 test_cmp expect actual &&
313 git hash-object c >actual &&
314 git rev-parse A:c >expect &&
315 test_cmp expect actual &&
317 test_must_fail git rev-parse HEAD:b &&
318 test_path_is_missing b
322 # Testcase 2c, Changes on A, rename on B
326 # Expected: rename/add conflict c_2 vs c_3
328 # NOTE: Since A modified b_1->b_2, and B renamed b_1->c_1, the threeway
329 # merge of those files should result in c_2. We then should have a
330 # rename/add conflict between c_2 and c_3. However, if we note in
331 # merge_content() that A had the right contents (b_2 has same
332 # contents as c_2, just at a different name), and that A had the
333 # right path present (c_3 existed) and thus decides that it can
334 # skip the update, then we're in trouble. This test verifies we do
335 # not make that particular mistake.
338 test_create_repo 2c &&
365 test_expect_success '2c: Modify b & add c VS rename b->c' '
372 test-tool chmtime --get -3600 c >old-mtime &&
373 GIT_MERGE_VERBOSITY=3 &&
374 export GIT_MERGE_VERBOSITY &&
375 test_must_fail git merge -s recursive B^0 >out 2>err &&
377 test_i18ngrep "CONFLICT (rename/add): Rename b->c" out &&
378 test_must_be_empty err &&
380 # Make sure c WAS updated
381 test-tool chmtime --get c >new-mtime &&
382 test $(cat old-mtime) -lt $(cat new-mtime)
384 # FIXME: rename/add conflicts are horribly broken right now;
385 # when I get back to my patch series fixing it and
386 # rename/rename(2to1) conflicts to bring them in line with
387 # how add/add conflicts behave, then checks like the below
388 # could be added. But that patch series is waiting until
389 # the rename-directory-detection series lands, which this
390 # is part of. And in the mean time, I do not want to further
391 # enforce broken behavior. So for now, the main test is the
392 # one above that err is an empty file.
394 #git ls-files -s >index_files &&
395 #test_line_count = 2 index_files &&
397 #git rev-parse >actual :2:c :3:c &&
398 #git rev-parse >expect A:b A:c &&
399 #test_cmp expect actual &&
401 #git cat-file -p A:b >>merged &&
402 #git cat-file -p A:c >>merge-me &&
404 #test_must_fail git merge-file \
405 # -L "Temporary merge branch 1" \
407 # -L "Temporary merge branch 2" \
408 # merged empty merge-me &&
409 #sed -e "s/^\([<=>]\)/\1\1\1/" merged >merged-internal &&
411 #git hash-object c >actual &&
412 #git hash-object merged-internal >expect &&
413 #test_cmp expect actual &&
415 #test_path_is_missing b
420 ###########################################################################
421 # SECTION 3: Cases involving directory renames
424 # Directory renames only apply when one side renames a directory, and the
425 # other side adds or renames a path into that directory. Applying the
426 # directory rename to that new path creates a new pathname that didn't
427 # exist on either side of history. Thus, it is impossible for the
428 # merge contents to already be at the right path, so all of these checks
429 # exist just to make sure that updates are not skipped.
430 ###########################################################################
432 # Testcase 3a, Change + rename into dir foo on A, dir rename foo->bar on B
433 # Commit O: bq_1, foo/whatever
434 # Commit A: foo/{bq_2, whatever}
435 # Commit B: bq_1, bar/whatever
436 # Expected: bar/{bq_2, whatever}
439 test_create_repo 3a_$1 &&
445 test_write_lines a b c d e f g h i j k >foo/whatever &&
446 git add bq foo/whatever &&
468 test_expect_success '3a-L: bq_1->foo/bq_2 on A, foo/->bar/ on B' '
475 test_path_is_missing bar/bq &&
476 GIT_MERGE_VERBOSITY=3 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
478 test_must_be_empty err &&
480 test_path_is_file bar/bq &&
482 git ls-files -s >index_files &&
483 test_line_count = 2 index_files &&
485 git rev-parse >actual HEAD:bar/bq HEAD:bar/whatever &&
486 git rev-parse >expect A:foo/bq A:foo/whatever &&
487 test_cmp expect actual &&
489 git hash-object bar/bq bar/whatever >actual &&
490 git rev-parse A:foo/bq A:foo/whatever >expect &&
491 test_cmp expect actual &&
493 test_must_fail git rev-parse HEAD:bq HEAD:foo/bq &&
494 test_path_is_missing bq foo/bq foo/whatever
498 test_expect_success '3a-R: bq_1->foo/bq_2 on A, foo/->bar/ on B' '
505 test_path_is_missing bar/bq &&
506 GIT_MERGE_VERBOSITY=3 git -c merge.directoryRenames=true merge -s recursive A^0 >out 2>err &&
508 test_must_be_empty err &&
510 test_path_is_file bar/bq &&
512 git ls-files -s >index_files &&
513 test_line_count = 2 index_files &&
515 git rev-parse >actual HEAD:bar/bq HEAD:bar/whatever &&
516 git rev-parse >expect A:foo/bq A:foo/whatever &&
517 test_cmp expect actual &&
519 git hash-object bar/bq bar/whatever >actual &&
520 git rev-parse A:foo/bq A:foo/whatever >expect &&
521 test_cmp expect actual &&
523 test_must_fail git rev-parse HEAD:bq HEAD:foo/bq &&
524 test_path_is_missing bq foo/bq foo/whatever
528 # Testcase 3b, rename into dir foo on A, dir rename foo->bar + change on B
529 # Commit O: bq_1, foo/whatever
530 # Commit A: foo/{bq_1, whatever}
531 # Commit B: bq_2, bar/whatever
532 # Expected: bar/{bq_2, whatever}
535 test_create_repo 3b_$1 &&
541 test_write_lines a b c d e f g h i j k >foo/whatever &&
542 git add bq foo/whatever &&
564 test_expect_success '3b-L: bq_1->foo/bq_2 on A, foo/->bar/ on B' '
571 test_path_is_missing bar/bq &&
572 GIT_MERGE_VERBOSITY=3 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
574 test_must_be_empty err &&
576 test_path_is_file bar/bq &&
578 git ls-files -s >index_files &&
579 test_line_count = 2 index_files &&
581 git rev-parse >actual HEAD:bar/bq HEAD:bar/whatever &&
582 git rev-parse >expect B:bq A:foo/whatever &&
583 test_cmp expect actual &&
585 git hash-object bar/bq bar/whatever >actual &&
586 git rev-parse B:bq A:foo/whatever >expect &&
587 test_cmp expect actual &&
589 test_must_fail git rev-parse HEAD:bq HEAD:foo/bq &&
590 test_path_is_missing bq foo/bq foo/whatever
594 test_expect_success '3b-R: bq_1->foo/bq_2 on A, foo/->bar/ on B' '
601 test_path_is_missing bar/bq &&
602 GIT_MERGE_VERBOSITY=3 git -c merge.directoryRenames=true merge -s recursive A^0 >out 2>err &&
604 test_must_be_empty err &&
606 test_path_is_file bar/bq &&
608 git ls-files -s >index_files &&
609 test_line_count = 2 index_files &&
611 git rev-parse >actual HEAD:bar/bq HEAD:bar/whatever &&
612 git rev-parse >expect B:bq A:foo/whatever &&
613 test_cmp expect actual &&
615 git hash-object bar/bq bar/whatever >actual &&
616 git rev-parse B:bq A:foo/whatever >expect &&
617 test_cmp expect actual &&
619 test_must_fail git rev-parse HEAD:bq HEAD:foo/bq &&
620 test_path_is_missing bq foo/bq foo/whatever
624 ###########################################################################
625 # SECTION 4: Cases involving dirty changes
626 ###########################################################################
628 # Testcase 4a, Changed on A, subset of changes on B, locally modified
633 # Expected: b_2 for merge, b_4 in working copy
636 test_create_repo 4a &&
640 test_write_lines 1 2 3 4 5 6 7 8 9 10 >b &&
650 test_write_lines 1 2 3 4 5 5.5 6 7 8 9 10 10.5 >b &&
656 test_write_lines 1 2 3 4 5 5.5 6 7 8 9 10 >b &&
663 # NOTE: For as long as we continue using unpack_trees() without index_only
664 # set to true, it will error out on a case like this claiming the the locally
665 # modified file would be overwritten by the merge. Getting this testcase
666 # correct requires doing the merge in-memory first, then realizing that no
667 # updates to the file are necessary, and thus that we can just leave the path
669 test_expect_failure '4a: Change on A, change on B subset of A, dirty mods present' '
675 echo "File rewritten" >b &&
677 test-tool chmtime --get -3600 b >old-mtime &&
679 GIT_MERGE_VERBOSITY=3 git merge -s recursive B^0 >out 2>err &&
681 test_must_be_empty err &&
683 # Make sure b was NOT updated
684 test-tool chmtime --get b >new-mtime &&
685 test_cmp old-mtime new-mtime &&
687 git ls-files -s >index_files &&
688 test_line_count = 1 index_files &&
690 git rev-parse >actual :0:b &&
691 git rev-parse >expect A:b &&
692 test_cmp expect actual &&
694 git hash-object b >actual &&
695 echo "File rewritten" | git hash-object --stdin >expect &&
696 test_cmp expect actual
700 # Testcase 4b, Changed+renamed on A, subset of changes on B, locally modified
708 test_create_repo 4b &&
712 test_write_lines 1 2 3 4 5 6 7 8 9 10 >b &&
722 test_write_lines 1 2 3 4 5 5.5 6 7 8 9 10 10.5 >b &&
729 test_write_lines 1 2 3 4 5 5.5 6 7 8 9 10 >b &&
736 test_expect_success '4b: Rename+Mod(A)/Mod(B), change on B subset of A, dirty mods present' '
742 echo "File rewritten" >c &&
744 test-tool chmtime --get -3600 c >old-mtime &&
746 GIT_MERGE_VERBOSITY=3 git merge -s recursive B^0 >out 2>err &&
748 test_must_be_empty err &&
750 # Make sure c was NOT updated
751 test-tool chmtime --get c >new-mtime &&
752 test_cmp old-mtime new-mtime &&
754 git ls-files -s >index_files &&
755 test_line_count = 1 index_files &&
757 git rev-parse >actual :0:c &&
758 git rev-parse >expect A:c &&
759 test_cmp expect actual &&
761 git hash-object c >actual &&
762 echo "File rewritten" | git hash-object --stdin >expect &&
763 test_cmp expect actual &&
765 test_must_fail git rev-parse HEAD:b &&
766 test_path_is_missing b