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 --no-rebase . white &&
108 test_stdout_line_count = 3 git ls-files -u B &&
109 test_stdout_line_count = 1 git ls-files -s N &&
114 git diff --exit-code white N
117 test_expect_success
'pull renaming branch into another renaming one' \
122 test_expect_code 1 git pull --no-rebase . white &&
123 test_stdout_line_count = 3 git ls-files -u B &&
124 test_stdout_line_count = 1 git ls-files -s N &&
129 git diff --exit-code white N
132 test_expect_success
'pull unrenaming branch into renaming one' \
136 test_expect_code 1 git pull --no-rebase . main &&
137 test_stdout_line_count = 3 git ls-files -u B &&
138 test_stdout_line_count = 1 git ls-files -s N &&
143 git diff --exit-code white N
146 test_expect_success
'pull conflicting renames' \
150 test_expect_code 1 git pull --no-rebase . blue &&
151 test_stdout_line_count = 1 git ls-files -u A &&
152 test_stdout_line_count = 1 git ls-files -u B &&
153 test_stdout_line_count = 1 git ls-files -u C &&
154 test_stdout_line_count = 1 git ls-files -s N &&
159 git diff --exit-code white N
162 test_expect_success
'interference with untracked working tree file' '
165 echo >A this file should not matter &&
166 test_expect_code 1 git pull --no-rebase . white &&
170 test_expect_success
'interference with untracked working tree file' '
172 git checkout white &&
175 echo >A this file should not matter &&
176 test_expect_code 1 git pull --no-rebase . red &&
180 test_expect_success
'interference with untracked working tree file' '
183 git checkout -f main &&
186 git pull --no-rebase . yellow &&
187 test_path_is_missing M &&
188 git reset --hard anchor
191 test_expect_success
'updated working tree file should prevent the merge' '
194 git checkout -f main &&
197 echo >>M one line addition &&
199 test_expect_code 128 git pull . yellow &&
200 test_cmp M M.saved &&
204 test_expect_success
'updated working tree file should prevent the merge' '
207 git checkout -f main &&
210 echo >>M one line addition &&
212 git update-index M &&
213 test_expect_code 128 git pull --no-rebase . yellow &&
214 test_cmp M M.saved &&
218 test_expect_success
'interference with untracked working tree file' '
221 git checkout -f yellow &&
224 echo >M this file should not matter &&
225 git pull --no-rebase . main &&
226 test_path_is_file M &&
231 git reset --hard anchor
234 test_expect_success
'merge of identical changes in a renamed file' '
237 git checkout change+rename &&
239 test-tool chmtime --get -3600 B >old-mtime &&
240 GIT_MERGE_VERBOSITY=3 git merge change >out &&
242 test-tool chmtime --get B >new-mtime &&
243 test_cmp old-mtime new-mtime &&
245 git reset --hard HEAD^ &&
246 git checkout change &&
248 # A will be renamed to B; we check mtimes and file presence
249 test_path_is_missing B &&
250 test-tool chmtime --get -3600 A >old-mtime &&
251 GIT_MERGE_VERBOSITY=3 git merge change+rename >out &&
253 test_path_is_missing A &&
254 test-tool chmtime --get B >new-mtime &&
255 test $(cat old-mtime) -lt $(cat new-mtime)
258 test_expect_success
'setup for rename + d/f conflicts' '
260 git checkout --orphan dir-in-way &&
266 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >sub/file &&
267 echo foo >dir/file-in-the-way &&
269 git commit -m "Common commit" &&
271 echo 11 >>sub/file &&
272 echo more >>dir/file-in-the-way &&
274 git commit -m "Commit to merge, with dir in the way" &&
276 git checkout -b dir-not-in-way &&
277 git reset --soft HEAD^ &&
279 git commit -m "Commit to merge, with dir removed" -- dir sub/file &&
281 git checkout -b renamed-file-has-no-conflicts dir-in-way~1 &&
284 printf "1\n2\n3\n4\n5555\n6\n7\n8\n9\n10\n" >dir &&
286 git commit -m "Independent change" &&
288 git checkout -b renamed-file-has-conflicts dir-in-way~1 &&
290 git mv sub/file dir &&
293 git commit -m "Conflicting change"
296 test_expect_success
'Rename+D/F conflict; renamed file merges + dir not in way' '
298 git checkout -q renamed-file-has-no-conflicts^0 &&
300 git merge --strategy=recursive dir-not-in-way &&
303 test_path_is_file dir &&
304 test_write_lines 1 2 3 4 5555 6 7 8 9 10 11 >expected &&
305 test_cmp expected dir
308 test_expect_success
'Rename+D/F conflict; renamed file merges but dir in way' '
311 git checkout -q renamed-file-has-no-conflicts^0 &&
312 test_must_fail git merge --strategy=recursive dir-in-way >output &&
314 test_i18ngrep "CONFLICT (modify/delete): dir/file-in-the-way" output &&
315 test_i18ngrep "Auto-merging dir" output &&
316 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
318 test_i18ngrep "moving it to dir~HEAD instead" output
320 test_i18ngrep "Adding as dir~HEAD instead" output
323 test_stdout_line_count = 3 git ls-files -u &&
324 test_stdout_line_count = 2 git ls-files -u dir/file-in-the-way &&
326 test_must_fail git diff --quiet &&
327 test_must_fail git diff --cached --quiet &&
329 test_path_is_file dir/file-in-the-way &&
330 test_path_is_file dir~HEAD &&
331 test_cmp expected dir~HEAD
334 test_expect_success
'Same as previous, but merged other way' '
337 git checkout -q dir-in-way^0 &&
338 test_must_fail git merge --strategy=recursive renamed-file-has-no-conflicts >output 2>errors &&
340 ! grep "error: refusing to lose untracked file at" errors &&
341 test_i18ngrep "CONFLICT (modify/delete): dir/file-in-the-way" output &&
342 test_i18ngrep "Auto-merging dir" output &&
343 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
345 test_i18ngrep "moving it to dir~renamed-file-has-no-conflicts instead" output
347 test_i18ngrep "Adding as dir~renamed-file-has-no-conflicts instead" output
350 test_stdout_line_count = 3 git ls-files -u &&
351 test_stdout_line_count = 2 git ls-files -u dir/file-in-the-way &&
353 test_must_fail git diff --quiet &&
354 test_must_fail git diff --cached --quiet &&
356 test_path_is_file dir/file-in-the-way &&
357 test_path_is_file dir~renamed-file-has-no-conflicts &&
358 test_cmp expected dir~renamed-file-has-no-conflicts
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_stdout_line_count = 3 git ls-files -u &&
368 test_stdout_line_count = 3 git ls-files -u dir &&
370 test_must_fail git diff --quiet &&
371 test_must_fail git diff --cached --quiet &&
373 test_path_is_file dir &&
374 cat >expected <<-\EOF &&
389 >>>>>>> dir-not-in-way:sub/file
391 test_cmp expected dir
394 test_expect_success
'Rename+D/F conflict; renamed file cannot merge and dir in the way' '
395 modify s/dir-not-in-way/dir-in-way/ expected &&
399 git checkout -q renamed-file-has-conflicts^0 &&
400 test_must_fail git merge --strategy=recursive dir-in-way &&
402 test_stdout_line_count = 5 git ls-files -u &&
403 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
405 test_stdout_line_count = 3 git ls-files -u dir~HEAD
407 git ls-files -u dir >out &&
408 test 3 -eq $(grep -v file-in-the-way out | wc -l) &&
411 test_stdout_line_count = 2 git ls-files -u dir/file-in-the-way &&
413 test_must_fail git diff --quiet &&
414 test_must_fail git diff --cached --quiet &&
416 test_path_is_file dir/file-in-the-way &&
417 test_path_is_file dir~HEAD &&
418 test_cmp expected dir~HEAD
421 test_expect_success
'Same as previous, but merged other way' '
424 git checkout -q dir-in-way^0 &&
425 test_must_fail git merge --strategy=recursive renamed-file-has-conflicts &&
427 test_stdout_line_count = 5 git ls-files -u &&
428 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
430 test_stdout_line_count = 3 git ls-files -u dir~renamed-file-has-conflicts
432 git ls-files -u dir >out &&
433 test 3 -eq $(grep -v file-in-the-way out | wc -l) &&
436 test_stdout_line_count = 2 git ls-files -u dir/file-in-the-way &&
438 test_must_fail git diff --quiet &&
439 test_must_fail git diff --cached --quiet &&
441 test_path_is_file dir/file-in-the-way &&
442 test_path_is_file dir~renamed-file-has-conflicts &&
443 cat >expected <<-\EOF &&
454 <<<<<<< HEAD:sub/file
458 >>>>>>> renamed-file-has-conflicts:dir
460 test_cmp expected dir~renamed-file-has-conflicts
463 test_expect_success
'setup both rename source and destination involved in D/F conflict' '
465 git checkout --orphan rename-dest &&
470 echo stuff >one/file &&
472 git commit -m "Common commit" &&
474 git mv one/file destdir &&
475 git commit -m "Renamed to destdir" &&
477 git checkout -b source-conflict HEAD~1 &&
480 touch one destdir/foo &&
482 git commit -m "Conflicts in the way"
485 test_expect_success
'both rename source and destination involved in D/F conflict' '
488 git checkout -q rename-dest^0 &&
489 test_must_fail git merge --strategy=recursive source-conflict &&
491 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
493 test_stdout_line_count = 2 git ls-files -u
495 test_stdout_line_count = 1 git ls-files -u
498 test_must_fail git diff --quiet &&
500 test_path_is_file destdir/foo &&
501 test_path_is_file one &&
502 test_path_is_file destdir~HEAD &&
503 test "stuff" = "$(cat destdir~HEAD)"
506 test_expect_success
'setup pair rename to parent of other (D/F conflicts)' '
508 git checkout --orphan rename-two &&
514 echo stuff >one/file &&
515 echo other >two/file &&
517 git commit -m "Common commit" &&
520 git mv two/file one &&
521 git commit -m "Rename two/file -> one" &&
523 git checkout -b rename-one HEAD~1 &&
525 git mv one/file two &&
527 git commit -m "Rename one/file -> two"
530 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
532 test_expect_success
'pair rename to parent of other (D/F conflicts) w/ untracked dir' '
533 git checkout -q rename-one^0 &&
535 test_must_fail git merge --strategy=recursive rename-two &&
537 test_stdout_line_count = 4 git ls-files -u &&
538 test_stdout_line_count = 2 git ls-files -u one &&
539 test_stdout_line_count = 2 git ls-files -u two &&
541 test_must_fail git diff --quiet &&
543 test 3 -eq $(find . | grep -v .git | wc -l) &&
545 test_path_is_file one &&
546 test_path_is_file two &&
547 test "other" = $(cat one) &&
548 test "stuff" = $(cat two)
551 test_expect_success
'pair rename to parent of other (D/F conflicts) w/ untracked dir' '
552 git checkout -q rename-one^0 &&
554 test_must_fail git merge --strategy=recursive rename-two &&
556 test_stdout_line_count = 2 git ls-files -u &&
557 test_stdout_line_count = 1 git ls-files -u one &&
558 test_stdout_line_count = 1 git ls-files -u two &&
560 test_must_fail git diff --quiet &&
562 test 4 -eq $(find . | grep -v .git | wc -l) &&
564 test_path_is_dir one &&
565 test_path_is_file one~rename-two &&
566 test_path_is_file two &&
567 test "other" = $(cat one~rename-two) &&
568 test "stuff" = $(cat two)
572 test_expect_success
'pair rename to parent of other (D/F conflicts) w/ clean start' '
575 test_must_fail git merge --strategy=recursive rename-two &&
577 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
579 test_stdout_line_count = 4 git ls-files -u &&
580 test_stdout_line_count = 2 git ls-files -u one &&
581 test_stdout_line_count = 2 git ls-files -u two
583 test_stdout_line_count = 2 git ls-files -u &&
584 test_stdout_line_count = 1 git ls-files -u one &&
585 test_stdout_line_count = 1 git ls-files -u two
588 test_must_fail git diff --quiet &&
590 test 3 -eq $(find . | grep -v .git | wc -l) &&
592 test_path_is_file one &&
593 test_path_is_file two &&
594 test "other" = $(cat one) &&
595 test "stuff" = $(cat two)
598 test_expect_success
'setup rename of one file to two, with directories in the way' '
600 git checkout --orphan first-rename &&
604 echo stuff >original &&
606 git commit -m "Common commit" &&
611 git mv original one &&
612 git commit -m "Put two/file in the way, rename to one" &&
614 git checkout -b second-rename HEAD~1 &&
618 git mv original two &&
619 git commit -m "Put one/file in the way, rename to two"
622 test_expect_success
'check handling of differently renamed file with D/F conflicts' '
623 git checkout -q first-rename^0 &&
624 test_must_fail git merge --strategy=recursive second-rename &&
626 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
628 test_stdout_line_count = 5 git ls-files -s &&
629 test_stdout_line_count = 3 git ls-files -u &&
630 test_stdout_line_count = 1 git ls-files -u one~HEAD &&
631 test_stdout_line_count = 1 git ls-files -u two~second-rename &&
632 test_stdout_line_count = 1 git ls-files -u original &&
633 test_stdout_line_count = 0 git ls-files -o
635 test_stdout_line_count = 5 git ls-files -s &&
636 test_stdout_line_count = 3 git ls-files -u &&
637 test_stdout_line_count = 1 git ls-files -u one &&
638 test_stdout_line_count = 1 git ls-files -u two &&
639 test_stdout_line_count = 1 git ls-files -u original &&
640 test_stdout_line_count = 2 git ls-files -o
643 test_path_is_file one/file &&
644 test_path_is_file two/file &&
645 test_path_is_file one~HEAD &&
646 test_path_is_file two~second-rename &&
647 test_path_is_missing original
650 test_expect_success
'setup rename one file to two; directories moving out of the way' '
652 git checkout --orphan first-rename-redo &&
656 echo stuff >original &&
658 touch one/file two/file &&
660 git commit -m "Common commit" &&
663 git mv original one &&
664 git commit -m "Rename to one" &&
666 git checkout -b second-rename-redo HEAD~1 &&
668 git mv original two &&
669 git commit -m "Rename to two"
672 test_expect_success
'check handling of differently renamed file with D/F conflicts' '
673 git checkout -q first-rename-redo^0 &&
674 test_must_fail git merge --strategy=recursive second-rename-redo &&
676 test_stdout_line_count = 3 git ls-files -u &&
677 test_stdout_line_count = 1 git ls-files -u one &&
678 test_stdout_line_count = 1 git ls-files -u two &&
679 test_stdout_line_count = 1 git ls-files -u original &&
680 test_stdout_line_count = 0 git ls-files -o &&
682 test_path_is_file one &&
683 test_path_is_file two &&
684 test_path_is_missing original
687 test_expect_success
'setup avoid unnecessary update, normal rename' '
689 git checkout --orphan avoid-unnecessary-update-1 &&
693 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >original &&
695 git commit -m "Common commit" &&
697 git mv original rename &&
700 git commit -m "Renamed and modified" &&
702 git checkout -b merge-branch-1 HEAD~1 &&
703 echo "random content" >random-file &&
705 git commit -m "Random, unrelated changes"
708 test_expect_success
'avoid unnecessary update, normal rename' '
709 git checkout -q avoid-unnecessary-update-1^0 &&
710 test-tool chmtime --get -3600 rename >expect &&
711 git merge merge-branch-1 &&
712 test-tool chmtime --get rename >actual &&
713 test_cmp expect actual # "rename" should have stayed intact
716 test_expect_success
'setup to test avoiding unnecessary update, with D/F conflict' '
718 git checkout --orphan avoid-unnecessary-update-2 &&
723 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >df/file &&
725 git commit -m "Common commit" &&
727 git mv df/file temp &&
732 git commit -m "Renamed and modified" &&
734 git checkout -b merge-branch-2 HEAD~1 &&
736 git add unrelated-change &&
737 git commit -m "Only unrelated changes"
740 test_expect_success
'avoid unnecessary update, with D/F conflict' '
741 git checkout -q avoid-unnecessary-update-2^0 &&
742 test-tool chmtime --get -3600 df >expect &&
743 git merge merge-branch-2 &&
744 test-tool chmtime --get df >actual &&
745 test_cmp expect actual # "df" should have stayed intact
748 test_expect_success
'setup avoid unnecessary update, dir->(file,nothing)' '
760 git checkout -b side &&
768 git commit -m "Add a newfile"
771 test_expect_success
'avoid unnecessary update, dir->(file,nothing)' '
772 git checkout -q main^0 &&
773 test-tool chmtime --get -3600 df >expect &&
775 test-tool chmtime --get df >actual &&
776 test_cmp expect actual # "df" should have stayed intact
779 test_expect_success
'setup avoid unnecessary update, modify/delete' '
790 git checkout -b side &&
792 git commit -m "Delete file" &&
797 git commit -m "Modify file"
800 test_expect_success
'avoid unnecessary update, modify/delete' '
801 git checkout -q main^0 &&
802 test-tool chmtime --get -3600 file >expect &&
803 test_must_fail git merge side &&
804 test-tool chmtime --get file >actual &&
805 test_cmp expect actual # "file" should have stayed intact
808 test_expect_success
'setup avoid unnecessary update, rename/add-dest' '
814 printf "1\n2\n3\n4\n5\n6\n7\n8\n" >file &&
818 git checkout -b side &&
821 git commit -m "Add file copy" &&
824 git mv file newfile &&
825 git commit -m "Rename file"
828 test_expect_success
'avoid unnecessary update, rename/add-dest' '
829 git checkout -q main^0 &&
830 test-tool chmtime --get -3600 newfile >expect &&
832 test-tool chmtime --get newfile >actual &&
833 test_cmp expect actual # "file" should have stayed intact
836 test_expect_success
'setup merge of rename + small change' '
838 git checkout --orphan rename-plus-small-change &&
842 echo ORIGINAL >file &&
846 git commit -m Initial &&
847 git checkout -b rename_branch &&
848 git mv file renamed_file &&
849 git commit -m Rename &&
850 git checkout rename-plus-small-change &&
851 echo NEW-VERSION >file &&
852 git commit -a -m Reformat
855 test_expect_success
'merge rename + small change' '
856 git merge rename_branch &&
858 test_stdout_line_count = 1 git ls-files -s &&
859 test_stdout_line_count = 0 git ls-files -o &&
860 newhash=$(git rev-parse HEAD:renamed_file) &&
861 oldhash=$(git rev-parse HEAD~1:file) &&
862 test $newhash = $oldhash
865 test_expect_success
'setup for use of extended merge markers' '
871 printf "1\n2\n3\n4\n5\n6\n7\n8\n" >original_file &&
872 git add original_file &&
875 git checkout -b rename &&
876 echo 9 >>original_file &&
877 git add original_file &&
878 git mv original_file renamed_file &&
882 echo 8.5 >>original_file &&
883 git add original_file &&
887 test_expect_success
'merge main into rename has correct extended markers' '
888 git checkout rename^0 &&
889 test_must_fail git merge -s recursive main^0 &&
891 cat >expected <<-\EOF &&
900 <<<<<<< HEAD:renamed_file
904 >>>>>>> main^0:original_file
906 test_cmp expected renamed_file
909 test_expect_success
'merge rename into main has correct extended markers' '
911 git checkout main^0 &&
912 test_must_fail git merge -s recursive rename^0 &&
914 cat >expected <<-\EOF &&
923 <<<<<<< HEAD:original_file
927 >>>>>>> rename^0:renamed_file
929 test_cmp expected renamed_file
932 test_expect_success
'setup spurious "refusing to lose untracked" message' '
939 printf "1\n2\n3\n4\n5\n6\n7\n8\n" >original_file &&
940 git add irrelevant_file original_file &&
943 git checkout -b rename &&
944 git mv original_file renamed_file &&
948 git rm original_file &&
952 test_expect_success
'no spurious "refusing to lose untracked" message' '
953 git checkout main^0 &&
954 test_must_fail git merge rename^0 2>errors.txt &&
955 ! grep "refusing to lose untracked file" errors.txt
958 test_expect_success
'do not follow renames for empty files' '
959 git checkout -f -b empty-base &&
962 git commit -m base &&
963 echo content >empty1 &&
965 git commit -m fill &&
966 git checkout -b empty-topic HEAD^ &&
967 git mv empty1 empty2 &&
968 git commit -m rename &&
969 test_must_fail git merge empty-base &&
970 test_must_be_empty empty2