3 test_description='Merge-recursive merging renames'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10 sed -e "$1" <"$2" >"$2.x" &&
14 test_expect_success 'setup' '
16 a aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
17 b bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
18 c cccccccccccccccccccccccccccccccccccccccccccccccc
19 d dddddddddddddddddddddddddddddddddddddddddddddddd
20 e eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
21 f ffffffffffffffffffffffffffffffffffffffffffffffff
22 g gggggggggggggggggggggggggggggggggggggggggggggggg
23 h hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
24 i iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
25 j jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj
26 k kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
27 l llllllllllllllllllllllllllllllllllllllllllllllll
28 m mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
29 n nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
30 o oooooooooooooooooooooooooooooooooooooooooooooooo
34 A AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
35 B BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
36 C CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
37 D DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
38 E EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
39 F FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
40 G GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
41 H HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
42 I IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
43 J JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
44 K KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK
45 L LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
46 M MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
47 N NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
48 O OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
52 git commit -m "initial has A and M" &&
58 git branch change+rename &&
60 sed -e "/^g /s/.*/g : main changes a line/" <A >A+ &&
62 git commit -a -m "main updates A" &&
64 git checkout yellow &&
66 git commit -a -m "yellow removes M" &&
69 sed -e "/^g /s/.*/g : white changes a line/" <A >B &&
70 sed -e "/^G /s/.*/G : colored branch changes a line/" <M >N &&
72 git update-index --add --remove A B M N &&
73 git commit -m "white renames A->B, M->N" &&
76 sed -e "/^g /s/.*/g : red changes a line/" <A >B &&
77 sed -e "/^G /s/.*/G : colored branch changes a line/" <M >N &&
79 git update-index --add --remove A B M N &&
80 git commit -m "red renames A->B, M->N" &&
83 sed -e "/^g /s/.*/g : blue changes a line/" <A >C &&
84 sed -e "/^G /s/.*/G : colored branch changes a line/" <M >N &&
86 git update-index --add --remove A C M N &&
87 git commit -m "blue renames A->C, M->N" &&
89 git checkout change &&
90 sed -e "/^g /s/.*/g : changed line/" <A >A+ &&
92 git commit -q -a -m "changed" &&
94 git checkout change+rename &&
95 sed -e "/^g /s/.*/g : changed line/" <A >B &&
97 git update-index --add B &&
98 git commit -q -a -m "changed and renamed" &&
103 test_expect_success 'pull renaming branch into unrenaming one' \
106 test_expect_code 1 git pull . white &&
108 git ls-files -u B >b.stages &&
109 test_line_count = 3 b.stages &&
110 git ls-files -s N >n.stages &&
111 test_line_count = 1 n.stages &&
116 git diff --exit-code white N
119 test_expect_success 'pull renaming branch into another renaming one' \
124 test_expect_code 1 git pull . white &&
125 git ls-files -u B >b.stages &&
126 test_line_count = 3 b.stages &&
127 git ls-files -s N >n.stages &&
128 test_line_count = 1 n.stages &&
133 git diff --exit-code white N
136 test_expect_success 'pull unrenaming branch into renaming one' \
140 test_expect_code 1 git pull . main &&
141 git ls-files -u B >b.stages &&
142 test_line_count = 3 b.stages &&
143 git ls-files -s N >n.stages &&
144 test_line_count = 1 n.stages &&
149 git diff --exit-code white N
152 test_expect_success 'pull conflicting renames' \
156 test_expect_code 1 git pull . blue &&
157 git ls-files -u A >a.stages &&
158 test_line_count = 1 a.stages &&
159 git ls-files -u B >b.stages &&
160 test_line_count = 1 b.stages &&
161 git ls-files -u C >c.stages &&
162 test_line_count = 1 c.stages &&
163 git ls-files -s N >n.stages &&
164 test_line_count = 1 n.stages &&
169 git diff --exit-code white N
172 test_expect_success 'interference with untracked working tree file' '
175 echo >A this file should not matter &&
176 test_expect_code 1 git pull . white &&
180 test_expect_success 'interference with untracked working tree file' '
182 git checkout white &&
185 echo >A this file should not matter &&
186 test_expect_code 1 git pull . red &&
190 test_expect_success 'interference with untracked working tree file' '
193 git checkout -f main &&
197 test_path_is_missing M &&
198 git reset --hard anchor
201 test_expect_success 'updated working tree file should prevent the merge' '
204 git checkout -f main &&
207 echo >>M one line addition &&
209 test_expect_code 128 git pull . yellow &&
210 test_cmp M M.saved &&
214 test_expect_success 'updated working tree file should prevent the merge' '
217 git checkout -f main &&
220 echo >>M one line addition &&
222 git update-index M &&
223 test_expect_code 128 git pull . yellow &&
224 test_cmp M M.saved &&
228 test_expect_success 'interference with untracked working tree file' '
231 git checkout -f yellow &&
234 echo >M this file should not matter &&
236 test_path_is_file M &&
241 git reset --hard anchor
244 test_expect_success 'merge of identical changes in a renamed file' '
247 git checkout change+rename &&
249 test-tool chmtime --get -3600 B >old-mtime &&
250 GIT_MERGE_VERBOSITY=3 git merge change >out &&
252 test-tool chmtime --get B >new-mtime &&
253 test_cmp old-mtime new-mtime &&
255 git reset --hard HEAD^ &&
256 git checkout change &&
258 # A will be renamed to B; we check mtimes and file presence
259 test_path_is_missing B &&
260 test-tool chmtime --get -3600 A >old-mtime &&
261 GIT_MERGE_VERBOSITY=3 git merge change+rename >out &&
263 test_path_is_missing A &&
264 test-tool chmtime --get B >new-mtime &&
265 test $(cat old-mtime) -lt $(cat new-mtime)
268 test_expect_success 'setup for rename + d/f conflicts' '
270 git checkout --orphan dir-in-way &&
276 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >sub/file &&
277 echo foo >dir/file-in-the-way &&
279 git commit -m "Common commit" &&
281 echo 11 >>sub/file &&
282 echo more >>dir/file-in-the-way &&
284 git commit -m "Commit to merge, with dir in the way" &&
286 git checkout -b dir-not-in-way &&
287 git reset --soft HEAD^ &&
289 git commit -m "Commit to merge, with dir removed" -- dir sub/file &&
291 git checkout -b renamed-file-has-no-conflicts dir-in-way~1 &&
294 printf "1\n2\n3\n4\n5555\n6\n7\n8\n9\n10\n" >dir &&
296 git commit -m "Independent change" &&
298 git checkout -b renamed-file-has-conflicts dir-in-way~1 &&
300 git mv sub/file dir &&
303 git commit -m "Conflicting change"
306 test_expect_success 'Rename+D/F conflict; renamed file merges + dir not in way' '
308 git checkout -q renamed-file-has-no-conflicts^0 &&
310 git merge --strategy=recursive dir-not-in-way &&
313 test_path_is_file dir &&
314 test_write_lines 1 2 3 4 5555 6 7 8 9 10 11 >expected &&
315 test_cmp expected dir
318 test_expect_success 'Rename+D/F conflict; renamed file merges but dir in way' '
321 git checkout -q renamed-file-has-no-conflicts^0 &&
322 test_must_fail git merge --strategy=recursive dir-in-way >output &&
324 test_i18ngrep "CONFLICT (modify/delete): dir/file-in-the-way" output &&
325 test_i18ngrep "Auto-merging dir" output &&
326 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
328 test_i18ngrep "moving it to dir~HEAD instead" output
330 test_i18ngrep "Adding as dir~HEAD instead" output
333 test 3 -eq "$(git ls-files -u | wc -l)" &&
334 test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
336 test_must_fail git diff --quiet &&
337 test_must_fail git diff --cached --quiet &&
339 test_path_is_file dir/file-in-the-way &&
340 test_path_is_file dir~HEAD &&
341 test_cmp expected dir~HEAD
344 test_expect_success 'Same as previous, but merged other way' '
347 git checkout -q dir-in-way^0 &&
348 test_must_fail git merge --strategy=recursive renamed-file-has-no-conflicts >output 2>errors &&
350 ! grep "error: refusing to lose untracked file at" errors &&
351 test_i18ngrep "CONFLICT (modify/delete): dir/file-in-the-way" output &&
352 test_i18ngrep "Auto-merging dir" output &&
353 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
355 test_i18ngrep "moving it to dir~renamed-file-has-no-conflicts instead" output
357 test_i18ngrep "Adding as dir~renamed-file-has-no-conflicts instead" output
360 test 3 -eq "$(git ls-files -u | wc -l)" &&
361 test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
363 test_must_fail git diff --quiet &&
364 test_must_fail git diff --cached --quiet &&
366 test_path_is_file dir/file-in-the-way &&
367 test_path_is_file dir~renamed-file-has-no-conflicts &&
368 test_cmp expected dir~renamed-file-has-no-conflicts
371 test_expect_success 'Rename+D/F conflict; renamed file cannot merge, dir not in way' '
374 git checkout -q renamed-file-has-conflicts^0 &&
375 test_must_fail git merge --strategy=recursive dir-not-in-way &&
377 test 3 -eq "$(git ls-files -u | wc -l)" &&
378 test 3 -eq "$(git ls-files -u dir | wc -l)" &&
380 test_must_fail git diff --quiet &&
381 test_must_fail git diff --cached --quiet &&
383 test_path_is_file dir &&
384 cat >expected <<-\EOF &&
399 >>>>>>> dir-not-in-way:sub/file
401 test_cmp expected dir
404 test_expect_success 'Rename+D/F conflict; renamed file cannot merge and dir in the way' '
405 modify s/dir-not-in-way/dir-in-way/ expected &&
409 git checkout -q renamed-file-has-conflicts^0 &&
410 test_must_fail git merge --strategy=recursive dir-in-way &&
412 test 5 -eq "$(git ls-files -u | wc -l)" &&
413 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
415 test 3 -eq "$(git ls-files -u dir~HEAD | wc -l)"
417 test 3 -eq "$(git ls-files -u dir | grep -v file-in-the-way | wc -l)"
419 test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
421 test_must_fail git diff --quiet &&
422 test_must_fail git diff --cached --quiet &&
424 test_path_is_file dir/file-in-the-way &&
425 test_path_is_file dir~HEAD &&
426 test_cmp expected dir~HEAD
429 test_expect_success 'Same as previous, but merged other way' '
432 git checkout -q dir-in-way^0 &&
433 test_must_fail git merge --strategy=recursive renamed-file-has-conflicts &&
435 test 5 -eq "$(git ls-files -u | wc -l)" &&
436 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
438 test 3 -eq "$(git ls-files -u dir~renamed-file-has-conflicts | wc -l)"
440 test 3 -eq "$(git ls-files -u dir | grep -v file-in-the-way | wc -l)"
442 test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
444 test_must_fail git diff --quiet &&
445 test_must_fail git diff --cached --quiet &&
447 test_path_is_file dir/file-in-the-way &&
448 test_path_is_file dir~renamed-file-has-conflicts &&
449 cat >expected <<-\EOF &&
460 <<<<<<< HEAD:sub/file
464 >>>>>>> renamed-file-has-conflicts:dir
466 test_cmp expected dir~renamed-file-has-conflicts
469 test_expect_success 'setup both rename source and destination involved in D/F conflict' '
471 git checkout --orphan rename-dest &&
476 echo stuff >one/file &&
478 git commit -m "Common commit" &&
480 git mv one/file destdir &&
481 git commit -m "Renamed to destdir" &&
483 git checkout -b source-conflict HEAD~1 &&
486 touch one destdir/foo &&
488 git commit -m "Conflicts in the way"
491 test_expect_success 'both rename source and destination involved in D/F conflict' '
494 git checkout -q rename-dest^0 &&
495 test_must_fail git merge --strategy=recursive source-conflict &&
497 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
499 test 2 -eq "$(git ls-files -u | wc -l)"
501 test 1 -eq "$(git ls-files -u | wc -l)"
504 test_must_fail git diff --quiet &&
506 test_path_is_file destdir/foo &&
507 test_path_is_file one &&
508 test_path_is_file destdir~HEAD &&
509 test "stuff" = "$(cat destdir~HEAD)"
512 test_expect_success 'setup pair rename to parent of other (D/F conflicts)' '
514 git checkout --orphan rename-two &&
520 echo stuff >one/file &&
521 echo other >two/file &&
523 git commit -m "Common commit" &&
526 git mv two/file one &&
527 git commit -m "Rename two/file -> one" &&
529 git checkout -b rename-one HEAD~1 &&
531 git mv one/file two &&
533 git commit -m "Rename one/file -> two"
536 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
538 test_expect_success 'pair rename to parent of other (D/F conflicts) w/ untracked dir' '
539 git checkout -q rename-one^0 &&
541 test_must_fail git merge --strategy=recursive rename-two &&
543 test 4 -eq "$(git ls-files -u | wc -l)" &&
544 test 2 -eq "$(git ls-files -u one | wc -l)" &&
545 test 2 -eq "$(git ls-files -u two | wc -l)" &&
547 test_must_fail git diff --quiet &&
549 test 3 -eq $(find . | grep -v .git | wc -l) &&
551 test_path_is_file one &&
552 test_path_is_file two &&
553 test "other" = $(cat one) &&
554 test "stuff" = $(cat two)
557 test_expect_success 'pair rename to parent of other (D/F conflicts) w/ untracked dir' '
558 git checkout -q rename-one^0 &&
560 test_must_fail git merge --strategy=recursive rename-two &&
562 test 2 -eq "$(git ls-files -u | wc -l)" &&
563 test 1 -eq "$(git ls-files -u one | wc -l)" &&
564 test 1 -eq "$(git ls-files -u two | wc -l)" &&
566 test_must_fail git diff --quiet &&
568 test 4 -eq $(find . | grep -v .git | wc -l) &&
570 test_path_is_dir one &&
571 test_path_is_file one~rename-two &&
572 test_path_is_file two &&
573 test "other" = $(cat one~rename-two) &&
574 test "stuff" = $(cat two)
578 test_expect_success 'pair rename to parent of other (D/F conflicts) w/ clean start' '
581 test_must_fail git merge --strategy=recursive rename-two &&
583 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
585 test 4 -eq "$(git ls-files -u | wc -l)" &&
586 test 2 -eq "$(git ls-files -u one | wc -l)" &&
587 test 2 -eq "$(git ls-files -u two | wc -l)"
589 test 2 -eq "$(git ls-files -u | wc -l)" &&
590 test 1 -eq "$(git ls-files -u one | wc -l)" &&
591 test 1 -eq "$(git ls-files -u two | wc -l)"
594 test_must_fail git diff --quiet &&
596 test 3 -eq $(find . | grep -v .git | wc -l) &&
598 test_path_is_file one &&
599 test_path_is_file two &&
600 test "other" = $(cat one) &&
601 test "stuff" = $(cat two)
604 test_expect_success 'setup rename of one file to two, with directories in the way' '
606 git checkout --orphan first-rename &&
610 echo stuff >original &&
612 git commit -m "Common commit" &&
617 git mv original one &&
618 git commit -m "Put two/file in the way, rename to one" &&
620 git checkout -b second-rename HEAD~1 &&
624 git mv original two &&
625 git commit -m "Put one/file in the way, rename to two"
628 test_expect_success 'check handling of differently renamed file with D/F conflicts' '
629 git checkout -q first-rename^0 &&
630 test_must_fail git merge --strategy=recursive second-rename &&
632 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
634 test 5 -eq "$(git ls-files -s | wc -l)" &&
635 test 3 -eq "$(git ls-files -u | wc -l)" &&
636 test 1 -eq "$(git ls-files -u one~HEAD | wc -l)" &&
637 test 1 -eq "$(git ls-files -u two~second-rename | wc -l)" &&
638 test 1 -eq "$(git ls-files -u original | wc -l)" &&
639 test 0 -eq "$(git ls-files -o | wc -l)"
641 test 5 -eq "$(git ls-files -s | wc -l)" &&
642 test 3 -eq "$(git ls-files -u | wc -l)" &&
643 test 1 -eq "$(git ls-files -u one | wc -l)" &&
644 test 1 -eq "$(git ls-files -u two | wc -l)" &&
645 test 1 -eq "$(git ls-files -u original | wc -l)" &&
646 test 2 -eq "$(git ls-files -o | wc -l)"
649 test_path_is_file one/file &&
650 test_path_is_file two/file &&
651 test_path_is_file one~HEAD &&
652 test_path_is_file two~second-rename &&
653 test_path_is_missing original
656 test_expect_success 'setup rename one file to two; directories moving out of the way' '
658 git checkout --orphan first-rename-redo &&
662 echo stuff >original &&
664 touch one/file two/file &&
666 git commit -m "Common commit" &&
669 git mv original one &&
670 git commit -m "Rename to one" &&
672 git checkout -b second-rename-redo HEAD~1 &&
674 git mv original two &&
675 git commit -m "Rename to two"
678 test_expect_success 'check handling of differently renamed file with D/F conflicts' '
679 git checkout -q first-rename-redo^0 &&
680 test_must_fail git merge --strategy=recursive second-rename-redo &&
682 test 3 -eq "$(git ls-files -u | wc -l)" &&
683 test 1 -eq "$(git ls-files -u one | wc -l)" &&
684 test 1 -eq "$(git ls-files -u two | wc -l)" &&
685 test 1 -eq "$(git ls-files -u original | wc -l)" &&
686 test 0 -eq "$(git ls-files -o | wc -l)" &&
688 test_path_is_file one &&
689 test_path_is_file two &&
690 test_path_is_missing original
693 test_expect_success 'setup avoid unnecessary update, normal rename' '
695 git checkout --orphan avoid-unnecessary-update-1 &&
699 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >original &&
701 git commit -m "Common commit" &&
703 git mv original rename &&
706 git commit -m "Renamed and modified" &&
708 git checkout -b merge-branch-1 HEAD~1 &&
709 echo "random content" >random-file &&
711 git commit -m "Random, unrelated changes"
714 test_expect_success 'avoid unnecessary update, normal rename' '
715 git checkout -q avoid-unnecessary-update-1^0 &&
716 test-tool chmtime --get -3600 rename >expect &&
717 git merge merge-branch-1 &&
718 test-tool chmtime --get rename >actual &&
719 test_cmp expect actual # "rename" should have stayed intact
722 test_expect_success 'setup to test avoiding unnecessary update, with D/F conflict' '
724 git checkout --orphan avoid-unnecessary-update-2 &&
729 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >df/file &&
731 git commit -m "Common commit" &&
733 git mv df/file temp &&
738 git commit -m "Renamed and modified" &&
740 git checkout -b merge-branch-2 HEAD~1 &&
742 git add unrelated-change &&
743 git commit -m "Only unrelated changes"
746 test_expect_success 'avoid unnecessary update, with D/F conflict' '
747 git checkout -q avoid-unnecessary-update-2^0 &&
748 test-tool chmtime --get -3600 df >expect &&
749 git merge merge-branch-2 &&
750 test-tool chmtime --get df >actual &&
751 test_cmp expect actual # "df" should have stayed intact
754 test_expect_success 'setup avoid unnecessary update, dir->(file,nothing)' '
766 git checkout -b side &&
774 git commit -m "Add a newfile"
777 test_expect_success 'avoid unnecessary update, dir->(file,nothing)' '
778 git checkout -q main^0 &&
779 test-tool chmtime --get -3600 df >expect &&
781 test-tool chmtime --get df >actual &&
782 test_cmp expect actual # "df" should have stayed intact
785 test_expect_success 'setup avoid unnecessary update, modify/delete' '
796 git checkout -b side &&
798 git commit -m "Delete file" &&
803 git commit -m "Modify file"
806 test_expect_success 'avoid unnecessary update, modify/delete' '
807 git checkout -q main^0 &&
808 test-tool chmtime --get -3600 file >expect &&
809 test_must_fail git merge side &&
810 test-tool chmtime --get file >actual &&
811 test_cmp expect actual # "file" should have stayed intact
814 test_expect_success 'setup avoid unnecessary update, rename/add-dest' '
820 printf "1\n2\n3\n4\n5\n6\n7\n8\n" >file &&
824 git checkout -b side &&
827 git commit -m "Add file copy" &&
830 git mv file newfile &&
831 git commit -m "Rename file"
834 test_expect_success 'avoid unnecessary update, rename/add-dest' '
835 git checkout -q main^0 &&
836 test-tool chmtime --get -3600 newfile >expect &&
838 test-tool chmtime --get newfile >actual &&
839 test_cmp expect actual # "file" should have stayed intact
842 test_expect_success 'setup merge of rename + small change' '
844 git checkout --orphan rename-plus-small-change &&
848 echo ORIGINAL >file &&
852 git commit -m Initial &&
853 git checkout -b rename_branch &&
854 git mv file renamed_file &&
855 git commit -m Rename &&
856 git checkout rename-plus-small-change &&
857 echo NEW-VERSION >file &&
858 git commit -a -m Reformat
861 test_expect_success 'merge rename + small change' '
862 git merge rename_branch &&
864 test 1 -eq $(git ls-files -s | wc -l) &&
865 test 0 -eq $(git ls-files -o | wc -l) &&
866 test $(git rev-parse HEAD:renamed_file) = $(git rev-parse HEAD~1:file)
869 test_expect_success 'setup for use of extended merge markers' '
875 printf "1\n2\n3\n4\n5\n6\n7\n8\n" >original_file &&
876 git add original_file &&
879 git checkout -b rename &&
880 echo 9 >>original_file &&
881 git add original_file &&
882 git mv original_file renamed_file &&
886 echo 8.5 >>original_file &&
887 git add original_file &&
891 test_expect_success 'merge main into rename has correct extended markers' '
892 git checkout rename^0 &&
893 test_must_fail git merge -s recursive main^0 &&
895 cat >expected <<-\EOF &&
904 <<<<<<< HEAD:renamed_file
908 >>>>>>> main^0:original_file
910 test_cmp expected renamed_file
913 test_expect_success 'merge rename into main has correct extended markers' '
915 git checkout main^0 &&
916 test_must_fail git merge -s recursive rename^0 &&
918 cat >expected <<-\EOF &&
927 <<<<<<< HEAD:original_file
931 >>>>>>> rename^0:renamed_file
933 test_cmp expected renamed_file
936 test_expect_success 'setup spurious "refusing to lose untracked" message' '
943 printf "1\n2\n3\n4\n5\n6\n7\n8\n" >original_file &&
944 git add irrelevant_file original_file &&
947 git checkout -b rename &&
948 git mv original_file renamed_file &&
952 git rm original_file &&
956 test_expect_success 'no spurious "refusing to lose untracked" message' '
957 git checkout main^0 &&
958 test_must_fail git merge rename^0 2>errors.txt &&
959 ! grep "refusing to lose untracked file" errors.txt
962 test_expect_success 'do not follow renames for empty files' '
963 git checkout -f -b empty-base &&
966 git commit -m base &&
967 echo content >empty1 &&
969 git commit -m fill &&
970 git checkout -b empty-topic HEAD^ &&
971 git mv empty1 empty2 &&
972 git commit -m rename &&
973 test_must_fail git merge empty-base &&
974 test_must_be_empty empty2