]>
git.ipfire.org Git - thirdparty/git.git/blob - t/t6036-recursive-corner-cases.sh
3 test_description
='recursive merge corner cases involving criss-cross merges'
7 get_clean_checkout
() {
23 test_expect_success
'setup basic criss-cross + rename with no modifications' '
24 ten="0 1 2 3 4 5 6 7 8 9" &&
27 echo line $i in a sample file
31 echo line $i in another sample file
34 test_tick && git commit -m initial &&
39 test_tick && git commit -m R1 &&
43 test_tick && git commit -m L1 &&
46 test_tick && git merge -s ours R1 &&
50 test_tick && git merge -s ours L1 &&
54 test_expect_success
'merge simple rename+criss-cross with no modifications' '
58 test_must_fail git merge -s recursive R2^0 &&
60 test 5 = $(git ls-files -s | wc -l) &&
61 test 3 = $(git ls-files -u | wc -l) &&
62 test 0 = $(git ls-files -o | wc -l) &&
64 test $(git rev-parse :0:one) = $(git rev-parse L2:one) &&
65 test $(git rev-parse :0:two) = $(git rev-parse R2:two) &&
66 test $(git rev-parse :2:three) = $(git rev-parse L2:three) &&
67 test $(git rev-parse :3:three) = $(git rev-parse R2:three) &&
71 test_must_fail git merge-file \
72 -L "Temporary merge branch 2" \
74 -L "Temporary merge branch 1" \
76 test $(git rev-parse :1:three) = $(git hash-object merged)
80 # Same as before, but modify L1 slightly:
91 test_expect_success
'setup criss-cross + rename merges with basic modification' '
97 ten="0 1 2 3 4 5 6 7 8 9"
100 echo line $i in a sample file
104 echo line $i in another sample file
107 test_tick && git commit -m initial &&
110 git checkout -b R1 &&
114 test_tick && git commit -m R1 &&
118 test_tick && git commit -m L1 &&
121 test_tick && git merge -s ours R1 &&
125 test_tick && git merge -s ours L1 &&
129 test_expect_success
'merge criss-cross + rename merges with basic modification' '
133 test_must_fail git merge -s recursive R2^0 &&
135 test 5 = $(git ls-files -s | wc -l) &&
136 test 3 = $(git ls-files -u | wc -l) &&
137 test 0 = $(git ls-files -o | wc -l) &&
139 test $(git rev-parse :0:one) = $(git rev-parse L2:one) &&
140 test $(git rev-parse :0:two) = $(git rev-parse R2:two) &&
141 test $(git rev-parse :2:three) = $(git rev-parse L2:three) &&
142 test $(git rev-parse :3:three) = $(git rev-parse R2:three) &&
144 head -n 10 two >merged &&
147 test_must_fail git merge-file \
148 -L "Temporary merge branch 2" \
150 -L "Temporary merge branch 1" \
151 merged empty merge-me &&
152 test $(git rev-parse :1:three) = $(git hash-object merged)
156 # For the next test, we start with three commits in two lines of development
157 # which setup a rename/add conflict:
158 # Commit A: File 'a' exists
159 # Commit B: Rename 'a' -> 'new_a'
160 # Commit C: Modify 'a', create different 'new_a'
161 # Later, two different people merge and resolve differently:
162 # Commit D: Merge B & C, ignoring separately created 'new_a'
163 # Commit E: Merge B & C making use of some piece of secondary 'new_a'
164 # Finally, someone goes to merge D & E. Does git detect the conflict?
175 test_expect_success
'setup differently handled merges of rename/add conflict' '
181 printf "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n" >a &&
183 test_tick && git commit -m A &&
188 echo "other content" >>new_a &&
190 test_tick && git commit -m C &&
194 test_tick && git commit -m B &&
197 test_must_fail git merge C &&
199 test_tick && git commit -m D &&
203 test_must_fail git merge B &&
204 rm new_a~HEAD new_a &&
205 printf "Incorrectly merged content" >>new_a &&
207 test_tick && git commit -m E &&
211 test_expect_success
'git detects differently handled merges conflict' '
215 git merge -s recursive E^0 && {
216 echo "BAD: should have conflicted"
217 test "Incorrectly merged content" = "$(cat new_a)" &&
218 echo "BAD: Silently accepted wrong content"
222 test 3 = $(git ls-files -s | wc -l) &&
223 test 3 = $(git ls-files -u | wc -l) &&
224 test 0 = $(git ls-files -o | wc -l) &&
226 test $(git rev-parse :2:new_a) = $(git rev-parse D:new_a) &&
227 test $(git rev-parse :3:new_a) = $(git rev-parse E:new_a) &&
229 git cat-file -p B:new_a >>merged &&
230 git cat-file -p C:new_a >>merge-me &&
232 test_must_fail git merge-file \
233 -L "Temporary merge branch 2" \
235 -L "Temporary merge branch 1" \
236 merged empty merge-me &&
237 test $(git rev-parse :1:new_a) = $(git hash-object merged)
241 # criss-cross + modify/delete:
251 # Commit A: file with contents 'A\n'
252 # Commit B: file with contents 'B\n'
253 # Commit C: file not present
254 # Commit D: file with contents 'B\n'
255 # Commit E: file not present
257 # Merging commits D & E should result in modify/delete conflict.
259 test_expect_success
'setup criss-cross + modify/delete resolved differently' '
283 test_must_fail git merge C &&
291 test_must_fail git merge B &&
298 test_expect_failure
'git detects conflict merging criss-cross+modify/delete' '
301 test_must_fail git merge -s recursive E^0 &&
303 test 2 -eq $(git ls-files -s | wc -l) &&
304 test 2 -eq $(git ls-files -u | wc -l) &&
306 test $(git rev-parse :1:file) = $(git rev-parse master:file) &&
307 test $(git rev-parse :2:file) = $(git rev-parse B:file)
310 test_expect_failure
'git detects conflict merging criss-cross+modify/delete, reverse direction' '
314 test_must_fail git merge -s recursive D^0 &&
316 test 2 -eq $(git ls-files -s | wc -l) &&
317 test 2 -eq $(git ls-files -u | wc -l) &&
319 test $(git rev-parse :1:file) = $(git rev-parse master:file) &&
320 test $(git rev-parse :3:file) = $(git rev-parse B:file)
324 # criss-cross + modify/modify with very contrived file contents:
334 # Commit A: file with contents 'A\n'
335 # Commit B: file with contents 'B\n'
336 # Commit C: file with contents 'C\n'
337 # Commit D: file with contents 'D\n'
338 # Commit E: file with contents:
339 # <<<<<<< Temporary merge branch 1
343 # >>>>>>> Temporary merge branch 2
345 # Now, when we merge commits D & E, does git detect the conflict?
347 test_expect_success
'setup differently handled merges of content conflict' '
371 test_must_fail git merge C &&
379 test_must_fail git merge B &&
381 <<<<<<< Temporary merge branch 1
385 >>>>>>> Temporary merge branch 2
393 test_expect_failure
'git detects conflict w/ criss-cross+contrived resolution' '
396 test_must_fail git merge -s recursive E^0 &&
398 test 3 -eq $(git ls-files -s | wc -l) &&
399 test 3 -eq $(git ls-files -u | wc -l) &&
400 test 0 -eq $(git ls-files -o | wc -l) &&
402 test $(git rev-parse :2:file) = $(git rev-parse D:file) &&
403 test $(git rev-parse :3:file) = $(git rev-parse E:file)
407 # criss-cross + d/f conflict via add/add:
408 # Commit A: Neither file 'a' nor directory 'a/' exist.
409 # Commit B: Introduce 'a'
410 # Commit C: Introduce 'a/file'
411 # Commit D: Merge B & C, keeping 'a' and deleting 'a/'
413 # Two different later cases:
414 # Commit E1: Merge B & C, deleting 'a' but keeping 'a/file'
415 # Commit E2: Merge B & C, deleting 'a' but keeping a slightly modified 'a/file'
425 # Merging D & E1 requires we first create a virtual merge base X from
426 # merging A & B in memory. Now, if X could keep both 'a' and 'a/file' in
427 # the index, then the merge of D & E1 could be resolved cleanly with both
428 # 'a' and 'a/file' removed. Since git does not currently allow creating
429 # such a tree, the best we can do is have X contain both 'a~<unique>' and
430 # 'a/file' resulting in the merge of D and E1 having a rename/delete
431 # conflict for 'a'. (Although this merge appears to be unsolvable with git
432 # currently, git could do a lot better than it currently does with these
433 # d/f conflicts, which is the purpose of this test.)
435 # Merge of D & E2 has similar issues for path 'a', but should always result
436 # in a modify/delete conflict for path 'a/file'.
438 # We run each merge in both directions, to check for directional issues
439 # with D/F conflict handling.
442 test_expect_success
'setup differently handled merges of directory/file conflict' '
469 test_must_fail git merge C &&
479 test_must_fail git merge B &&
489 test_must_fail git merge B &&
492 printf "10\n11\n" >a/file &&
499 test_expect_success
'merge of D & E1 fails but has appropriate contents' '
500 get_clean_checkout D^0 &&
502 test_must_fail git merge -s recursive E1^0 &&
504 test 2 -eq $(git ls-files -s | wc -l) &&
505 test 1 -eq $(git ls-files -u | wc -l) &&
506 test 0 -eq $(git ls-files -o | wc -l) &&
508 test $(git rev-parse :0:ignore-me) = $(git rev-parse A:ignore-me) &&
509 test $(git rev-parse :2:a) = $(git rev-parse B:a)
512 test_expect_success
'merge of E1 & D fails but has appropriate contents' '
513 get_clean_checkout E1^0 &&
515 test_must_fail git merge -s recursive D^0 &&
517 test 2 -eq $(git ls-files -s | wc -l) &&
518 test 1 -eq $(git ls-files -u | wc -l) &&
519 test 0 -eq $(git ls-files -o | wc -l) &&
521 test $(git rev-parse :0:ignore-me) = $(git rev-parse A:ignore-me) &&
522 test $(git rev-parse :3:a) = $(git rev-parse B:a)
525 test_expect_success
'merge of D & E2 fails but has appropriate contents' '
526 get_clean_checkout D^0 &&
528 test_must_fail git merge -s recursive E2^0 &&
530 test 4 -eq $(git ls-files -s | wc -l) &&
531 test 3 -eq $(git ls-files -u | wc -l) &&
532 test 1 -eq $(git ls-files -o | wc -l) &&
534 test $(git rev-parse :2:a) = $(git rev-parse B:a) &&
535 test $(git rev-parse :3:a/file) = $(git rev-parse E2:a/file) &&
536 test $(git rev-parse :1:a/file) = $(git rev-parse C:a/file) &&
537 test $(git rev-parse :0:ignore-me) = $(git rev-parse A:ignore-me) &&
542 test_expect_success
'merge of E2 & D fails but has appropriate contents' '
543 get_clean_checkout E2^0 &&
545 test_must_fail git merge -s recursive D^0 &&
547 test 4 -eq $(git ls-files -s | wc -l) &&
548 test 3 -eq $(git ls-files -u | wc -l) &&
549 test 1 -eq $(git ls-files -o | wc -l) &&
551 test $(git rev-parse :3:a) = $(git rev-parse B:a) &&
552 test $(git rev-parse :2:a/file) = $(git rev-parse E2:a/file) &&
553 test $(git rev-parse :1:a/file) = $(git rev-parse C:a/file)
554 test $(git rev-parse :0:ignore-me) = $(git rev-parse A:ignore-me) &&
560 # criss-cross with rename/rename(1to2)/modify followed by
561 # rename/rename(2to1)/modify:
571 # Commit A: new file: a
572 # Commit B: rename a->b, modifying by adding a line
573 # Commit C: rename a->c
574 # Commit D: merge B&C, resolving conflict by keeping contents in newname
575 # Commit E: merge B&C, resolving conflict similar to D but adding another line
577 # There is a conflict merging B & C, but one of filename not of file
578 # content. Whoever created D and E chose specific resolutions for that
579 # conflict resolution. Now, since: (1) there is no content conflict
580 # merging B & C, (2) D does not modify that merged content further, and (3)
581 # both D & E resolve the name conflict in the same way, the modification to
582 # newname in E should not cause any conflicts when it is merged with D.
583 # (Note that this can be accomplished by having the virtual merge base have
584 # the merged contents of b and c stored in a file named a, which seems like
585 # the most logical choice anyway.)
587 # Comment from Junio: I do not necessarily agree with the choice "a", but
588 # it feels sound to say "B and C do not agree what the final pathname
589 # should be, but we know this content was derived from the common A:a so we
590 # use one path whose name is arbitrary in the virtual merge base X between
591 # D and E" and then further let the rename detection to notice that that
592 # arbitrary path gets renamed between X-D to "newname" and X-E also to
593 # "newname" to resolve it as both sides renaming it to the same new
594 # name. It is akin to what we do at the content level, i.e. "B and C do not
595 # agree what the final contents should be, so we leave the conflict marker
596 # but that may cancel out at the final merge stage".
598 test_expect_success
'setup rename/rename(1to2)/modify followed by what looks like rename/rename(2to1)/modify' '
605 printf "1\n2\n3\n4\n5\n6\n" >a &&
610 git checkout -b B A &&
616 git checkout -b C A &&
620 git checkout -q B^0 &&
621 git merge --no-commit -s ours C^0 &&
623 git commit -m "Merge commit C^0 into HEAD" &&
626 git checkout -q C^0 &&
627 git merge --no-commit -s ours B^0 &&
629 printf "7\n8\n" >>newname &&
631 git commit -m "Merge commit B^0 into HEAD" &&
635 test_expect_failure
'handle rename/rename(1to2)/modify followed by what looks like rename/rename(2to1)/modify' '
638 git merge -s recursive E^0 &&
640 test 1 -eq $(git ls-files -s | wc -l) &&
641 test 0 -eq $(git ls-files -u | wc -l) &&
642 test 0 -eq $(git ls-files -o | wc -l) &&
644 test $(git rev-parse HEAD:newname) = $(git rev-parse E:newname)
648 # criss-cross with rename/rename(1to2)/add-source + resolvable modify/modify:
658 # Commit A: new file: a
659 # Commit B: rename a->b
660 # Commit C: rename a->c, add different a
661 # Commit D: merge B&C, keeping b&c and (new) a modified at beginning
662 # Commit E: merge B&C, keeping b&c and (new) a modified at end
664 # Merging commits D & E should result in no conflict; doing so correctly
665 # requires getting the virtual merge base (from merging B&C) right, handling
666 # renaming carefully (both in the virtual merge base and later), and getting
667 # content merge handled.
669 test_expect_success
'setup criss-cross + rename/rename/add + modify/modify' '
675 printf "lots\nof\nwords\nand\ncontent\n" >a &&
680 git checkout -b B A &&
684 git checkout -b C A &&
686 printf "2\n3\n4\n5\n6\n7\n" >a &&
691 git merge --no-commit -s ours C^0 &&
692 git checkout C -- a c &&
698 git commit -m "Merge commit C^0 into HEAD" &&
702 git merge --no-commit -s ours B^0 &&
703 git checkout B -- b &&
706 git commit -m "Merge commit B^0 into HEAD" &&
710 test_expect_failure
'detect rename/rename/add-source for virtual merge-base' '
713 git merge -s recursive E^0 &&
715 test 3 -eq $(git ls-files -s | wc -l) &&
716 test 0 -eq $(git ls-files -u | wc -l) &&
717 test 0 -eq $(git ls-files -o | wc -l) &&
719 test $(git rev-parse HEAD:b) = $(git rev-parse A:a) &&
720 test $(git rev-parse HEAD:c) = $(git rev-parse A:a) &&
721 test "$(cat a)" = "$(printf "1\n2\n3\n4\n5\n6\n7\n8\n")"