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 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
325 test_i18ngrep "moving it to dir~HEAD instead" output
327 test_i18ngrep "Adding as dir~HEAD instead" output
330 test 3 -eq "$(git ls-files -u | wc -l)" &&
331 test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
333 test_must_fail git diff --quiet &&
334 test_must_fail git diff --cached --quiet &&
336 test_path_is_file dir/file-in-the-way &&
337 test_path_is_file dir~HEAD &&
338 test_cmp expected dir~HEAD
341 test_expect_success 'Same as previous, but merged other way' '
344 git checkout -q dir-in-way^0 &&
345 test_must_fail git merge --strategy=recursive renamed-file-has-no-conflicts >output 2>errors &&
347 ! grep "error: refusing to lose untracked file at" errors &&
348 test_i18ngrep "CONFLICT (modify/delete): dir/file-in-the-way" output &&
349 test_i18ngrep "Auto-merging dir" output &&
350 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
352 test_i18ngrep "moving it to dir~renamed-file-has-no-conflicts instead" output
354 test_i18ngrep "Adding as dir~renamed-file-has-no-conflicts instead" output
357 test 3 -eq "$(git ls-files -u | wc -l)" &&
358 test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
360 test_must_fail git diff --quiet &&
361 test_must_fail git diff --cached --quiet &&
363 test_path_is_file dir/file-in-the-way &&
364 test_path_is_file dir~renamed-file-has-no-conflicts &&
365 test_cmp expected dir~renamed-file-has-no-conflicts
368 test_expect_success 'Rename+D/F conflict; renamed file cannot merge, dir not in way' '
371 git checkout -q renamed-file-has-conflicts^0 &&
372 test_must_fail git merge --strategy=recursive dir-not-in-way &&
374 test 3 -eq "$(git ls-files -u | wc -l)" &&
375 test 3 -eq "$(git ls-files -u dir | wc -l)" &&
377 test_must_fail git diff --quiet &&
378 test_must_fail git diff --cached --quiet &&
380 test_path_is_file dir &&
381 cat >expected <<-\EOF &&
396 >>>>>>> dir-not-in-way:sub/file
398 test_cmp expected dir
401 test_expect_success 'Rename+D/F conflict; renamed file cannot merge and dir in the way' '
402 modify s/dir-not-in-way/dir-in-way/ expected &&
406 git checkout -q renamed-file-has-conflicts^0 &&
407 test_must_fail git merge --strategy=recursive dir-in-way &&
409 test 5 -eq "$(git ls-files -u | wc -l)" &&
410 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
412 test 3 -eq "$(git ls-files -u dir~HEAD | wc -l)"
414 test 3 -eq "$(git ls-files -u dir | grep -v file-in-the-way | wc -l)"
416 test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
418 test_must_fail git diff --quiet &&
419 test_must_fail git diff --cached --quiet &&
421 test_path_is_file dir/file-in-the-way &&
422 test_path_is_file dir~HEAD &&
423 test_cmp expected dir~HEAD
426 test_expect_success 'Same as previous, but merged other way' '
429 git checkout -q dir-in-way^0 &&
430 test_must_fail git merge --strategy=recursive renamed-file-has-conflicts &&
432 test 5 -eq "$(git ls-files -u | wc -l)" &&
433 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
435 test 3 -eq "$(git ls-files -u dir~renamed-file-has-conflicts | wc -l)"
437 test 3 -eq "$(git ls-files -u dir | grep -v file-in-the-way | wc -l)"
439 test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
441 test_must_fail git diff --quiet &&
442 test_must_fail git diff --cached --quiet &&
444 test_path_is_file dir/file-in-the-way &&
445 test_path_is_file dir~renamed-file-has-conflicts &&
446 cat >expected <<-\EOF &&
457 <<<<<<< HEAD:sub/file
461 >>>>>>> renamed-file-has-conflicts:dir
463 test_cmp expected dir~renamed-file-has-conflicts
466 test_expect_success 'setup both rename source and destination involved in D/F conflict' '
468 git checkout --orphan rename-dest &&
473 echo stuff >one/file &&
475 git commit -m "Common commit" &&
477 git mv one/file destdir &&
478 git commit -m "Renamed to destdir" &&
480 git checkout -b source-conflict HEAD~1 &&
483 touch one destdir/foo &&
485 git commit -m "Conflicts in the way"
488 test_expect_success 'both rename source and destination involved in D/F conflict' '
491 git checkout -q rename-dest^0 &&
492 test_must_fail git merge --strategy=recursive source-conflict &&
494 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
496 test 2 -eq "$(git ls-files -u | wc -l)"
498 test 1 -eq "$(git ls-files -u | wc -l)"
501 test_must_fail git diff --quiet &&
503 test_path_is_file destdir/foo &&
504 test_path_is_file one &&
505 test_path_is_file destdir~HEAD &&
506 test "stuff" = "$(cat destdir~HEAD)"
509 test_expect_success 'setup pair rename to parent of other (D/F conflicts)' '
511 git checkout --orphan rename-two &&
517 echo stuff >one/file &&
518 echo other >two/file &&
520 git commit -m "Common commit" &&
523 git mv two/file one &&
524 git commit -m "Rename two/file -> one" &&
526 git checkout -b rename-one HEAD~1 &&
528 git mv one/file two &&
530 git commit -m "Rename one/file -> two"
533 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
535 test_expect_success 'pair rename to parent of other (D/F conflicts) w/ untracked dir' '
536 git checkout -q rename-one^0 &&
538 test_must_fail git merge --strategy=recursive rename-two &&
540 test 4 -eq "$(git ls-files -u | wc -l)" &&
541 test 2 -eq "$(git ls-files -u one | wc -l)" &&
542 test 2 -eq "$(git ls-files -u two | wc -l)" &&
544 test_must_fail git diff --quiet &&
546 test 3 -eq $(find . | grep -v .git | wc -l) &&
548 test_path_is_file one &&
549 test_path_is_file two &&
550 test "other" = $(cat one) &&
551 test "stuff" = $(cat two)
554 test_expect_success 'pair rename to parent of other (D/F conflicts) w/ untracked dir' '
555 git checkout -q rename-one^0 &&
557 test_must_fail git merge --strategy=recursive rename-two &&
559 test 2 -eq "$(git ls-files -u | wc -l)" &&
560 test 1 -eq "$(git ls-files -u one | wc -l)" &&
561 test 1 -eq "$(git ls-files -u two | wc -l)" &&
563 test_must_fail git diff --quiet &&
565 test 4 -eq $(find . | grep -v .git | wc -l) &&
567 test_path_is_dir one &&
568 test_path_is_file one~rename-two &&
569 test_path_is_file two &&
570 test "other" = $(cat one~rename-two) &&
571 test "stuff" = $(cat two)
575 test_expect_success 'pair rename to parent of other (D/F conflicts) w/ clean start' '
578 test_must_fail git merge --strategy=recursive rename-two &&
580 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
582 test 4 -eq "$(git ls-files -u | wc -l)" &&
583 test 2 -eq "$(git ls-files -u one | wc -l)" &&
584 test 2 -eq "$(git ls-files -u two | wc -l)"
586 test 2 -eq "$(git ls-files -u | wc -l)" &&
587 test 1 -eq "$(git ls-files -u one | wc -l)" &&
588 test 1 -eq "$(git ls-files -u two | wc -l)"
591 test_must_fail git diff --quiet &&
593 test 3 -eq $(find . | grep -v .git | wc -l) &&
595 test_path_is_file one &&
596 test_path_is_file two &&
597 test "other" = $(cat one) &&
598 test "stuff" = $(cat two)
601 test_expect_success 'setup rename of one file to two, with directories in the way' '
603 git checkout --orphan first-rename &&
607 echo stuff >original &&
609 git commit -m "Common commit" &&
614 git mv original one &&
615 git commit -m "Put two/file in the way, rename to one" &&
617 git checkout -b second-rename HEAD~1 &&
621 git mv original two &&
622 git commit -m "Put one/file in the way, rename to two"
625 test_expect_success 'check handling of differently renamed file with D/F conflicts' '
626 git checkout -q first-rename^0 &&
627 test_must_fail git merge --strategy=recursive second-rename &&
629 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
631 test 5 -eq "$(git ls-files -s | wc -l)" &&
632 test 3 -eq "$(git ls-files -u | wc -l)" &&
633 test 1 -eq "$(git ls-files -u one~HEAD | wc -l)" &&
634 test 1 -eq "$(git ls-files -u two~second-rename | wc -l)" &&
635 test 1 -eq "$(git ls-files -u original | wc -l)" &&
636 test 0 -eq "$(git ls-files -o | wc -l)"
638 test 5 -eq "$(git ls-files -s | wc -l)" &&
639 test 3 -eq "$(git ls-files -u | wc -l)" &&
640 test 1 -eq "$(git ls-files -u one | wc -l)" &&
641 test 1 -eq "$(git ls-files -u two | wc -l)" &&
642 test 1 -eq "$(git ls-files -u original | wc -l)" &&
643 test 2 -eq "$(git ls-files -o | wc -l)"
646 test_path_is_file one/file &&
647 test_path_is_file two/file &&
648 test_path_is_file one~HEAD &&
649 test_path_is_file two~second-rename &&
650 test_path_is_missing original
653 test_expect_success 'setup rename one file to two; directories moving out of the way' '
655 git checkout --orphan first-rename-redo &&
659 echo stuff >original &&
661 touch one/file two/file &&
663 git commit -m "Common commit" &&
666 git mv original one &&
667 git commit -m "Rename to one" &&
669 git checkout -b second-rename-redo HEAD~1 &&
671 git mv original two &&
672 git commit -m "Rename to two"
675 test_expect_success 'check handling of differently renamed file with D/F conflicts' '
676 git checkout -q first-rename-redo^0 &&
677 test_must_fail git merge --strategy=recursive second-rename-redo &&
679 test 3 -eq "$(git ls-files -u | wc -l)" &&
680 test 1 -eq "$(git ls-files -u one | wc -l)" &&
681 test 1 -eq "$(git ls-files -u two | wc -l)" &&
682 test 1 -eq "$(git ls-files -u original | wc -l)" &&
683 test 0 -eq "$(git ls-files -o | wc -l)" &&
685 test_path_is_file one &&
686 test_path_is_file two &&
687 test_path_is_missing original
690 test_expect_success 'setup avoid unnecessary update, normal rename' '
692 git checkout --orphan avoid-unnecessary-update-1 &&
696 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >original &&
698 git commit -m "Common commit" &&
700 git mv original rename &&
703 git commit -m "Renamed and modified" &&
705 git checkout -b merge-branch-1 HEAD~1 &&
706 echo "random content" >random-file &&
708 git commit -m "Random, unrelated changes"
711 test_expect_success 'avoid unnecessary update, normal rename' '
712 git checkout -q avoid-unnecessary-update-1^0 &&
713 test-tool chmtime --get -3600 rename >expect &&
714 git merge merge-branch-1 &&
715 test-tool chmtime --get rename >actual &&
716 test_cmp expect actual # "rename" should have stayed intact
719 test_expect_success 'setup to test avoiding unnecessary update, with D/F conflict' '
721 git checkout --orphan avoid-unnecessary-update-2 &&
726 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >df/file &&
728 git commit -m "Common commit" &&
730 git mv df/file temp &&
735 git commit -m "Renamed and modified" &&
737 git checkout -b merge-branch-2 HEAD~1 &&
739 git add unrelated-change &&
740 git commit -m "Only unrelated changes"
743 test_expect_success 'avoid unnecessary update, with D/F conflict' '
744 git checkout -q avoid-unnecessary-update-2^0 &&
745 test-tool chmtime --get -3600 df >expect &&
746 git merge merge-branch-2 &&
747 test-tool chmtime --get df >actual &&
748 test_cmp expect actual # "df" should have stayed intact
751 test_expect_success 'setup avoid unnecessary update, dir->(file,nothing)' '
763 git checkout -b side &&
767 git checkout master &&
771 git commit -m "Add a newfile"
774 test_expect_success 'avoid unnecessary update, dir->(file,nothing)' '
775 git checkout -q master^0 &&
776 test-tool chmtime --get -3600 df >expect &&
778 test-tool chmtime --get df >actual &&
779 test_cmp expect actual # "df" should have stayed intact
782 test_expect_success 'setup avoid unnecessary update, modify/delete' '
793 git checkout -b side &&
795 git commit -m "Delete file" &&
797 git checkout master &&
800 git commit -m "Modify file"
803 test_expect_success 'avoid unnecessary update, modify/delete' '
804 git checkout -q master^0 &&
805 test-tool chmtime --get -3600 file >expect &&
806 test_must_fail git merge side &&
807 test-tool chmtime --get file >actual &&
808 test_cmp expect actual # "file" should have stayed intact
811 test_expect_success 'setup avoid unnecessary update, rename/add-dest' '
817 printf "1\n2\n3\n4\n5\n6\n7\n8\n" >file &&
821 git checkout -b side &&
824 git commit -m "Add file copy" &&
826 git checkout master &&
827 git mv file newfile &&
828 git commit -m "Rename file"
831 test_expect_success 'avoid unnecessary update, rename/add-dest' '
832 git checkout -q master^0 &&
833 test-tool chmtime --get -3600 newfile >expect &&
835 test-tool chmtime --get newfile >actual &&
836 test_cmp expect actual # "file" should have stayed intact
839 test_expect_success 'setup merge of rename + small change' '
841 git checkout --orphan rename-plus-small-change &&
845 echo ORIGINAL >file &&
849 git commit -m Initial &&
850 git checkout -b rename_branch &&
851 git mv file renamed_file &&
852 git commit -m Rename &&
853 git checkout rename-plus-small-change &&
854 echo NEW-VERSION >file &&
855 git commit -a -m Reformat
858 test_expect_success 'merge rename + small change' '
859 git merge rename_branch &&
861 test 1 -eq $(git ls-files -s | wc -l) &&
862 test 0 -eq $(git ls-files -o | wc -l) &&
863 test $(git rev-parse HEAD:renamed_file) = $(git rev-parse HEAD~1:file)
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 &&
882 git checkout master &&
883 echo 8.5 >>original_file &&
884 git add original_file &&
888 test_expect_success 'merge master into rename has correct extended markers' '
889 git checkout rename^0 &&
890 test_must_fail git merge -s recursive master^0 &&
892 cat >expected <<-\EOF &&
901 <<<<<<< HEAD:renamed_file
905 >>>>>>> master^0:original_file
907 test_cmp expected renamed_file
910 test_expect_success 'merge rename into master has correct extended markers' '
912 git checkout master^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 &&
948 git checkout master &&
949 git rm original_file &&
953 test_expect_success 'no spurious "refusing to lose untracked" message' '
954 git checkout master^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