3 test_description
='Merge-recursive merging renames'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7 TEST_PASSES_SANITIZE_LEAK
=true
11 sed -e "$1" <"$2" >"$2.x" &&
15 test_expect_success
'setup' '
17 a aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
18 b bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
19 c cccccccccccccccccccccccccccccccccccccccccccccccc
20 d dddddddddddddddddddddddddddddddddddddddddddddddd
21 e eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
22 f ffffffffffffffffffffffffffffffffffffffffffffffff
23 g gggggggggggggggggggggggggggggggggggggggggggggggg
24 h hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
25 i iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
26 j jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj
27 k kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
28 l llllllllllllllllllllllllllllllllllllllllllllllll
29 m mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
30 n nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
31 o oooooooooooooooooooooooooooooooooooooooooooooooo
35 A AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
36 B BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
37 C CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
38 D DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
39 E EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
40 F FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
41 G GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
42 H HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
43 I IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
44 J JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
45 K KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK
46 L LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
47 M MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
48 N NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
49 O OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
53 git commit -m "initial has A and M" &&
59 git branch change+rename &&
61 sed -e "/^g /s/.*/g : main changes a line/" <A >A+ &&
63 git commit -a -m "main updates A" &&
65 git checkout yellow &&
67 git commit -a -m "yellow removes M" &&
70 sed -e "/^g /s/.*/g : white changes a line/" <A >B &&
71 sed -e "/^G /s/.*/G : colored branch changes a line/" <M >N &&
73 git update-index --add --remove A B M N &&
74 git commit -m "white renames A->B, M->N" &&
77 sed -e "/^g /s/.*/g : red changes a line/" <A >B &&
78 sed -e "/^G /s/.*/G : colored branch changes a line/" <M >N &&
80 git update-index --add --remove A B M N &&
81 git commit -m "red renames A->B, M->N" &&
84 sed -e "/^g /s/.*/g : blue changes a line/" <A >C &&
85 sed -e "/^G /s/.*/G : colored branch changes a line/" <M >N &&
87 git update-index --add --remove A C M N &&
88 git commit -m "blue renames A->C, M->N" &&
90 git checkout change &&
91 sed -e "/^g /s/.*/g : changed line/" <A >A+ &&
93 git commit -q -a -m "changed" &&
95 git checkout change+rename &&
96 sed -e "/^g /s/.*/g : changed line/" <A >B &&
98 git update-index --add B &&
99 git commit -q -a -m "changed and renamed" &&
104 test_expect_success
'pull renaming branch into unrenaming one' \
107 test_expect_code 1 git pull --no-rebase . white &&
109 test_stdout_line_count = 3 git ls-files -u B &&
110 test_stdout_line_count = 1 git ls-files -s N &&
115 git diff --exit-code white N
118 test_expect_success
'pull renaming branch into another renaming one' \
123 test_expect_code 1 git pull --no-rebase . white &&
124 test_stdout_line_count = 3 git ls-files -u B &&
125 test_stdout_line_count = 1 git ls-files -s N &&
130 git diff --exit-code white N
133 test_expect_success
'pull unrenaming branch into renaming one' \
137 test_expect_code 1 git pull --no-rebase . main &&
138 test_stdout_line_count = 3 git ls-files -u B &&
139 test_stdout_line_count = 1 git ls-files -s N &&
144 git diff --exit-code white N
147 test_expect_success
'pull conflicting renames' \
151 test_expect_code 1 git pull --no-rebase . blue &&
152 test_stdout_line_count = 1 git ls-files -u A &&
153 test_stdout_line_count = 1 git ls-files -u B &&
154 test_stdout_line_count = 1 git ls-files -u C &&
155 test_stdout_line_count = 1 git ls-files -s N &&
160 git diff --exit-code white N
163 test_expect_success
'interference with untracked working tree file' '
166 echo >A this file should not matter &&
167 test_expect_code 1 git pull --no-rebase . white &&
171 test_expect_success
'interference with untracked working tree file' '
173 git checkout white &&
176 echo >A this file should not matter &&
177 test_expect_code 1 git pull --no-rebase . red &&
181 test_expect_success
'interference with untracked working tree file' '
184 git checkout -f main &&
187 git pull --no-rebase . yellow &&
188 test_path_is_missing M &&
189 git reset --hard anchor
192 test_expect_success
'updated working tree file should prevent the merge' '
195 git checkout -f main &&
198 echo >>M one line addition &&
200 test_expect_code 128 git pull . yellow &&
201 test_cmp M M.saved &&
205 test_expect_success
'updated working tree file should prevent the merge' '
208 git checkout -f main &&
211 echo >>M one line addition &&
213 git update-index M &&
214 test_expect_code 2 git pull --no-rebase . yellow &&
215 test_cmp M M.saved &&
219 test_expect_success
'interference with untracked working tree file' '
222 git checkout -f yellow &&
225 echo >M this file should not matter &&
226 git pull --no-rebase . main &&
227 test_path_is_file M &&
232 git reset --hard anchor
235 test_expect_success
'merge of identical changes in a renamed file' '
238 git checkout change+rename &&
240 test-tool chmtime --get -3600 B >old-mtime &&
241 GIT_MERGE_VERBOSITY=3 git merge change >out &&
243 test-tool chmtime --get B >new-mtime &&
244 test_cmp old-mtime new-mtime &&
246 git reset --hard HEAD^ &&
247 git checkout change &&
249 # A will be renamed to B; we check mtimes and file presence
250 test_path_is_missing B &&
251 test-tool chmtime --get -3600 A >old-mtime &&
252 GIT_MERGE_VERBOSITY=3 git merge change+rename >out &&
254 test_path_is_missing A &&
255 test-tool chmtime --get B >new-mtime &&
256 test $(cat old-mtime) -lt $(cat new-mtime)
259 test_expect_success
'setup for rename + d/f conflicts' '
261 git checkout --orphan dir-in-way &&
267 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >sub/file &&
268 echo foo >dir/file-in-the-way &&
270 git commit -m "Common commit" &&
272 echo 11 >>sub/file &&
273 echo more >>dir/file-in-the-way &&
275 git commit -m "Commit to merge, with dir in the way" &&
277 git checkout -b dir-not-in-way &&
278 git reset --soft HEAD^ &&
280 git commit -m "Commit to merge, with dir removed" -- dir sub/file &&
282 git checkout -b renamed-file-has-no-conflicts dir-in-way~1 &&
285 printf "1\n2\n3\n4\n5555\n6\n7\n8\n9\n10\n" >dir &&
287 git commit -m "Independent change" &&
289 git checkout -b renamed-file-has-conflicts dir-in-way~1 &&
291 git mv sub/file dir &&
294 git commit -m "Conflicting change"
297 test_expect_success
'Rename+D/F conflict; renamed file merges + dir not in way' '
299 git checkout -q renamed-file-has-no-conflicts^0 &&
301 git merge --strategy=recursive dir-not-in-way &&
304 test_path_is_file dir &&
305 test_write_lines 1 2 3 4 5555 6 7 8 9 10 11 >expected &&
306 test_cmp expected dir
309 test_expect_success
'Rename+D/F conflict; renamed file merges but dir in way' '
312 git checkout -q renamed-file-has-no-conflicts^0 &&
313 test_must_fail git merge --strategy=recursive dir-in-way >output &&
315 test_grep "CONFLICT (modify/delete): dir/file-in-the-way" output &&
316 test_grep "Auto-merging dir" output &&
317 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
319 test_grep "moving it to dir~HEAD instead" output
321 test_grep "Adding as dir~HEAD instead" output
324 test_stdout_line_count = 3 git ls-files -u &&
325 test_stdout_line_count = 2 git ls-files -u dir/file-in-the-way &&
327 test_must_fail git diff --quiet &&
328 test_must_fail git diff --cached --quiet &&
330 test_path_is_file dir/file-in-the-way &&
331 test_path_is_file dir~HEAD &&
332 test_cmp expected dir~HEAD
335 test_expect_success
'Same as previous, but merged other way' '
338 git checkout -q dir-in-way^0 &&
339 test_must_fail git merge --strategy=recursive renamed-file-has-no-conflicts >output 2>errors &&
341 ! grep "error: refusing to lose untracked file at" errors &&
342 test_grep "CONFLICT (modify/delete): dir/file-in-the-way" output &&
343 test_grep "Auto-merging dir" output &&
344 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
346 test_grep "moving it to dir~renamed-file-has-no-conflicts instead" output
348 test_grep "Adding as dir~renamed-file-has-no-conflicts instead" output
351 test_stdout_line_count = 3 git ls-files -u &&
352 test_stdout_line_count = 2 git ls-files -u dir/file-in-the-way &&
354 test_must_fail git diff --quiet &&
355 test_must_fail git diff --cached --quiet &&
357 test_path_is_file dir/file-in-the-way &&
358 test_path_is_file dir~renamed-file-has-no-conflicts &&
359 test_cmp expected dir~renamed-file-has-no-conflicts
362 test_expect_success
'Rename+D/F conflict; renamed file cannot merge, dir not in way' '
365 git checkout -q renamed-file-has-conflicts^0 &&
366 test_must_fail git merge --strategy=recursive dir-not-in-way &&
368 test_stdout_line_count = 3 git ls-files -u &&
369 test_stdout_line_count = 3 git ls-files -u dir &&
371 test_must_fail git diff --quiet &&
372 test_must_fail git diff --cached --quiet &&
374 test_path_is_file dir &&
375 cat >expected <<-\EOF &&
390 >>>>>>> dir-not-in-way:sub/file
392 test_cmp expected dir
395 test_expect_success
'Rename+D/F conflict; renamed file cannot merge and dir in the way' '
396 modify s/dir-not-in-way/dir-in-way/ expected &&
400 git checkout -q renamed-file-has-conflicts^0 &&
401 test_must_fail git merge --strategy=recursive dir-in-way &&
403 test_stdout_line_count = 5 git ls-files -u &&
404 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
406 test_stdout_line_count = 3 git ls-files -u dir~HEAD
408 git ls-files -u dir >out &&
409 test 3 -eq $(grep -v file-in-the-way out | wc -l) &&
412 test_stdout_line_count = 2 git ls-files -u dir/file-in-the-way &&
414 test_must_fail git diff --quiet &&
415 test_must_fail git diff --cached --quiet &&
417 test_path_is_file dir/file-in-the-way &&
418 test_path_is_file dir~HEAD &&
419 test_cmp expected dir~HEAD
422 test_expect_success
'Same as previous, but merged other way' '
425 git checkout -q dir-in-way^0 &&
426 test_must_fail git merge --strategy=recursive renamed-file-has-conflicts &&
428 test_stdout_line_count = 5 git ls-files -u &&
429 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
431 test_stdout_line_count = 3 git ls-files -u dir~renamed-file-has-conflicts
433 git ls-files -u dir >out &&
434 test 3 -eq $(grep -v file-in-the-way out | wc -l) &&
437 test_stdout_line_count = 2 git ls-files -u dir/file-in-the-way &&
439 test_must_fail git diff --quiet &&
440 test_must_fail git diff --cached --quiet &&
442 test_path_is_file dir/file-in-the-way &&
443 test_path_is_file dir~renamed-file-has-conflicts &&
444 cat >expected <<-\EOF &&
455 <<<<<<< HEAD:sub/file
459 >>>>>>> renamed-file-has-conflicts:dir
461 test_cmp expected dir~renamed-file-has-conflicts
464 test_expect_success
'setup both rename source and destination involved in D/F conflict' '
466 git checkout --orphan rename-dest &&
471 echo stuff >one/file &&
473 git commit -m "Common commit" &&
475 git mv one/file destdir &&
476 git commit -m "Renamed to destdir" &&
478 git checkout -b source-conflict HEAD~1 &&
481 touch one destdir/foo &&
483 git commit -m "Conflicts in the way"
486 test_expect_success
'both rename source and destination involved in D/F conflict' '
489 git checkout -q rename-dest^0 &&
490 test_must_fail git merge --strategy=recursive source-conflict &&
492 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
494 test_stdout_line_count = 2 git ls-files -u
496 test_stdout_line_count = 1 git ls-files -u
499 test_must_fail git diff --quiet &&
501 test_path_is_file destdir/foo &&
502 test_path_is_file one &&
503 test_path_is_file destdir~HEAD &&
504 test "stuff" = "$(cat destdir~HEAD)"
507 test_expect_success
'setup pair rename to parent of other (D/F conflicts)' '
509 git checkout --orphan rename-two &&
515 echo stuff >one/file &&
516 echo other >two/file &&
518 git commit -m "Common commit" &&
521 git mv two/file one &&
522 git commit -m "Rename two/file -> one" &&
524 git checkout -b rename-one HEAD~1 &&
526 git mv one/file two &&
528 git commit -m "Rename one/file -> two"
531 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
533 test_expect_success
'pair rename to parent of other (D/F conflicts) w/ untracked dir' '
534 git checkout -q rename-one^0 &&
536 test_must_fail git merge --strategy=recursive rename-two &&
538 test_stdout_line_count = 4 git ls-files -u &&
539 test_stdout_line_count = 2 git ls-files -u one &&
540 test_stdout_line_count = 2 git ls-files -u two &&
542 test_must_fail git diff --quiet &&
544 test 3 -eq $(find . | grep -v .git | wc -l) &&
546 test_path_is_file one &&
547 test_path_is_file two &&
548 test "other" = $(cat one) &&
549 test "stuff" = $(cat two)
552 test_expect_success
'pair rename to parent of other (D/F conflicts) w/ untracked dir' '
553 git checkout -q rename-one^0 &&
555 test_must_fail git merge --strategy=recursive rename-two &&
557 test_stdout_line_count = 2 git ls-files -u &&
558 test_stdout_line_count = 1 git ls-files -u one &&
559 test_stdout_line_count = 1 git ls-files -u two &&
561 test_must_fail git diff --quiet &&
563 test 4 -eq $(find . | grep -v .git | wc -l) &&
565 test_path_is_dir one &&
566 test_path_is_file one~rename-two &&
567 test_path_is_file two &&
568 test "other" = $(cat one~rename-two) &&
569 test "stuff" = $(cat two)
573 test_expect_success
'pair rename to parent of other (D/F conflicts) w/ clean start' '
576 test_must_fail git merge --strategy=recursive rename-two &&
578 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
580 test_stdout_line_count = 4 git ls-files -u &&
581 test_stdout_line_count = 2 git ls-files -u one &&
582 test_stdout_line_count = 2 git ls-files -u two
584 test_stdout_line_count = 2 git ls-files -u &&
585 test_stdout_line_count = 1 git ls-files -u one &&
586 test_stdout_line_count = 1 git ls-files -u two
589 test_must_fail git diff --quiet &&
591 test 3 -eq $(find . | grep -v .git | wc -l) &&
593 test_path_is_file one &&
594 test_path_is_file two &&
595 test "other" = $(cat one) &&
596 test "stuff" = $(cat two)
599 test_expect_success
'setup rename of one file to two, with directories in the way' '
601 git checkout --orphan first-rename &&
605 echo stuff >original &&
607 git commit -m "Common commit" &&
612 git mv original one &&
613 git commit -m "Put two/file in the way, rename to one" &&
615 git checkout -b second-rename HEAD~1 &&
619 git mv original two &&
620 git commit -m "Put one/file in the way, rename to two"
623 test_expect_success
'check handling of differently renamed file with D/F conflicts' '
624 git checkout -q first-rename^0 &&
625 test_must_fail git merge --strategy=recursive second-rename &&
627 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
629 test_stdout_line_count = 5 git ls-files -s &&
630 test_stdout_line_count = 3 git ls-files -u &&
631 test_stdout_line_count = 1 git ls-files -u one~HEAD &&
632 test_stdout_line_count = 1 git ls-files -u two~second-rename &&
633 test_stdout_line_count = 1 git ls-files -u original &&
634 test_stdout_line_count = 0 git ls-files -o
636 test_stdout_line_count = 5 git ls-files -s &&
637 test_stdout_line_count = 3 git ls-files -u &&
638 test_stdout_line_count = 1 git ls-files -u one &&
639 test_stdout_line_count = 1 git ls-files -u two &&
640 test_stdout_line_count = 1 git ls-files -u original &&
641 test_stdout_line_count = 2 git ls-files -o
644 test_path_is_file one/file &&
645 test_path_is_file two/file &&
646 test_path_is_file one~HEAD &&
647 test_path_is_file two~second-rename &&
648 test_path_is_missing original
651 test_expect_success
'setup rename one file to two; directories moving out of the way' '
653 git checkout --orphan first-rename-redo &&
657 echo stuff >original &&
659 touch one/file two/file &&
661 git commit -m "Common commit" &&
664 git mv original one &&
665 git commit -m "Rename to one" &&
667 git checkout -b second-rename-redo HEAD~1 &&
669 git mv original two &&
670 git commit -m "Rename to two"
673 test_expect_success
'check handling of differently renamed file with D/F conflicts' '
674 git checkout -q first-rename-redo^0 &&
675 test_must_fail git merge --strategy=recursive second-rename-redo &&
677 test_stdout_line_count = 3 git ls-files -u &&
678 test_stdout_line_count = 1 git ls-files -u one &&
679 test_stdout_line_count = 1 git ls-files -u two &&
680 test_stdout_line_count = 1 git ls-files -u original &&
681 test_stdout_line_count = 0 git ls-files -o &&
683 test_path_is_file one &&
684 test_path_is_file two &&
685 test_path_is_missing original
688 test_expect_success
'setup avoid unnecessary update, normal rename' '
690 git checkout --orphan avoid-unnecessary-update-1 &&
694 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >original &&
696 git commit -m "Common commit" &&
698 git mv original rename &&
701 git commit -m "Renamed and modified" &&
703 git checkout -b merge-branch-1 HEAD~1 &&
704 echo "random content" >random-file &&
706 git commit -m "Random, unrelated changes"
709 test_expect_success
'avoid unnecessary update, normal rename' '
710 git checkout -q avoid-unnecessary-update-1^0 &&
711 test-tool chmtime --get -3600 rename >expect &&
712 git merge merge-branch-1 &&
713 test-tool chmtime --get rename >actual &&
714 test_cmp expect actual # "rename" should have stayed intact
717 test_expect_success
'setup to test avoiding unnecessary update, with D/F conflict' '
719 git checkout --orphan avoid-unnecessary-update-2 &&
724 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >df/file &&
726 git commit -m "Common commit" &&
728 git mv df/file temp &&
733 git commit -m "Renamed and modified" &&
735 git checkout -b merge-branch-2 HEAD~1 &&
737 git add unrelated-change &&
738 git commit -m "Only unrelated changes"
741 test_expect_success
'avoid unnecessary update, with D/F conflict' '
742 git checkout -q avoid-unnecessary-update-2^0 &&
743 test-tool chmtime --get -3600 df >expect &&
744 git merge merge-branch-2 &&
745 test-tool chmtime --get df >actual &&
746 test_cmp expect actual # "df" should have stayed intact
749 test_expect_success
'setup avoid unnecessary update, dir->(file,nothing)' '
761 git checkout -b side &&
769 git commit -m "Add a newfile"
772 test_expect_success
'avoid unnecessary update, dir->(file,nothing)' '
773 git checkout -q main^0 &&
774 test-tool chmtime --get -3600 df >expect &&
776 test-tool chmtime --get df >actual &&
777 test_cmp expect actual # "df" should have stayed intact
780 test_expect_success
'setup avoid unnecessary update, modify/delete' '
791 git checkout -b side &&
793 git commit -m "Delete file" &&
798 git commit -m "Modify file"
801 test_expect_success
'avoid unnecessary update, modify/delete' '
802 git checkout -q main^0 &&
803 test-tool chmtime --get -3600 file >expect &&
804 test_must_fail git merge side &&
805 test-tool chmtime --get file >actual &&
806 test_cmp expect actual # "file" should have stayed intact
809 test_expect_success
'setup avoid unnecessary update, rename/add-dest' '
815 printf "1\n2\n3\n4\n5\n6\n7\n8\n" >file &&
819 git checkout -b side &&
822 git commit -m "Add file copy" &&
825 git mv file newfile &&
826 git commit -m "Rename file"
829 test_expect_success
'avoid unnecessary update, rename/add-dest' '
830 git checkout -q main^0 &&
831 test-tool chmtime --get -3600 newfile >expect &&
833 test-tool chmtime --get newfile >actual &&
834 test_cmp expect actual # "file" should have stayed intact
837 test_expect_success
'setup merge of rename + small change' '
839 git checkout --orphan rename-plus-small-change &&
843 echo ORIGINAL >file &&
847 git commit -m Initial &&
848 git checkout -b rename_branch &&
849 git mv file renamed_file &&
850 git commit -m Rename &&
851 git checkout rename-plus-small-change &&
852 echo NEW-VERSION >file &&
853 git commit -a -m Reformat
856 test_expect_success
'merge rename + small change' '
857 git merge rename_branch &&
859 test_stdout_line_count = 1 git ls-files -s &&
860 test_stdout_line_count = 0 git ls-files -o &&
861 newhash=$(git rev-parse HEAD:renamed_file) &&
862 oldhash=$(git rev-parse HEAD~1:file) &&
863 test $newhash = $oldhash
866 test_expect_success
'setup for use of extended merge markers' '
872 printf "1\n2\n3\n4\n5\n6\n7\n8\n" >original_file &&
873 git add original_file &&
876 git checkout -b rename &&
877 echo 9 >>original_file &&
878 git add original_file &&
879 git mv original_file renamed_file &&
883 echo 8.5 >>original_file &&
884 git add original_file &&
888 test_expect_success
'merge main into rename has correct extended markers' '
889 git checkout rename^0 &&
890 test_must_fail git merge -s recursive main^0 &&
892 cat >expected <<-\EOF &&
901 <<<<<<< HEAD:renamed_file
905 >>>>>>> main^0:original_file
907 test_cmp expected renamed_file
910 test_expect_success
'merge rename into main has correct extended markers' '
912 git checkout main^0 &&
913 test_must_fail git merge -s recursive rename^0 &&
915 cat >expected <<-\EOF &&
924 <<<<<<< HEAD:original_file
928 >>>>>>> rename^0:renamed_file
930 test_cmp expected renamed_file
933 test_expect_success
'setup spurious "refusing to lose untracked" message' '
940 printf "1\n2\n3\n4\n5\n6\n7\n8\n" >original_file &&
941 git add irrelevant_file original_file &&
944 git checkout -b rename &&
945 git mv original_file renamed_file &&
949 git rm original_file &&
953 test_expect_success
'no spurious "refusing to lose untracked" message' '
954 git checkout main^0 &&
955 test_must_fail git merge rename^0 2>errors.txt &&
956 ! grep "refusing to lose untracked file" errors.txt
959 test_expect_success
'do not follow renames for empty files' '
960 git checkout -f -b empty-base &&
963 git commit -m base &&
964 echo content >empty1 &&
966 git commit -m fill &&
967 git checkout -b empty-topic HEAD^ &&
968 git mv empty1 empty2 &&
969 git commit -m rename &&
970 test_must_fail git merge empty-base &&
971 test_must_be_empty empty2