3 test_description='Merge-recursive merging renames'
7 sed -e "$1" <"$2" >"$2.x" &&
11 test_expect_success 'setup' '
13 a aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
14 b bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
15 c cccccccccccccccccccccccccccccccccccccccccccccccc
16 d dddddddddddddddddddddddddddddddddddddddddddddddd
17 e eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
18 f ffffffffffffffffffffffffffffffffffffffffffffffff
19 g gggggggggggggggggggggggggggggggggggggggggggggggg
20 h hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
21 i iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
22 j jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj
23 k kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
24 l llllllllllllllllllllllllllllllllllllllllllllllll
25 m mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
26 n nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
27 o oooooooooooooooooooooooooooooooooooooooooooooooo
31 A AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
32 B BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
33 C CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
34 D DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
35 E EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
36 F FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
37 G GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
38 H HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
39 I IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
40 J JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
41 K KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK
42 L LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
43 M MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
44 N NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
45 O OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
49 git commit -m "initial has A and M" &&
55 git branch change+rename &&
57 sed -e "/^g /s/.*/g : master changes a line/" <A >A+ &&
59 git commit -a -m "master updates A" &&
61 git checkout yellow &&
63 git commit -a -m "yellow removes M" &&
66 sed -e "/^g /s/.*/g : white changes a line/" <A >B &&
67 sed -e "/^G /s/.*/G : colored branch changes a line/" <M >N &&
69 git update-index --add --remove A B M N &&
70 git commit -m "white renames A->B, M->N" &&
73 sed -e "/^g /s/.*/g : red changes a line/" <A >B &&
74 sed -e "/^G /s/.*/G : colored branch changes a line/" <M >N &&
76 git update-index --add --remove A B M N &&
77 git commit -m "red renames A->B, M->N" &&
80 sed -e "/^g /s/.*/g : blue changes a line/" <A >C &&
81 sed -e "/^G /s/.*/G : colored branch changes a line/" <M >N &&
83 git update-index --add --remove A C M N &&
84 git commit -m "blue renames A->C, M->N" &&
86 git checkout change &&
87 sed -e "/^g /s/.*/g : changed line/" <A >A+ &&
89 git commit -q -a -m "changed" &&
91 git checkout change+rename &&
92 sed -e "/^g /s/.*/g : changed line/" <A >B &&
94 git update-index --add B &&
95 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 &&
246 test-tool chmtime --get -3600 B >old-mtime &&
247 GIT_MERGE_VERBOSITY=3 git merge change >out &&
249 test-tool chmtime --get B >new-mtime &&
250 test_cmp old-mtime new-mtime &&
252 git reset --hard HEAD^ &&
253 git checkout change &&
255 # A will be renamed to B; we check mtimes and file presence
256 test_path_is_missing B &&
257 test-tool chmtime --get -3600 A >old-mtime &&
258 GIT_MERGE_VERBOSITY=3 git merge change+rename >out &&
260 test_path_is_missing A &&
261 test-tool chmtime --get B >new-mtime &&
262 test $(cat old-mtime) -lt $(cat new-mtime)
265 test_expect_success 'setup for rename + d/f conflicts' '
267 git checkout --orphan dir-in-way &&
273 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >sub/file &&
274 echo foo >dir/file-in-the-way &&
276 git commit -m "Common commit" &&
278 echo 11 >>sub/file &&
279 echo more >>dir/file-in-the-way &&
281 git commit -m "Commit to merge, with dir in the way" &&
283 git checkout -b dir-not-in-way &&
284 git reset --soft HEAD^ &&
286 git commit -m "Commit to merge, with dir removed" -- dir sub/file &&
288 git checkout -b renamed-file-has-no-conflicts dir-in-way~1 &&
291 printf "1\n2\n3\n4\n5555\n6\n7\n8\n9\n10\n" >dir &&
293 git commit -m "Independent change" &&
295 git checkout -b renamed-file-has-conflicts dir-in-way~1 &&
297 git mv sub/file dir &&
300 git commit -m "Conflicting change"
303 test_expect_success 'Rename+D/F conflict; renamed file merges + dir not in way' '
305 git checkout -q renamed-file-has-no-conflicts^0 &&
307 git merge --strategy=recursive dir-not-in-way &&
310 test_path_is_file dir &&
311 test_write_lines 1 2 3 4 5555 6 7 8 9 10 11 >expected &&
312 test_cmp expected dir
315 test_expect_success 'Rename+D/F conflict; renamed file merges but dir in way' '
318 git checkout -q renamed-file-has-no-conflicts^0 &&
319 test_must_fail git merge --strategy=recursive dir-in-way >output &&
321 test_i18ngrep "CONFLICT (modify/delete): dir/file-in-the-way" output &&
322 test_i18ngrep "Auto-merging dir" output &&
323 test_i18ngrep "Adding as dir~HEAD instead" output &&
325 test 3 -eq "$(git ls-files -u | wc -l)" &&
326 test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
328 test_must_fail git diff --quiet &&
329 test_must_fail git diff --cached --quiet &&
331 test_path_is_file dir/file-in-the-way &&
332 test_path_is_file dir~HEAD &&
333 test_cmp expected dir~HEAD
336 test_expect_success 'Same as previous, but merged other way' '
339 git checkout -q dir-in-way^0 &&
340 test_must_fail git merge --strategy=recursive renamed-file-has-no-conflicts >output 2>errors &&
342 ! grep "error: refusing to lose untracked file at" errors &&
343 test_i18ngrep "CONFLICT (modify/delete): dir/file-in-the-way" output &&
344 test_i18ngrep "Auto-merging dir" output &&
345 test_i18ngrep "Adding as dir~renamed-file-has-no-conflicts instead" output &&
347 test 3 -eq "$(git ls-files -u | wc -l)" &&
348 test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
350 test_must_fail git diff --quiet &&
351 test_must_fail git diff --cached --quiet &&
353 test_path_is_file dir/file-in-the-way &&
354 test_path_is_file dir~renamed-file-has-no-conflicts &&
355 test_cmp expected dir~renamed-file-has-no-conflicts
358 test_expect_success 'Rename+D/F conflict; renamed file cannot merge, dir not in way' '
361 git checkout -q renamed-file-has-conflicts^0 &&
362 test_must_fail git merge --strategy=recursive dir-not-in-way &&
364 test 3 -eq "$(git ls-files -u | wc -l)" &&
365 test 3 -eq "$(git ls-files -u dir | wc -l)" &&
367 test_must_fail git diff --quiet &&
368 test_must_fail git diff --cached --quiet &&
370 test_path_is_file dir &&
371 cat >expected <<-\EOF &&
386 >>>>>>> dir-not-in-way:sub/file
388 test_cmp expected dir
391 test_expect_success 'Rename+D/F conflict; renamed file cannot merge and dir in the way' '
392 modify s/dir-not-in-way/dir-in-way/ expected &&
396 git checkout -q renamed-file-has-conflicts^0 &&
397 test_must_fail git merge --strategy=recursive dir-in-way &&
399 test 5 -eq "$(git ls-files -u | wc -l)" &&
400 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
402 test 3 -eq "$(git ls-files -u dir~HEAD | wc -l)"
404 test 3 -eq "$(git ls-files -u dir | grep -v file-in-the-way | wc -l)"
406 test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
408 test_must_fail git diff --quiet &&
409 test_must_fail git diff --cached --quiet &&
411 test_path_is_file dir/file-in-the-way &&
412 test_path_is_file dir~HEAD &&
413 test_cmp expected dir~HEAD
416 test_expect_success 'Same as previous, but merged other way' '
419 git checkout -q dir-in-way^0 &&
420 test_must_fail git merge --strategy=recursive renamed-file-has-conflicts &&
422 test 5 -eq "$(git ls-files -u | wc -l)" &&
423 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
425 test 3 -eq "$(git ls-files -u dir~renamed-file-has-conflicts | wc -l)"
427 test 3 -eq "$(git ls-files -u dir | grep -v file-in-the-way | wc -l)"
429 test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
431 test_must_fail git diff --quiet &&
432 test_must_fail git diff --cached --quiet &&
434 test_path_is_file dir/file-in-the-way &&
435 test_path_is_file dir~renamed-file-has-conflicts &&
436 cat >expected <<-\EOF &&
447 <<<<<<< HEAD:sub/file
451 >>>>>>> renamed-file-has-conflicts:dir
453 test_cmp expected dir~renamed-file-has-conflicts
456 test_expect_success 'setup both rename source and destination involved in D/F conflict' '
458 git checkout --orphan rename-dest &&
463 echo stuff >one/file &&
465 git commit -m "Common commit" &&
467 git mv one/file destdir &&
468 git commit -m "Renamed to destdir" &&
470 git checkout -b source-conflict HEAD~1 &&
473 touch one destdir/foo &&
475 git commit -m "Conflicts in the way"
478 test_expect_success 'both rename source and destination involved in D/F conflict' '
481 git checkout -q rename-dest^0 &&
482 test_must_fail git merge --strategy=recursive source-conflict &&
484 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
486 test 2 -eq "$(git ls-files -u | wc -l)"
488 test 1 -eq "$(git ls-files -u | wc -l)"
491 test_must_fail git diff --quiet &&
493 test_path_is_file destdir/foo &&
494 test_path_is_file one &&
495 test_path_is_file destdir~HEAD &&
496 test "stuff" = "$(cat destdir~HEAD)"
499 test_expect_success 'setup pair rename to parent of other (D/F conflicts)' '
501 git checkout --orphan rename-two &&
507 echo stuff >one/file &&
508 echo other >two/file &&
510 git commit -m "Common commit" &&
513 git mv two/file one &&
514 git commit -m "Rename two/file -> one" &&
516 git checkout -b rename-one HEAD~1 &&
518 git mv one/file two &&
520 git commit -m "Rename one/file -> two"
523 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
525 test_expect_success 'pair rename to parent of other (D/F conflicts) w/ untracked dir' '
526 git checkout -q rename-one^0 &&
528 test_must_fail git merge --strategy=recursive rename-two &&
530 test 4 -eq "$(git ls-files -u | wc -l)" &&
531 test 2 -eq "$(git ls-files -u one | wc -l)" &&
532 test 2 -eq "$(git ls-files -u two | wc -l)" &&
534 test_must_fail git diff --quiet &&
536 test 3 -eq $(find . | grep -v .git | wc -l) &&
538 test_path_is_file one &&
539 test_path_is_file two &&
540 test "other" = $(cat one) &&
541 test "stuff" = $(cat two)
544 test_expect_success 'pair rename to parent of other (D/F conflicts) w/ untracked dir' '
545 git checkout -q rename-one^0 &&
547 test_must_fail git merge --strategy=recursive rename-two &&
549 test 2 -eq "$(git ls-files -u | wc -l)" &&
550 test 1 -eq "$(git ls-files -u one | wc -l)" &&
551 test 1 -eq "$(git ls-files -u two | wc -l)" &&
553 test_must_fail git diff --quiet &&
555 test 4 -eq $(find . | grep -v .git | wc -l) &&
557 test_path_is_dir one &&
558 test_path_is_file one~rename-two &&
559 test_path_is_file two &&
560 test "other" = $(cat one~rename-two) &&
561 test "stuff" = $(cat two)
565 test_expect_success 'pair rename to parent of other (D/F conflicts) w/ clean start' '
568 test_must_fail git merge --strategy=recursive rename-two &&
570 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
572 test 4 -eq "$(git ls-files -u | wc -l)" &&
573 test 2 -eq "$(git ls-files -u one | wc -l)" &&
574 test 2 -eq "$(git ls-files -u two | wc -l)"
576 test 2 -eq "$(git ls-files -u | wc -l)" &&
577 test 1 -eq "$(git ls-files -u one | wc -l)" &&
578 test 1 -eq "$(git ls-files -u two | wc -l)"
581 test_must_fail git diff --quiet &&
583 test 3 -eq $(find . | grep -v .git | wc -l) &&
585 test_path_is_file one &&
586 test_path_is_file two &&
587 test "other" = $(cat one) &&
588 test "stuff" = $(cat two)
591 test_expect_success 'setup rename of one file to two, with directories in the way' '
593 git checkout --orphan first-rename &&
597 echo stuff >original &&
599 git commit -m "Common commit" &&
604 git mv original one &&
605 git commit -m "Put two/file in the way, rename to one" &&
607 git checkout -b second-rename HEAD~1 &&
611 git mv original two &&
612 git commit -m "Put one/file in the way, rename to two"
615 test_expect_success 'check handling of differently renamed file with D/F conflicts' '
616 git checkout -q first-rename^0 &&
617 test_must_fail git merge --strategy=recursive second-rename &&
619 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
621 test 5 -eq "$(git ls-files -s | wc -l)" &&
622 test 3 -eq "$(git ls-files -u | wc -l)" &&
623 test 1 -eq "$(git ls-files -u one~HEAD | wc -l)" &&
624 test 1 -eq "$(git ls-files -u two~second-rename | wc -l)" &&
625 test 1 -eq "$(git ls-files -u original | wc -l)" &&
626 test 0 -eq "$(git ls-files -o | wc -l)"
628 test 5 -eq "$(git ls-files -s | wc -l)" &&
629 test 3 -eq "$(git ls-files -u | wc -l)" &&
630 test 1 -eq "$(git ls-files -u one | wc -l)" &&
631 test 1 -eq "$(git ls-files -u two | wc -l)" &&
632 test 1 -eq "$(git ls-files -u original | wc -l)" &&
633 test 2 -eq "$(git ls-files -o | wc -l)"
636 test_path_is_file one/file &&
637 test_path_is_file two/file &&
638 test_path_is_file one~HEAD &&
639 test_path_is_file two~second-rename &&
640 test_path_is_missing original
643 test_expect_success 'setup rename one file to two; directories moving out of the way' '
645 git checkout --orphan first-rename-redo &&
649 echo stuff >original &&
651 touch one/file two/file &&
653 git commit -m "Common commit" &&
656 git mv original one &&
657 git commit -m "Rename to one" &&
659 git checkout -b second-rename-redo HEAD~1 &&
661 git mv original two &&
662 git commit -m "Rename to two"
665 test_expect_success 'check handling of differently renamed file with D/F conflicts' '
666 git checkout -q first-rename-redo^0 &&
667 test_must_fail git merge --strategy=recursive second-rename-redo &&
669 test 3 -eq "$(git ls-files -u | wc -l)" &&
670 test 1 -eq "$(git ls-files -u one | wc -l)" &&
671 test 1 -eq "$(git ls-files -u two | wc -l)" &&
672 test 1 -eq "$(git ls-files -u original | wc -l)" &&
673 test 0 -eq "$(git ls-files -o | wc -l)" &&
675 test_path_is_file one &&
676 test_path_is_file two &&
677 test_path_is_missing original
680 test_expect_success 'setup avoid unnecessary update, normal rename' '
682 git checkout --orphan avoid-unnecessary-update-1 &&
686 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >original &&
688 git commit -m "Common commit" &&
690 git mv original rename &&
693 git commit -m "Renamed and modified" &&
695 git checkout -b merge-branch-1 HEAD~1 &&
696 echo "random content" >random-file &&
698 git commit -m "Random, unrelated changes"
701 test_expect_success 'avoid unnecessary update, normal rename' '
702 git checkout -q avoid-unnecessary-update-1^0 &&
703 test-tool chmtime --get -3600 rename >expect &&
704 git merge merge-branch-1 &&
705 test-tool chmtime --get rename >actual &&
706 test_cmp expect actual # "rename" should have stayed intact
709 test_expect_success 'setup to test avoiding unnecessary update, with D/F conflict' '
711 git checkout --orphan avoid-unnecessary-update-2 &&
716 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >df/file &&
718 git commit -m "Common commit" &&
720 git mv df/file temp &&
725 git commit -m "Renamed and modified" &&
727 git checkout -b merge-branch-2 HEAD~1 &&
729 git add unrelated-change &&
730 git commit -m "Only unrelated changes"
733 test_expect_success 'avoid unnecessary update, with D/F conflict' '
734 git checkout -q avoid-unnecessary-update-2^0 &&
735 test-tool chmtime --get -3600 df >expect &&
736 git merge merge-branch-2 &&
737 test-tool chmtime --get df >actual &&
738 test_cmp expect actual # "df" should have stayed intact
741 test_expect_success 'setup avoid unnecessary update, dir->(file,nothing)' '
753 git checkout -b side &&
757 git checkout master &&
761 git commit -m "Add a newfile"
764 test_expect_success 'avoid unnecessary update, dir->(file,nothing)' '
765 git checkout -q master^0 &&
766 test-tool chmtime --get -3600 df >expect &&
768 test-tool chmtime --get df >actual &&
769 test_cmp expect actual # "df" should have stayed intact
772 test_expect_success 'setup avoid unnecessary update, modify/delete' '
783 git checkout -b side &&
785 git commit -m "Delete file" &&
787 git checkout master &&
790 git commit -m "Modify file"
793 test_expect_success 'avoid unnecessary update, modify/delete' '
794 git checkout -q master^0 &&
795 test-tool chmtime --get -3600 file >expect &&
796 test_must_fail git merge side &&
797 test-tool chmtime --get file >actual &&
798 test_cmp expect actual # "file" should have stayed intact
801 test_expect_success 'setup avoid unnecessary update, rename/add-dest' '
807 printf "1\n2\n3\n4\n5\n6\n7\n8\n" >file &&
811 git checkout -b side &&
814 git commit -m "Add file copy" &&
816 git checkout master &&
817 git mv file newfile &&
818 git commit -m "Rename file"
821 test_expect_success 'avoid unnecessary update, rename/add-dest' '
822 git checkout -q master^0 &&
823 test-tool chmtime --get -3600 newfile >expect &&
825 test-tool chmtime --get newfile >actual &&
826 test_cmp expect actual # "file" should have stayed intact
829 test_expect_success 'setup merge of rename + small change' '
831 git checkout --orphan rename-plus-small-change &&
835 echo ORIGINAL >file &&
839 git commit -m Initial &&
840 git checkout -b rename_branch &&
841 git mv file renamed_file &&
842 git commit -m Rename &&
843 git checkout rename-plus-small-change &&
844 echo NEW-VERSION >file &&
845 git commit -a -m Reformat
848 test_expect_success 'merge rename + small change' '
849 git merge rename_branch &&
851 test 1 -eq $(git ls-files -s | wc -l) &&
852 test 0 -eq $(git ls-files -o | wc -l) &&
853 test $(git rev-parse HEAD:renamed_file) = $(git rev-parse HEAD~1:file)
856 test_expect_success 'setup for use of extended merge markers' '
862 printf "1\n2\n3\n4\n5\n6\n7\n8\n" >original_file &&
863 git add original_file &&
866 git checkout -b rename &&
867 echo 9 >>original_file &&
868 git add original_file &&
869 git mv original_file renamed_file &&
872 git checkout master &&
873 echo 8.5 >>original_file &&
874 git add original_file &&
878 test_expect_success 'merge master into rename has correct extended markers' '
879 git checkout rename^0 &&
880 test_must_fail git merge -s recursive master^0 &&
882 cat >expected <<-\EOF &&
891 <<<<<<< HEAD:renamed_file
895 >>>>>>> master^0:original_file
897 test_cmp expected renamed_file
900 test_expect_success 'merge rename into master has correct extended markers' '
902 git checkout master^0 &&
903 test_must_fail git merge -s recursive rename^0 &&
905 cat >expected <<-\EOF &&
914 <<<<<<< HEAD:original_file
918 >>>>>>> rename^0:renamed_file
920 test_cmp expected renamed_file
923 test_expect_success 'setup spurious "refusing to lose untracked" message' '
930 printf "1\n2\n3\n4\n5\n6\n7\n8\n" >original_file &&
931 git add irrelevant_file original_file &&
934 git checkout -b rename &&
935 git mv original_file renamed_file &&
938 git checkout master &&
939 git rm original_file &&
943 test_expect_success 'no spurious "refusing to lose untracked" message' '
944 git checkout master^0 &&
945 test_must_fail git merge rename^0 2>errors.txt &&
946 ! grep "refusing to lose untracked file" errors.txt
949 test_expect_success 'do not follow renames for empty files' '
950 git checkout -f -b empty-base &&
953 git commit -m base &&
954 echo content >empty1 &&
956 git commit -m fill &&
957 git checkout -b empty-topic HEAD^ &&
958 git mv empty1 empty2 &&
959 git commit -m rename &&
960 test_must_fail git merge empty-base &&
961 test_must_be_empty empty2