3 test_description
='Merge-recursive merging renames'
7 sed -e "$1" <"$2" >"$2.x" &&
11 test_expect_success setup \
14 a aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
15 b bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
16 c cccccccccccccccccccccccccccccccccccccccccccccccc
17 d dddddddddddddddddddddddddddddddddddddddddddddddd
18 e eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
19 f ffffffffffffffffffffffffffffffffffffffffffffffff
20 g gggggggggggggggggggggggggggggggggggggggggggggggg
21 h hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
22 i iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
23 j jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj
24 k kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
25 l llllllllllllllllllllllllllllllllllllllllllllllll
26 m mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
27 n nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
28 o oooooooooooooooooooooooooooooooooooooooooooooooo
32 A AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
33 B BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
34 C CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
35 D DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
36 E EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
37 F FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
38 G GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
39 H HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
40 I IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
41 J JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
42 K KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK
43 L LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
44 M MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
45 N NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
46 O OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
50 git commit -m "initial has A and M" &&
56 git branch change+rename &&
58 sed -e "/^g /s/.*/g : master changes a line/" <A >A+ &&
60 git commit -a -m "master updates A" &&
62 git checkout yellow &&
64 git commit -a -m "yellow removes M" &&
67 sed -e "/^g /s/.*/g : white changes a line/" <A >B &&
68 sed -e "/^G /s/.*/G : colored branch changes a line/" <M >N &&
70 git update-index --add --remove A B M N &&
71 git commit -m "white renames A->B, M->N" &&
74 sed -e "/^g /s/.*/g : red changes a line/" <A >B &&
75 sed -e "/^G /s/.*/G : colored branch changes a line/" <M >N &&
77 git update-index --add --remove A B M N &&
78 git commit -m "red renames A->B, M->N" &&
81 sed -e "/^g /s/.*/g : blue changes a line/" <A >C &&
82 sed -e "/^G /s/.*/G : colored branch changes a line/" <M >N &&
84 git update-index --add --remove A C M N &&
85 git commit -m "blue renames A->C, M->N" &&
87 git checkout change &&
88 sed -e "/^g /s/.*/g : changed line/" <A >A+ &&
90 git commit -q -a -m "changed" &&
92 git checkout change+rename &&
93 sed -e "/^g /s/.*/g : changed line/" <A >B &&
95 git update-index --add B &&
96 git commit -q -a -m "changed and renamed" &&
100 test_expect_success
'pull renaming branch into unrenaming one' \
103 git pull . white && {
104 echo "BAD: should have conflicted"
108 test "$(git ls-files -u B | wc -l)" -eq 3 || {
109 echo "BAD: should have left stages for B"
112 test "$(git ls-files -s N | wc -l)" -eq 1 || {
113 echo "BAD: should have merged N"
119 }" B | grep master || {
120 echo "BAD: should have listed our change first"
123 test "$(git diff white N | wc -l)" -eq 0 || {
124 echo "BAD: should have taken colored branch"
129 test_expect_success
'pull renaming branch into another renaming one' \
134 git pull . white && {
135 echo "BAD: should have conflicted"
138 test "$(git ls-files -u B | wc -l)" -eq 3 || {
139 echo "BAD: should have left stages"
142 test "$(git ls-files -s N | wc -l)" -eq 1 || {
143 echo "BAD: should have merged N"
150 echo "BAD: should have listed our change first"
153 test "$(git diff white N | wc -l)" -eq 0 || {
154 echo "BAD: should have taken colored branch"
159 test_expect_success
'pull unrenaming branch into renaming one' \
163 git pull . master && {
164 echo "BAD: should have conflicted"
167 test "$(git ls-files -u B | wc -l)" -eq 3 || {
168 echo "BAD: should have left stages"
171 test "$(git ls-files -s N | wc -l)" -eq 1 || {
172 echo "BAD: should have merged N"
179 echo "BAD: should have listed our change first"
182 test "$(git diff white N | wc -l)" -eq 0 || {
183 echo "BAD: should have taken colored branch"
188 test_expect_success
'pull conflicting renames' \
193 echo "BAD: should have conflicted"
196 test "$(git ls-files -u A | wc -l)" -eq 1 || {
197 echo "BAD: should have left a stage"
200 test "$(git ls-files -u B | wc -l)" -eq 1 || {
201 echo "BAD: should have left a stage"
204 test "$(git ls-files -u C | wc -l)" -eq 1 || {
205 echo "BAD: should have left a stage"
208 test "$(git ls-files -s N | wc -l)" -eq 1 || {
209 echo "BAD: should have merged N"
216 echo "BAD: should have listed our change first"
219 test "$(git diff white N | wc -l)" -eq 0 || {
220 echo "BAD: should have taken colored branch"
225 test_expect_success
'interference with untracked working tree file' '
229 echo >A this file should not matter
230 git pull . white && {
231 echo "BAD: should have conflicted"
235 echo "BAD: should have left A intact"
240 test_expect_success
'interference with untracked working tree file' '
246 echo >A this file should not matter
248 echo "BAD: should have conflicted"
252 echo "BAD: should have left A intact"
257 test_expect_success
'interference with untracked working tree file' '
261 git checkout -f master
264 git pull . yellow || {
265 echo "BAD: should have cleanly merged"
269 echo "BAD: should have removed M"
272 git reset --hard anchor
275 test_expect_success
'updated working tree file should prevent the merge' '
279 git checkout -f master
282 echo >>M one line addition
284 git pull . yellow && {
285 echo "BAD: should have complained"
288 test_cmp M M.saved || {
289 echo "BAD: should have left M intact"
295 test_expect_success
'updated working tree file should prevent the merge' '
299 git checkout -f master
302 echo >>M one line addition
305 git pull . yellow && {
306 echo "BAD: should have complained"
309 test_cmp M M.saved || {
310 echo "BAD: should have left M intact"
316 test_expect_success
'interference with untracked working tree file' '
320 git checkout -f yellow
323 echo >M this file should not matter
324 git pull . master || {
325 echo "BAD: should have cleanly merged"
329 echo "BAD: should have left M intact"
332 git ls-files -s | grep M && {
333 echo "BAD: M must be untracked in the result"
336 git reset --hard anchor
339 test_expect_success
'merge of identical changes in a renamed file' '
342 git checkout change+rename &&
343 GIT_MERGE_VERBOSITY=3 git merge change | grep "^Skipped B" &&
344 git reset --hard HEAD^ &&
345 git checkout change &&
346 GIT_MERGE_VERBOSITY=3 git merge change+rename | grep "^Skipped B"
349 test_expect_success
'setup for rename + d/f conflicts' '
351 git checkout --orphan dir-in-way &&
356 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >sub/file &&
357 echo foo >dir/file-in-the-way &&
359 git commit -m "Common commmit" &&
361 echo 11 >>sub/file &&
362 echo more >>dir/file-in-the-way &&
364 git commit -m "Commit to merge, with dir in the way" &&
366 git checkout -b dir-not-in-way &&
367 git reset --soft HEAD^ &&
369 git commit -m "Commit to merge, with dir removed" -- dir sub/file &&
371 git checkout -b renamed-file-has-no-conflicts dir-in-way~1 &&
374 printf "1\n2\n3\n4\n5555\n6\n7\n8\n9\n10\n" >dir &&
376 git commit -m "Independent change" &&
378 git checkout -b renamed-file-has-conflicts dir-in-way~1 &&
380 git mv sub/file dir &&
383 git commit -m "Conflicting change"
386 printf "1\n2\n3\n4\n5555\n6\n7\n8\n9\n10\n11\n" >expected
388 test_expect_success
'Rename+D/F conflict; renamed file merges + dir not in way' '
390 git checkout -q renamed-file-has-no-conflicts^0 &&
391 git merge --strategy=recursive dir-not-in-way &&
394 test_cmp expected dir
397 test_expect_failure
'Rename+D/F conflict; renamed file merges but dir in way' '
400 git checkout -q renamed-file-has-no-conflicts^0 &&
401 test_must_fail git merge --strategy=recursive dir-in-way >output &&
403 grep "CONFLICT (delete/modify): dir/file-in-the-way" output &&
404 grep "Auto-merging dir" output &&
405 grep "Adding as dir~HEAD instead" output &&
407 test 2 = "$(git ls-files -u | wc -l)" &&
408 test 2 = "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
410 test_must_fail git diff --quiet &&
411 test_must_fail git diff --cached --quiet &&
413 test -f dir/file-in-the-way &&
415 test_cmp expected dir~HEAD
418 test_expect_failure
'Same as previous, but merged other way' '
421 git checkout -q dir-in-way^0 &&
422 test_must_fail git merge --strategy=recursive renamed-file-has-no-conflicts >output 2>errors &&
424 ! grep "error: refusing to lose untracked file at" errors &&
425 grep "CONFLICT (delete/modify): dir/file-in-the-way" output &&
426 grep "Auto-merging dir" output &&
427 grep "Adding as dir~renamed-file-has-no-conflicts instead" output &&
429 test 2 = "$(git ls-files -u | wc -l)" &&
430 test 2 = "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
432 test_must_fail git diff --quiet &&
433 test_must_fail git diff --cached --quiet &&
435 test -f dir/file-in-the-way &&
436 test -f dir~renamed-file-has-no-conflicts &&
437 test_cmp expected dir~renamed-file-has-no-conflicts
440 cat >expected
<<\EOF
&&
455 >>>>>>> dir-not-in-way
458 test_expect_failure 'Rename+D/F conflict; renamed file cannot merge, dir not in way' '
461 git checkout -q renamed-file-has-conflicts^0 &&
462 test_must_fail git merge --strategy=recursive dir-not-in-way &&
464 test 3 = "$(git ls-files -u | wc -l)" &&
465 test 3 = "$(git ls-files -u dir | wc -l)" &&
467 test_must_fail git diff --quiet &&
468 test_must_fail git diff --cached --quiet &&
471 test_cmp expected dir
474 test_expect_failure 'Rename+D/F conflict; renamed file cannot merge and dir in the way' '
475 modify s/dir-not-in-way/dir-in-way/ expected &&
479 git checkout -q renamed-file-has-conflicts^0 &&
480 test_must_fail git merge --strategy=recursive dir-in-way &&
482 test 5 = "$(git ls-files -u | wc -l)" &&
483 test 3 = "$(git ls-files -u dir | grep -v file-in-the-way | wc -l)" &&
484 test 2 = "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
486 test_must_fail git diff --quiet &&
487 test_must_fail git diff --cached --quiet &&
489 test -f dir/file-in-the-way &&
491 test_cmp expected dir~HEAD
494 cat >expected <<\EOF &&
509 >>>>>>> renamed-file-has-conflicts
512 test_expect_failure 'Same as previous
, but merged other way
' '
515 git checkout
-q dir-in-way^
0 &&
516 test_must_fail git merge
--strategy=recursive renamed-file-has-conflicts
&&
518 test 5 = "$(git ls-files -u | wc -l)" &&
519 test 3 = "$(git ls-files -u dir | grep -v file-in-the-way | wc -l)" &&
520 test 2 = "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
522 test_must_fail git
diff --quiet &&
523 test_must_fail git
diff --cached --quiet &&
525 test -f dir
/file-in-the-way
&&
526 test -f dir~renamed-file-has-conflicts
&&
527 test_cmp expected dir~renamed-file-has-conflicts
530 test_expect_success 'setup both rename
source and destination involved
in D
/F conflict
' '
532 git checkout
--orphan rename-dest
&&
537 echo stuff
>one
/file &&
539 git commit
-m "Common commmit" &&
541 git
mv one
/file destdir
&&
542 git commit
-m "Renamed to destdir" &&
544 git checkout
-b source-conflict HEAD~
1 &&
547 touch one destdir
/foo
&&
549 git commit
-m "Conflicts in the way"
552 test_expect_failure 'both rename
source and destination involved
in D
/F conflict
' '
555 git checkout
-q rename-dest^
0 &&
556 test_must_fail git merge
--strategy=recursive source-conflict
&&
558 test 1 = "$(git ls-files -u | wc -l)" &&
560 test_must_fail git
diff --quiet &&
562 test -f destdir
/foo
&&
564 test -f destdir~HEAD
&&
565 test "stuff" = "$(cat destdir~HEAD)"
568 test_expect_success 'setup pair rename to parent of other
(D
/F conflicts
)' '
570 git checkout
--orphan rename-two
&&
576 echo stuff
>one
/file &&
577 echo other
>two
/file &&
579 git commit
-m "Common commmit" &&
582 git
mv two
/file one
&&
583 git commit
-m "Rename two/file -> one" &&
585 git checkout
-b rename-one HEAD~
1 &&
587 git
mv one
/file two
&&
589 git commit
-m "Rename one/file -> two"
592 test_expect_failure 'pair rename to parent of other
(D
/F conflicts
) w
/ untracked dir
' '
593 git checkout
-q rename-one^
0 &&
595 test_must_fail git merge
--strategy=recursive rename-two
&&
597 test 2 = "$(git ls-files -u | wc -l)" &&
598 test 1 = "$(git ls-files -u one | wc -l)" &&
599 test 1 = "$(git ls-files -u two | wc -l)" &&
601 test_must_fail git
diff --quiet &&
603 test 4 = $
(find . |
grep -v .git |
wc -l) &&
606 test -f one~rename-two
&&
608 test "other" = $
(cat one~rename-two
) &&
609 test "stuff" = $
(cat two
)
612 test_expect_success 'pair rename to parent of other
(D
/F conflicts
) w
/ clean start
' '
615 test_must_fail git merge
--strategy=recursive rename-two
&&
617 test 2 = "$(git ls-files -u | wc -l)" &&
618 test 1 = "$(git ls-files -u one | wc -l)" &&
619 test 1 = "$(git ls-files -u two | wc -l)" &&
621 test_must_fail git
diff --quiet &&
623 test 3 = $
(find . |
grep -v .git |
wc -l) &&
627 test "other" = $
(cat one
) &&
628 test "stuff" = $
(cat two
)
631 test_expect_success 'setup rename of one
file to two
, with directories
in the way
' '
633 git checkout
--orphan first-rename
&&
637 echo stuff
>original
&&
639 git commit
-m "Common commmit" &&
644 git
mv original one
&&
645 git commit
-m "Put two/file in the way, rename to one" &&
647 git checkout
-b second-rename HEAD~
1 &&
651 git
mv original two
&&
652 git commit
-m "Put one/file in the way, rename to two"
655 test_expect_success 'check handling of differently renamed
file with D
/F conflicts
' '
656 git checkout
-q first-rename^
0 &&
657 test_must_fail git merge
--strategy=recursive second-rename
&&
659 test 5 = "$(git ls-files -s | wc -l)" &&
660 test 3 = "$(git ls-files -u | wc -l)" &&
661 test 1 = "$(git ls-files -u one | wc -l)" &&
662 test 1 = "$(git ls-files -u two | wc -l)" &&
663 test 1 = "$(git ls-files -u original | wc -l)" &&
664 test 2 = "$(git ls-files -o | wc -l)" &&
669 test -f two~second-rename
&&
673 test_expect_success 'setup rename one
file to two
; directories moving out of the way
' '
675 git checkout
--orphan first-rename-redo
&&
679 echo stuff
>original
&&
681 touch one
/file two
/file &&
683 git commit
-m "Common commmit" &&
686 git
mv original one
&&
687 git commit
-m "Rename to one" &&
689 git checkout
-b second-rename-redo HEAD~
1 &&
691 git
mv original two
&&
692 git commit
-m "Rename to two"
695 test_expect_failure 'check handling of differently renamed
file with D
/F conflicts
' '
696 git checkout
-q first-rename-redo^
0 &&
697 test_must_fail git merge
--strategy=recursive second-rename-redo
&&
699 test 3 = "$(git ls-files -u | wc -l)" &&
700 test 1 = "$(git ls-files -u one | wc -l)" &&
701 test 1 = "$(git ls-files -u two | wc -l)" &&
702 test 1 = "$(git ls-files -u original | wc -l)" &&
703 test 0 = "$(git ls-files -o | wc -l)" &&