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 =-1 b &&
75 test-tool chmtime --get 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 =-1 b &&
106 test-tool chmtime --get b >old-mtime &&
107 GIT_MERGE_VERBOSITY=3 git merge -s recursive A^0 >out 2>err &&
109 # Make sure b WAS updated
110 test-tool chmtime --get b >new-mtime &&
111 test $(cat old-mtime) -lt $(cat new-mtime) &&
113 test_must_be_empty err &&
115 git ls-files -s >index_files &&
116 test_line_count = 1 index_files &&
118 git rev-parse >actual HEAD:b &&
119 git rev-parse >expect A:b &&
120 test_cmp expect actual &&
122 git hash-object b >actual &&
123 git rev-parse A:b >expect &&
124 test_cmp expect actual
129 ###########################################################################
130 # SECTION 2: Cases involving basic renames
131 ###########################################################################
133 # Testcase 2a, Changes on A, rename on B
140 test_create_repo 2a_$1 &&
166 test_expect_success '2a-L: Modify/rename, merge into modify side' '
173 test_path_is_missing c &&
174 GIT_MERGE_VERBOSITY=3 git merge -s recursive B^0 >out 2>err &&
176 test_path_is_file c &&
178 git ls-files -s >index_files &&
179 test_line_count = 1 index_files &&
181 git rev-parse >actual HEAD:c &&
182 git rev-parse >expect A:b &&
183 test_cmp expect actual &&
185 git hash-object c >actual &&
186 git rev-parse A:b >expect &&
187 test_cmp expect actual &&
189 test_must_fail git rev-parse HEAD:b &&
190 test_path_is_missing b
194 test_expect_success '2a-R: Modify/rename, merge into rename side' '
201 test-tool chmtime =-1 c &&
202 test-tool chmtime --get c >old-mtime &&
203 GIT_MERGE_VERBOSITY=3 git merge -s recursive A^0 >out 2>err &&
205 # Make sure c WAS updated
206 test-tool chmtime --get c >new-mtime &&
207 test $(cat old-mtime) -lt $(cat new-mtime) &&
209 test_must_be_empty err &&
211 git ls-files -s >index_files &&
212 test_line_count = 1 index_files &&
214 git rev-parse >actual HEAD:c &&
215 git rev-parse >expect A:b &&
216 test_cmp expect actual &&
218 git hash-object c >actual &&
219 git rev-parse A:b >expect &&
220 test_cmp expect actual &&
222 test_must_fail git rev-parse HEAD:b &&
223 test_path_is_missing b
227 # Testcase 2b, Changed and renamed on A, subset of changes on B
234 test_create_repo 2b_$1 &&
238 test_write_lines 1 2 3 4 5 6 7 8 9 10 >b &&
248 test_write_lines 1 2 3 4 5 5.5 6 7 8 9 10 10.5 >b &&
255 test_write_lines 1 2 3 4 5 5.5 6 7 8 9 10 >b &&
262 test_expect_success '2b-L: Rename+Mod(A)/Mod(B), B mods subset of A' '
269 test-tool chmtime =-1 c &&
270 test-tool chmtime --get c >old-mtime &&
271 GIT_MERGE_VERBOSITY=3 git merge -s recursive B^0 >out 2>err &&
273 test_must_be_empty err &&
275 # Make sure c WAS updated
276 test-tool chmtime --get c >new-mtime &&
277 test_cmp old-mtime new-mtime &&
279 git ls-files -s >index_files &&
280 test_line_count = 1 index_files &&
282 git rev-parse >actual HEAD:c &&
283 git rev-parse >expect A:c &&
284 test_cmp expect actual &&
286 git hash-object c >actual &&
287 git rev-parse A:c >expect &&
288 test_cmp expect actual &&
290 test_must_fail git rev-parse HEAD:b &&
291 test_path_is_missing b
295 test_expect_success '2b-R: Rename+Mod(A)/Mod(B), B mods subset of A' '
302 test_path_is_missing c &&
303 GIT_MERGE_VERBOSITY=3 git merge -s recursive A^0 >out 2>err &&
305 # Make sure c now present (and thus was updated)
306 test_path_is_file c &&
308 test_must_be_empty err &&
310 git ls-files -s >index_files &&
311 test_line_count = 1 index_files &&
313 git rev-parse >actual HEAD:c &&
314 git rev-parse >expect A:c &&
315 test_cmp expect actual &&
317 git hash-object c >actual &&
318 git rev-parse A:c >expect &&
319 test_cmp expect actual &&
321 test_must_fail git rev-parse HEAD:b &&
322 test_path_is_missing b
326 # Testcase 2c, Changes on A, rename on B
330 # Expected: rename/add conflict c_2 vs c_3
332 # NOTE: Since A modified b_1->b_2, and B renamed b_1->c_1, the threeway
333 # merge of those files should result in c_2. We then should have a
334 # rename/add conflict between c_2 and c_3. However, if we note in
335 # merge_content() that A had the right contents (b_2 has same
336 # contents as c_2, just at a different name), and that A had the
337 # right path present (c_3 existed) and thus decides that it can
338 # skip the update, then we're in trouble. This test verifies we do
339 # not make that particular mistake.
342 test_create_repo 2c &&
369 test_expect_success '2c: Modify b & add c VS rename b->c' '
376 test-tool chmtime =-1 c &&
377 test-tool chmtime --get c >old-mtime &&
378 GIT_MERGE_VERBOSITY=3 &&
379 export GIT_MERGE_VERBOSITY &&
380 test_must_fail git merge -s recursive B^0 >out 2>err &&
382 test_i18ngrep "CONFLICT (rename/add): Rename b->c" out &&
383 test_must_be_empty err &&
385 # Make sure c WAS updated
386 test-tool chmtime --get c >new-mtime &&
387 test $(cat old-mtime) -lt $(cat new-mtime)
389 # FIXME: rename/add conflicts are horribly broken right now;
390 # when I get back to my patch series fixing it and
391 # rename/rename(2to1) conflicts to bring them in line with
392 # how add/add conflicts behave, then checks like the below
393 # could be added. But that patch series is waiting until
394 # the rename-directory-detection series lands, which this
395 # is part of. And in the mean time, I do not want to further
396 # enforce broken behavior. So for now, the main test is the
397 # one above that err is an empty file.
399 #git ls-files -s >index_files &&
400 #test_line_count = 2 index_files &&
402 #git rev-parse >actual :2:c :3:c &&
403 #git rev-parse >expect A:b A:c &&
404 #test_cmp expect actual &&
406 #git cat-file -p A:b >>merged &&
407 #git cat-file -p A:c >>merge-me &&
409 #test_must_fail git merge-file \
410 # -L "Temporary merge branch 1" \
412 # -L "Temporary merge branch 2" \
413 # merged empty merge-me &&
414 #sed -e "s/^\([<=>]\)/\1\1\1/" merged >merged-internal &&
416 #git hash-object c >actual &&
417 #git hash-object merged-internal >expect &&
418 #test_cmp expect actual &&
420 #test_path_is_missing b
425 ###########################################################################
426 # SECTION 3: Cases involving directory renames
429 # Directory renames only apply when one side renames a directory, and the
430 # other side adds or renames a path into that directory. Applying the
431 # directory rename to that new path creates a new pathname that didn't
432 # exist on either side of history. Thus, it is impossible for the
433 # merge contents to already be at the right path, so all of these checks
434 # exist just to make sure that updates are not skipped.
435 ###########################################################################
437 # Testcase 3a, Change + rename into dir foo on A, dir rename foo->bar on B
438 # Commit O: bq_1, foo/whatever
439 # Commit A: foo/{bq_2, whatever}
440 # Commit B: bq_1, bar/whatever
441 # Expected: bar/{bq_2, whatever}
444 test_create_repo 3a_$1 &&
450 test_write_lines a b c d e f g h i j k >foo/whatever &&
451 git add bq foo/whatever &&
473 test_expect_success '3a-L: bq_1->foo/bq_2 on A, foo/->bar/ on B' '
480 test_path_is_missing bar/bq &&
481 GIT_MERGE_VERBOSITY=3 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
483 test_must_be_empty err &&
485 test_path_is_file bar/bq &&
487 git ls-files -s >index_files &&
488 test_line_count = 2 index_files &&
490 git rev-parse >actual HEAD:bar/bq HEAD:bar/whatever &&
491 git rev-parse >expect A:foo/bq A:foo/whatever &&
492 test_cmp expect actual &&
494 git hash-object bar/bq bar/whatever >actual &&
495 git rev-parse A:foo/bq A:foo/whatever >expect &&
496 test_cmp expect actual &&
498 test_must_fail git rev-parse HEAD:bq HEAD:foo/bq &&
499 test_path_is_missing bq foo/bq foo/whatever
503 test_expect_success '3a-R: bq_1->foo/bq_2 on A, foo/->bar/ on B' '
510 test_path_is_missing bar/bq &&
511 GIT_MERGE_VERBOSITY=3 git -c merge.directoryRenames=true merge -s recursive A^0 >out 2>err &&
513 test_must_be_empty err &&
515 test_path_is_file bar/bq &&
517 git ls-files -s >index_files &&
518 test_line_count = 2 index_files &&
520 git rev-parse >actual HEAD:bar/bq HEAD:bar/whatever &&
521 git rev-parse >expect A:foo/bq A:foo/whatever &&
522 test_cmp expect actual &&
524 git hash-object bar/bq bar/whatever >actual &&
525 git rev-parse A:foo/bq A:foo/whatever >expect &&
526 test_cmp expect actual &&
528 test_must_fail git rev-parse HEAD:bq HEAD:foo/bq &&
529 test_path_is_missing bq foo/bq foo/whatever
533 # Testcase 3b, rename into dir foo on A, dir rename foo->bar + change on B
534 # Commit O: bq_1, foo/whatever
535 # Commit A: foo/{bq_1, whatever}
536 # Commit B: bq_2, bar/whatever
537 # Expected: bar/{bq_2, whatever}
540 test_create_repo 3b_$1 &&
546 test_write_lines a b c d e f g h i j k >foo/whatever &&
547 git add bq foo/whatever &&
569 test_expect_success '3b-L: bq_1->foo/bq_2 on A, foo/->bar/ on B' '
576 test_path_is_missing bar/bq &&
577 GIT_MERGE_VERBOSITY=3 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
579 test_must_be_empty err &&
581 test_path_is_file bar/bq &&
583 git ls-files -s >index_files &&
584 test_line_count = 2 index_files &&
586 git rev-parse >actual HEAD:bar/bq HEAD:bar/whatever &&
587 git rev-parse >expect B:bq A:foo/whatever &&
588 test_cmp expect actual &&
590 git hash-object bar/bq bar/whatever >actual &&
591 git rev-parse B:bq A:foo/whatever >expect &&
592 test_cmp expect actual &&
594 test_must_fail git rev-parse HEAD:bq HEAD:foo/bq &&
595 test_path_is_missing bq foo/bq foo/whatever
599 test_expect_success '3b-R: bq_1->foo/bq_2 on A, foo/->bar/ on B' '
606 test_path_is_missing bar/bq &&
607 GIT_MERGE_VERBOSITY=3 git -c merge.directoryRenames=true merge -s recursive A^0 >out 2>err &&
609 test_must_be_empty err &&
611 test_path_is_file bar/bq &&
613 git ls-files -s >index_files &&
614 test_line_count = 2 index_files &&
616 git rev-parse >actual HEAD:bar/bq HEAD:bar/whatever &&
617 git rev-parse >expect B:bq A:foo/whatever &&
618 test_cmp expect actual &&
620 git hash-object bar/bq bar/whatever >actual &&
621 git rev-parse B:bq A:foo/whatever >expect &&
622 test_cmp expect actual &&
624 test_must_fail git rev-parse HEAD:bq HEAD:foo/bq &&
625 test_path_is_missing bq foo/bq foo/whatever
629 ###########################################################################
630 # SECTION 4: Cases involving dirty changes
631 ###########################################################################
633 # Testcase 4a, Changed on A, subset of changes on B, locally modified
638 # Expected: b_2 for merge, b_4 in working copy
641 test_create_repo 4a &&
645 test_write_lines 1 2 3 4 5 6 7 8 9 10 >b &&
655 test_write_lines 1 2 3 4 5 5.5 6 7 8 9 10 10.5 >b &&
661 test_write_lines 1 2 3 4 5 5.5 6 7 8 9 10 >b &&
668 # NOTE: For as long as we continue using unpack_trees() without index_only
669 # set to true, it will error out on a case like this claiming the the locally
670 # modified file would be overwritten by the merge. Getting this testcase
671 # correct requires doing the merge in-memory first, then realizing that no
672 # updates to the file are necessary, and thus that we can just leave the path
674 test_expect_failure '4a: Change on A, change on B subset of A, dirty mods present' '
680 echo "File rewritten" >b &&
682 test-tool chmtime =-1 b &&
683 test-tool chmtime --get b >old-mtime &&
685 GIT_MERGE_VERBOSITY=3 git merge -s recursive B^0 >out 2>err &&
687 test_must_be_empty err &&
689 # Make sure b was NOT updated
690 test-tool chmtime --get b >new-mtime &&
691 test_cmp old-mtime new-mtime &&
693 git ls-files -s >index_files &&
694 test_line_count = 1 index_files &&
696 git rev-parse >actual :0:b &&
697 git rev-parse >expect A:b &&
698 test_cmp expect actual &&
700 git hash-object b >actual &&
701 echo "File rewritten" | git hash-object --stdin >expect &&
702 test_cmp expect actual
706 # Testcase 4b, Changed+renamed on A, subset of changes on B, locally modified
714 test_create_repo 4b &&
718 test_write_lines 1 2 3 4 5 6 7 8 9 10 >b &&
728 test_write_lines 1 2 3 4 5 5.5 6 7 8 9 10 10.5 >b &&
735 test_write_lines 1 2 3 4 5 5.5 6 7 8 9 10 >b &&
742 test_expect_success '4b: Rename+Mod(A)/Mod(B), change on B subset of A, dirty mods present' '
748 echo "File rewritten" >c &&
750 test-tool chmtime =-1 c &&
751 test-tool chmtime --get c >old-mtime &&
753 GIT_MERGE_VERBOSITY=3 git merge -s recursive B^0 >out 2>err &&
755 test_must_be_empty err &&
757 # Make sure c was NOT updated
758 test-tool chmtime --get c >new-mtime &&
759 test_cmp old-mtime new-mtime &&
761 git ls-files -s >index_files &&
762 test_line_count = 1 index_files &&
764 git rev-parse >actual :0:c &&
765 git rev-parse >expect A:c &&
766 test_cmp expect actual &&
768 git hash-object c >actual &&
769 echo "File rewritten" | git hash-object --stdin >expect &&
770 test_cmp expect actual &&
772 test_must_fail git rev-parse HEAD:b &&
773 test_path_is_missing b