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 test_expect_code 1 git pull . white &&
105 git ls-files -u B >b.stages &&
106 test_line_count = 3 b.stages &&
107 git ls-files -s N >n.stages &&
108 test_line_count = 1 n.stages &&
112 }" B | grep master &&
113 git diff --exit-code white N
116 test_expect_success 'pull renaming branch into another renaming one' \
121 test_expect_code 1 git pull . white &&
122 git ls-files -u B >b.stages &&
123 test_line_count = 3 b.stages &&
124 git ls-files -s N >n.stages &&
125 test_line_count = 1 n.stages &&
130 git diff --exit-code white N
133 test_expect_success 'pull unrenaming branch into renaming one' \
137 test_expect_code 1 git pull . master &&
138 git ls-files -u B >b.stages &&
139 test_line_count = 3 b.stages &&
140 git ls-files -s N >n.stages &&
141 test_line_count = 1 n.stages &&
146 git diff --exit-code white N
149 test_expect_success 'pull conflicting renames' \
153 test_expect_code 1 git pull . blue &&
154 git ls-files -u A >a.stages &&
155 test_line_count = 1 a.stages &&
156 git ls-files -u B >b.stages &&
157 test_line_count = 1 b.stages &&
158 git ls-files -u C >c.stages &&
159 test_line_count = 1 c.stages &&
160 git ls-files -s N >n.stages &&
161 test_line_count = 1 n.stages &&
166 git diff --exit-code white N
169 test_expect_success 'interference with untracked working tree file' '
172 echo >A this file should not matter &&
173 test_expect_code 1 git pull . white &&
177 test_expect_success 'interference with untracked working tree file' '
179 git checkout white &&
182 echo >A this file should not matter &&
183 test_expect_code 1 git pull . red &&
187 test_expect_success 'interference with untracked working tree file' '
190 git checkout -f master &&
194 test_path_is_missing M &&
195 git reset --hard anchor
198 test_expect_success 'updated working tree file should prevent the merge' '
201 git checkout -f master &&
204 echo >>M one line addition &&
206 test_expect_code 128 git pull . yellow &&
207 test_cmp M M.saved &&
211 test_expect_success 'updated working tree file should prevent the merge' '
214 git checkout -f master &&
217 echo >>M one line addition &&
219 git update-index M &&
220 test_expect_code 128 git pull . yellow &&
221 test_cmp M M.saved &&
225 test_expect_success 'interference with untracked working tree file' '
228 git checkout -f yellow &&
231 echo >M this file should not matter &&
233 test_path_is_file M &&
238 git reset --hard anchor
241 test_expect_success 'merge of identical changes in a renamed file' '
244 git checkout change+rename &&
245 GIT_MERGE_VERBOSITY=3 git merge change | test_i18ngrep "^Skipped B" &&
246 git reset --hard HEAD^ &&
247 git checkout change &&
248 GIT_MERGE_VERBOSITY=3 git merge change+rename | test_i18ngrep "^Skipped B"
251 test_expect_success 'setup for rename + d/f conflicts' '
253 git checkout --orphan dir-in-way &&
259 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >sub/file &&
260 echo foo >dir/file-in-the-way &&
262 git commit -m "Common commit" &&
264 echo 11 >>sub/file &&
265 echo more >>dir/file-in-the-way &&
267 git commit -m "Commit to merge, with dir in the way" &&
269 git checkout -b dir-not-in-way &&
270 git reset --soft HEAD^ &&
272 git commit -m "Commit to merge, with dir removed" -- dir sub/file &&
274 git checkout -b renamed-file-has-no-conflicts dir-in-way~1 &&
277 printf "1\n2\n3\n4\n5555\n6\n7\n8\n9\n10\n" >dir &&
279 git commit -m "Independent change" &&
281 git checkout -b renamed-file-has-conflicts dir-in-way~1 &&
283 git mv sub/file dir &&
286 git commit -m "Conflicting change"
289 printf "1\n2\n3\n4\n5555\n6\n7\n8\n9\n10\n11\n" >expected
291 test_expect_success 'Rename+D/F conflict; renamed file merges + dir not in way' '
293 git checkout -q renamed-file-has-no-conflicts^0 &&
294 git merge --strategy=recursive dir-not-in-way &&
297 test_cmp expected dir
300 test_expect_success 'Rename+D/F conflict; renamed file merges but dir in way' '
303 git checkout -q renamed-file-has-no-conflicts^0 &&
304 test_must_fail git merge --strategy=recursive dir-in-way >output &&
306 test_i18ngrep "CONFLICT (modify/delete): dir/file-in-the-way" output &&
307 test_i18ngrep "Auto-merging dir" output &&
308 test_i18ngrep "Adding as dir~HEAD instead" output &&
310 test 3 -eq "$(git ls-files -u | wc -l)" &&
311 test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
313 test_must_fail git diff --quiet &&
314 test_must_fail git diff --cached --quiet &&
316 test -f dir/file-in-the-way &&
318 test_cmp expected dir~HEAD
321 test_expect_success 'Same as previous, but merged other way' '
324 git checkout -q dir-in-way^0 &&
325 test_must_fail git merge --strategy=recursive renamed-file-has-no-conflicts >output 2>errors &&
327 ! grep "error: refusing to lose untracked file at" errors &&
328 test_i18ngrep "CONFLICT (modify/delete): dir/file-in-the-way" output &&
329 test_i18ngrep "Auto-merging dir" output &&
330 test_i18ngrep "Adding as dir~renamed-file-has-no-conflicts instead" output &&
332 test 3 -eq "$(git ls-files -u | wc -l)" &&
333 test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
335 test_must_fail git diff --quiet &&
336 test_must_fail git diff --cached --quiet &&
338 test -f dir/file-in-the-way &&
339 test -f dir~renamed-file-has-no-conflicts &&
340 test_cmp expected dir~renamed-file-has-no-conflicts
343 cat >expected <<\EOF &&
358 >>>>>>> dir-not-in-way:sub/file
361 test_expect_success 'Rename+D/F conflict; renamed file cannot merge, dir not in way' '
364 git checkout -q renamed-file-has-conflicts^0 &&
365 test_must_fail git merge --strategy=recursive dir-not-in-way &&
367 test 3 -eq "$(git ls-files -u | wc -l)" &&
368 test 3 -eq "$(git ls-files -u dir | wc -l)" &&
370 test_must_fail git diff --quiet &&
371 test_must_fail git diff --cached --quiet &&
374 test_cmp expected dir
377 test_expect_success 'Rename+D/F conflict; renamed file cannot merge and dir in the way' '
378 modify s/dir-not-in-way/dir-in-way/ expected &&
382 git checkout -q renamed-file-has-conflicts^0 &&
383 test_must_fail git merge --strategy=recursive dir-in-way &&
385 test 5 -eq "$(git ls-files -u | wc -l)" &&
386 test 3 -eq "$(git ls-files -u dir | grep -v file-in-the-way | wc -l)" &&
387 test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
389 test_must_fail git diff --quiet &&
390 test_must_fail git diff --cached --quiet &&
392 test -f dir/file-in-the-way &&
394 test_cmp expected dir~HEAD
397 cat >expected <<\EOF &&
408 <<<<<<< HEAD:sub/file
412 >>>>>>> renamed-file-has-conflicts:dir
415 test_expect_success 'Same as previous, but merged other way' '
418 git checkout -q dir-in-way^0 &&
419 test_must_fail git merge --strategy=recursive renamed-file-has-conflicts &&
421 test 5 -eq "$(git ls-files -u | wc -l)" &&
422 test 3 -eq "$(git ls-files -u dir | grep -v file-in-the-way | wc -l)" &&
423 test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
425 test_must_fail git diff --quiet &&
426 test_must_fail git diff --cached --quiet &&
428 test -f dir/file-in-the-way &&
429 test -f dir~renamed-file-has-conflicts &&
430 test_cmp expected dir~renamed-file-has-conflicts
433 test_expect_success 'setup both rename source and destination involved in D/F conflict' '
435 git checkout --orphan rename-dest &&
440 echo stuff >one/file &&
442 git commit -m "Common commit" &&
444 git mv one/file destdir &&
445 git commit -m "Renamed to destdir" &&
447 git checkout -b source-conflict HEAD~1 &&
450 touch one destdir/foo &&
452 git commit -m "Conflicts in the way"
455 test_expect_success 'both rename source and destination involved in D/F conflict' '
458 git checkout -q rename-dest^0 &&
459 test_must_fail git merge --strategy=recursive source-conflict &&
461 test 1 -eq "$(git ls-files -u | wc -l)" &&
463 test_must_fail git diff --quiet &&
465 test -f destdir/foo &&
467 test -f destdir~HEAD &&
468 test "stuff" = "$(cat destdir~HEAD)"
471 test_expect_success 'setup pair rename to parent of other (D/F conflicts)' '
473 git checkout --orphan rename-two &&
479 echo stuff >one/file &&
480 echo other >two/file &&
482 git commit -m "Common commit" &&
485 git mv two/file one &&
486 git commit -m "Rename two/file -> one" &&
488 git checkout -b rename-one HEAD~1 &&
490 git mv one/file two &&
492 git commit -m "Rename one/file -> two"
495 test_expect_success 'pair rename to parent of other (D/F conflicts) w/ untracked dir' '
496 git checkout -q rename-one^0 &&
498 test_must_fail git merge --strategy=recursive rename-two &&
500 test 2 -eq "$(git ls-files -u | wc -l)" &&
501 test 1 -eq "$(git ls-files -u one | wc -l)" &&
502 test 1 -eq "$(git ls-files -u two | wc -l)" &&
504 test_must_fail git diff --quiet &&
506 test 4 -eq $(find . | grep -v .git | wc -l) &&
509 test -f one~rename-two &&
511 test "other" = $(cat one~rename-two) &&
512 test "stuff" = $(cat two)
515 test_expect_success 'pair rename to parent of other (D/F conflicts) w/ clean start' '
518 test_must_fail git merge --strategy=recursive rename-two &&
520 test 2 -eq "$(git ls-files -u | wc -l)" &&
521 test 1 -eq "$(git ls-files -u one | wc -l)" &&
522 test 1 -eq "$(git ls-files -u two | wc -l)" &&
524 test_must_fail git diff --quiet &&
526 test 3 -eq $(find . | grep -v .git | wc -l) &&
530 test "other" = $(cat one) &&
531 test "stuff" = $(cat two)
534 test_expect_success 'setup rename of one file to two, with directories in the way' '
536 git checkout --orphan first-rename &&
540 echo stuff >original &&
542 git commit -m "Common commit" &&
547 git mv original one &&
548 git commit -m "Put two/file in the way, rename to one" &&
550 git checkout -b second-rename HEAD~1 &&
554 git mv original two &&
555 git commit -m "Put one/file in the way, rename to two"
558 test_expect_success 'check handling of differently renamed file with D/F conflicts' '
559 git checkout -q first-rename^0 &&
560 test_must_fail git merge --strategy=recursive second-rename &&
562 test 5 -eq "$(git ls-files -s | wc -l)" &&
563 test 3 -eq "$(git ls-files -u | wc -l)" &&
564 test 1 -eq "$(git ls-files -u one | wc -l)" &&
565 test 1 -eq "$(git ls-files -u two | wc -l)" &&
566 test 1 -eq "$(git ls-files -u original | wc -l)" &&
567 test 2 -eq "$(git ls-files -o | wc -l)" &&
572 test -f two~second-rename &&
576 test_expect_success 'setup rename one file to two; directories moving out of the way' '
578 git checkout --orphan first-rename-redo &&
582 echo stuff >original &&
584 touch one/file two/file &&
586 git commit -m "Common commit" &&
589 git mv original one &&
590 git commit -m "Rename to one" &&
592 git checkout -b second-rename-redo HEAD~1 &&
594 git mv original two &&
595 git commit -m "Rename to two"
598 test_expect_success 'check handling of differently renamed file with D/F conflicts' '
599 git checkout -q first-rename-redo^0 &&
600 test_must_fail git merge --strategy=recursive second-rename-redo &&
602 test 3 -eq "$(git ls-files -u | wc -l)" &&
603 test 1 -eq "$(git ls-files -u one | wc -l)" &&
604 test 1 -eq "$(git ls-files -u two | wc -l)" &&
605 test 1 -eq "$(git ls-files -u original | wc -l)" &&
606 test 0 -eq "$(git ls-files -o | wc -l)" &&
613 test_expect_success 'setup avoid unnecessary update, normal rename' '
615 git checkout --orphan avoid-unnecessary-update-1 &&
619 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >original &&
621 git commit -m "Common commit" &&
623 git mv original rename &&
626 git commit -m "Renamed and modified" &&
628 git checkout -b merge-branch-1 HEAD~1 &&
629 echo "random content" >random-file &&
631 git commit -m "Random, unrelated changes"
634 test_expect_success 'avoid unnecessary update, normal rename' '
635 git checkout -q avoid-unnecessary-update-1^0 &&
636 test-chmtime =1000000000 rename &&
637 test-chmtime -v +0 rename >expect &&
638 git merge merge-branch-1 &&
639 test-chmtime -v +0 rename >actual &&
640 test_cmp expect actual # "rename" should have stayed intact
643 test_expect_success 'setup to test avoiding unnecessary update, with D/F conflict' '
645 git checkout --orphan avoid-unnecessary-update-2 &&
650 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >df/file &&
652 git commit -m "Common commit" &&
654 git mv df/file temp &&
659 git commit -m "Renamed and modified" &&
661 git checkout -b merge-branch-2 HEAD~1 &&
663 git add unrelated-change &&
664 git commit -m "Only unrelated changes"
667 test_expect_success 'avoid unnecessary update, with D/F conflict' '
668 git checkout -q avoid-unnecessary-update-2^0 &&
669 test-chmtime =1000000000 df &&
670 test-chmtime -v +0 df >expect &&
671 git merge merge-branch-2 &&
672 test-chmtime -v +0 df >actual &&
673 test_cmp expect actual # "df" should have stayed intact
676 test_expect_success 'setup avoid unnecessary update, dir->(file,nothing)' '
688 git checkout -b side &&
692 git checkout master &&
696 git commit -m "Add a newfile"
699 test_expect_success 'avoid unnecessary update, dir->(file,nothing)' '
700 git checkout -q master^0 &&
701 test-chmtime =1000000000 df &&
702 test-chmtime -v +0 df >expect &&
704 test-chmtime -v +0 df >actual &&
705 test_cmp expect actual # "df" should have stayed intact
708 test_expect_success 'setup avoid unnecessary update, modify/delete' '
719 git checkout -b side &&
721 git commit -m "Delete file" &&
723 git checkout master &&
726 git commit -m "Modify file"
729 test_expect_success 'avoid unnecessary update, modify/delete' '
730 git checkout -q master^0 &&
731 test-chmtime =1000000000 file &&
732 test-chmtime -v +0 file >expect &&
733 test_must_fail git merge side &&
734 test-chmtime -v +0 file >actual &&
735 test_cmp expect actual # "file" should have stayed intact
738 test_expect_success 'setup avoid unnecessary update, rename/add-dest' '
744 printf "1\n2\n3\n4\n5\n6\n7\n8\n" >file &&
748 git checkout -b side &&
751 git commit -m "Add file copy" &&
753 git checkout master &&
754 git mv file newfile &&
755 git commit -m "Rename file"
758 test_expect_success 'avoid unnecessary update, rename/add-dest' '
759 git checkout -q master^0 &&
760 test-chmtime =1000000000 newfile &&
761 test-chmtime -v +0 newfile >expect &&
763 test-chmtime -v +0 newfile >actual &&
764 test_cmp expect actual # "file" should have stayed intact
767 test_expect_success 'setup merge of rename + small change' '
769 git checkout --orphan rename-plus-small-change &&
773 echo ORIGINAL >file &&
777 git commit -m Initial &&
778 git checkout -b rename_branch &&
779 git mv file renamed_file &&
780 git commit -m Rename &&
781 git checkout rename-plus-small-change &&
782 echo NEW-VERSION >file &&
783 git commit -a -m Reformat
786 test_expect_success 'merge rename + small change' '
787 git merge rename_branch &&
789 test 1 -eq $(git ls-files -s | wc -l) &&
790 test 0 -eq $(git ls-files -o | wc -l) &&
791 test $(git rev-parse HEAD:renamed_file) = $(git rev-parse HEAD~1:file)
794 test_expect_success 'setup for use of extended merge markers' '
800 printf "1\n2\n3\n4\n5\n6\n7\n8\n" >original_file &&
801 git add original_file &&
804 git checkout -b rename &&
805 echo 9 >>original_file &&
806 git add original_file &&
807 git mv original_file renamed_file &&
810 git checkout master &&
811 echo 8.5 >>original_file &&
812 git add original_file &&
816 cat >expected <<\EOF &&
825 <<<<<<< HEAD:renamed_file
829 >>>>>>> master^0:original_file
832 test_expect_success 'merge master into rename has correct extended markers' '
833 git checkout rename^0 &&
834 test_must_fail git merge -s recursive master^0 &&
835 test_cmp expected renamed_file
838 cat >expected <<\EOF &&
847 <<<<<<< HEAD:original_file
851 >>>>>>> rename^0:renamed_file
854 test_expect_success 'merge rename into master has correct extended markers' '
856 git checkout master^0 &&
857 test_must_fail git merge -s recursive rename^0 &&
858 test_cmp expected renamed_file
861 test_expect_success 'setup spurious "refusing to lose untracked" message' '
868 printf "1\n2\n3\n4\n5\n6\n7\n8\n" >original_file &&
869 git add irrelevant_file original_file &&
872 git checkout -b rename &&
873 git mv original_file renamed_file &&
876 git checkout master &&
877 git rm original_file &&
881 test_expect_success 'no spurious "refusing to lose untracked" message' '
882 git checkout master^0 &&
883 test_must_fail git merge rename^0 2>errors.txt &&
884 ! grep "refusing to lose untracked file" errors.txt
887 test_expect_success 'do not follow renames for empty files' '
888 git checkout -f -b empty-base &&
891 git commit -m base &&
892 echo content >empty1 &&
894 git commit -m fill &&
895 git checkout -b empty-topic HEAD^ &&
896 git mv empty1 empty2 &&
897 git commit -m rename &&
898 test_must_fail git merge empty-base &&
900 test_cmp expect empty2