]>
git.ipfire.org Git - thirdparty/git.git/blob - t/t6022-merge-rename.sh
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 =31337 B &&
247 test-tool chmtime --get B >old-mtime &&
248 GIT_MERGE_VERBOSITY=3 git merge change >out &&
250 test-tool chmtime --get B >new-mtime &&
251 test_cmp old-mtime new-mtime &&
253 git reset --hard HEAD^ &&
254 git checkout change &&
256 test-tool chmtime =-1 M &&
257 test-tool chmtime --get M >old-mtime &&
258 GIT_MERGE_VERBOSITY=3 git merge change+rename >out &&
260 test-tool chmtime --get B >new-mtime &&
261 test $(cat old-mtime) -lt $(cat new-mtime)
264 test_expect_success
'setup for rename + d/f conflicts' '
266 git checkout --orphan dir-in-way &&
272 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >sub/file &&
273 echo foo >dir/file-in-the-way &&
275 git commit -m "Common commit" &&
277 echo 11 >>sub/file &&
278 echo more >>dir/file-in-the-way &&
280 git commit -m "Commit to merge, with dir in the way" &&
282 git checkout -b dir-not-in-way &&
283 git reset --soft HEAD^ &&
285 git commit -m "Commit to merge, with dir removed" -- dir sub/file &&
287 git checkout -b renamed-file-has-no-conflicts dir-in-way~1 &&
290 printf "1\n2\n3\n4\n5555\n6\n7\n8\n9\n10\n" >dir &&
292 git commit -m "Independent change" &&
294 git checkout -b renamed-file-has-conflicts dir-in-way~1 &&
296 git mv sub/file dir &&
299 git commit -m "Conflicting change"
302 test_expect_success
'Rename+D/F conflict; renamed file merges + dir not in way' '
304 git checkout -q renamed-file-has-no-conflicts^0 &&
306 git merge --strategy=recursive dir-not-in-way &&
309 test_path_is_file dir &&
310 test_write_lines 1 2 3 4 5555 6 7 8 9 10 11 >expected &&
311 test_cmp expected dir
314 test_expect_success
'Rename+D/F conflict; renamed file merges but dir in way' '
317 git checkout -q renamed-file-has-no-conflicts^0 &&
318 test_must_fail git merge --strategy=recursive dir-in-way >output &&
320 test_i18ngrep "CONFLICT (modify/delete): dir/file-in-the-way" output &&
321 test_i18ngrep "Auto-merging dir" output &&
322 test_i18ngrep "Adding as dir~HEAD instead" output &&
324 test 3 -eq "$(git ls-files -u | wc -l)" &&
325 test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
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_i18ngrep "CONFLICT (modify/delete): dir/file-in-the-way" output &&
343 test_i18ngrep "Auto-merging dir" output &&
344 test_i18ngrep "Adding as dir~renamed-file-has-no-conflicts instead" output &&
346 test 3 -eq "$(git ls-files -u | wc -l)" &&
347 test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
349 test_must_fail git diff --quiet &&
350 test_must_fail git diff --cached --quiet &&
352 test_path_is_file dir/file-in-the-way &&
353 test_path_is_file dir~renamed-file-has-no-conflicts &&
354 test_cmp expected dir~renamed-file-has-no-conflicts
357 test_expect_success
'Rename+D/F conflict; renamed file cannot merge, dir not in way' '
360 git checkout -q renamed-file-has-conflicts^0 &&
361 test_must_fail git merge --strategy=recursive dir-not-in-way &&
363 test 3 -eq "$(git ls-files -u | wc -l)" &&
364 test 3 -eq "$(git ls-files -u dir | wc -l)" &&
366 test_must_fail git diff --quiet &&
367 test_must_fail git diff --cached --quiet &&
369 test_path_is_file dir &&
370 cat >expected <<-\EOF &&
385 >>>>>>> dir-not-in-way:sub/file
387 test_cmp expected dir
390 test_expect_success
'Rename+D/F conflict; renamed file cannot merge and dir in the way' '
391 modify s/dir-not-in-way/dir-in-way/ expected &&
395 git checkout -q renamed-file-has-conflicts^0 &&
396 test_must_fail git merge --strategy=recursive dir-in-way &&
398 test 5 -eq "$(git ls-files -u | wc -l)" &&
399 test 3 -eq "$(git ls-files -u dir | grep -v file-in-the-way | wc -l)" &&
400 test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
402 test_must_fail git diff --quiet &&
403 test_must_fail git diff --cached --quiet &&
405 test_path_is_file dir/file-in-the-way &&
406 test_path_is_file dir~HEAD &&
407 test_cmp expected dir~HEAD
410 test_expect_success
'Same as previous, but merged other way' '
413 git checkout -q dir-in-way^0 &&
414 test_must_fail git merge --strategy=recursive renamed-file-has-conflicts &&
416 test 5 -eq "$(git ls-files -u | wc -l)" &&
417 test 3 -eq "$(git ls-files -u dir | grep -v file-in-the-way | wc -l)" &&
418 test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
420 test_must_fail git diff --quiet &&
421 test_must_fail git diff --cached --quiet &&
423 test_path_is_file dir/file-in-the-way &&
424 test_path_is_file dir~renamed-file-has-conflicts &&
425 cat >expected <<-\EOF &&
436 <<<<<<< HEAD:sub/file
440 >>>>>>> renamed-file-has-conflicts:dir
442 test_cmp expected dir~renamed-file-has-conflicts
445 test_expect_success
'setup both rename source and destination involved in D/F conflict' '
447 git checkout --orphan rename-dest &&
452 echo stuff >one/file &&
454 git commit -m "Common commit" &&
456 git mv one/file destdir &&
457 git commit -m "Renamed to destdir" &&
459 git checkout -b source-conflict HEAD~1 &&
462 touch one destdir/foo &&
464 git commit -m "Conflicts in the way"
467 test_expect_success
'both rename source and destination involved in D/F conflict' '
470 git checkout -q rename-dest^0 &&
471 test_must_fail git merge --strategy=recursive source-conflict &&
473 test 1 -eq "$(git ls-files -u | wc -l)" &&
475 test_must_fail git diff --quiet &&
477 test_path_is_file destdir/foo &&
478 test_path_is_file one &&
479 test_path_is_file destdir~HEAD &&
480 test "stuff" = "$(cat destdir~HEAD)"
483 test_expect_success
'setup pair rename to parent of other (D/F conflicts)' '
485 git checkout --orphan rename-two &&
491 echo stuff >one/file &&
492 echo other >two/file &&
494 git commit -m "Common commit" &&
497 git mv two/file one &&
498 git commit -m "Rename two/file -> one" &&
500 git checkout -b rename-one HEAD~1 &&
502 git mv one/file two &&
504 git commit -m "Rename one/file -> two"
507 test_expect_success
'pair rename to parent of other (D/F conflicts) w/ untracked dir' '
508 git checkout -q rename-one^0 &&
510 test_must_fail git merge --strategy=recursive rename-two &&
512 test 2 -eq "$(git ls-files -u | wc -l)" &&
513 test 1 -eq "$(git ls-files -u one | wc -l)" &&
514 test 1 -eq "$(git ls-files -u two | wc -l)" &&
516 test_must_fail git diff --quiet &&
518 test 4 -eq $(find . | grep -v .git | wc -l) &&
520 test_path_is_dir one &&
521 test_path_is_file one~rename-two &&
522 test_path_is_file two &&
523 test "other" = $(cat one~rename-two) &&
524 test "stuff" = $(cat two)
527 test_expect_success
'pair rename to parent of other (D/F conflicts) w/ clean start' '
530 test_must_fail git merge --strategy=recursive rename-two &&
532 test 2 -eq "$(git ls-files -u | wc -l)" &&
533 test 1 -eq "$(git ls-files -u one | wc -l)" &&
534 test 1 -eq "$(git ls-files -u two | wc -l)" &&
536 test_must_fail git diff --quiet &&
538 test 3 -eq $(find . | grep -v .git | wc -l) &&
540 test_path_is_file one &&
541 test_path_is_file two &&
542 test "other" = $(cat one) &&
543 test "stuff" = $(cat two)
546 test_expect_success
'setup rename of one file to two, with directories in the way' '
548 git checkout --orphan first-rename &&
552 echo stuff >original &&
554 git commit -m "Common commit" &&
559 git mv original one &&
560 git commit -m "Put two/file in the way, rename to one" &&
562 git checkout -b second-rename HEAD~1 &&
566 git mv original two &&
567 git commit -m "Put one/file in the way, rename to two"
570 test_expect_success
'check handling of differently renamed file with D/F conflicts' '
571 git checkout -q first-rename^0 &&
572 test_must_fail git merge --strategy=recursive second-rename &&
574 test 5 -eq "$(git ls-files -s | wc -l)" &&
575 test 3 -eq "$(git ls-files -u | wc -l)" &&
576 test 1 -eq "$(git ls-files -u one | wc -l)" &&
577 test 1 -eq "$(git ls-files -u two | wc -l)" &&
578 test 1 -eq "$(git ls-files -u original | wc -l)" &&
579 test 2 -eq "$(git ls-files -o | wc -l)" &&
581 test_path_is_file one/file &&
582 test_path_is_file two/file &&
583 test_path_is_file one~HEAD &&
584 test_path_is_file two~second-rename &&
585 test_path_is_missing original
588 test_expect_success
'setup rename one file to two; directories moving out of the way' '
590 git checkout --orphan first-rename-redo &&
594 echo stuff >original &&
596 touch one/file two/file &&
598 git commit -m "Common commit" &&
601 git mv original one &&
602 git commit -m "Rename to one" &&
604 git checkout -b second-rename-redo HEAD~1 &&
606 git mv original two &&
607 git commit -m "Rename to two"
610 test_expect_success
'check handling of differently renamed file with D/F conflicts' '
611 git checkout -q first-rename-redo^0 &&
612 test_must_fail git merge --strategy=recursive second-rename-redo &&
614 test 3 -eq "$(git ls-files -u | wc -l)" &&
615 test 1 -eq "$(git ls-files -u one | wc -l)" &&
616 test 1 -eq "$(git ls-files -u two | wc -l)" &&
617 test 1 -eq "$(git ls-files -u original | wc -l)" &&
618 test 0 -eq "$(git ls-files -o | wc -l)" &&
620 test_path_is_file one &&
621 test_path_is_file two &&
622 test_path_is_missing original
625 test_expect_success
'setup avoid unnecessary update, normal rename' '
627 git checkout --orphan avoid-unnecessary-update-1 &&
631 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >original &&
633 git commit -m "Common commit" &&
635 git mv original rename &&
638 git commit -m "Renamed and modified" &&
640 git checkout -b merge-branch-1 HEAD~1 &&
641 echo "random content" >random-file &&
643 git commit -m "Random, unrelated changes"
646 test_expect_success
'avoid unnecessary update, normal rename' '
647 git checkout -q avoid-unnecessary-update-1^0 &&
648 test-tool chmtime --get =1000000000 rename >expect &&
649 git merge merge-branch-1 &&
650 test-tool chmtime --get rename >actual &&
651 test_cmp expect actual # "rename" should have stayed intact
654 test_expect_success
'setup to test avoiding unnecessary update, with D/F conflict' '
656 git checkout --orphan avoid-unnecessary-update-2 &&
661 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >df/file &&
663 git commit -m "Common commit" &&
665 git mv df/file temp &&
670 git commit -m "Renamed and modified" &&
672 git checkout -b merge-branch-2 HEAD~1 &&
674 git add unrelated-change &&
675 git commit -m "Only unrelated changes"
678 test_expect_success
'avoid unnecessary update, with D/F conflict' '
679 git checkout -q avoid-unnecessary-update-2^0 &&
680 test-tool chmtime --get =1000000000 df >expect &&
681 git merge merge-branch-2 &&
682 test-tool chmtime --get df >actual &&
683 test_cmp expect actual # "df" should have stayed intact
686 test_expect_success
'setup avoid unnecessary update, dir->(file,nothing)' '
698 git checkout -b side &&
702 git checkout master &&
706 git commit -m "Add a newfile"
709 test_expect_success
'avoid unnecessary update, dir->(file,nothing)' '
710 git checkout -q master^0 &&
711 test-tool chmtime --get =1000000000 df >expect &&
713 test-tool chmtime --get df >actual &&
714 test_cmp expect actual # "df" should have stayed intact
717 test_expect_success
'setup avoid unnecessary update, modify/delete' '
728 git checkout -b side &&
730 git commit -m "Delete file" &&
732 git checkout master &&
735 git commit -m "Modify file"
738 test_expect_success
'avoid unnecessary update, modify/delete' '
739 git checkout -q master^0 &&
740 test-tool chmtime --get =1000000000 file >expect &&
741 test_must_fail git merge side &&
742 test-tool chmtime --get file >actual &&
743 test_cmp expect actual # "file" should have stayed intact
746 test_expect_success
'setup avoid unnecessary update, rename/add-dest' '
752 printf "1\n2\n3\n4\n5\n6\n7\n8\n" >file &&
756 git checkout -b side &&
759 git commit -m "Add file copy" &&
761 git checkout master &&
762 git mv file newfile &&
763 git commit -m "Rename file"
766 test_expect_success
'avoid unnecessary update, rename/add-dest' '
767 git checkout -q master^0 &&
768 test-tool chmtime --get =1000000000 newfile >expect &&
770 test-tool chmtime --get newfile >actual &&
771 test_cmp expect actual # "file" should have stayed intact
774 test_expect_success
'setup merge of rename + small change' '
776 git checkout --orphan rename-plus-small-change &&
780 echo ORIGINAL >file &&
784 git commit -m Initial &&
785 git checkout -b rename_branch &&
786 git mv file renamed_file &&
787 git commit -m Rename &&
788 git checkout rename-plus-small-change &&
789 echo NEW-VERSION >file &&
790 git commit -a -m Reformat
793 test_expect_success
'merge rename + small change' '
794 git merge rename_branch &&
796 test 1 -eq $(git ls-files -s | wc -l) &&
797 test 0 -eq $(git ls-files -o | wc -l) &&
798 test $(git rev-parse HEAD:renamed_file) = $(git rev-parse HEAD~1:file)
801 test_expect_success
'setup for use of extended merge markers' '
807 printf "1\n2\n3\n4\n5\n6\n7\n8\n" >original_file &&
808 git add original_file &&
811 git checkout -b rename &&
812 echo 9 >>original_file &&
813 git add original_file &&
814 git mv original_file renamed_file &&
817 git checkout master &&
818 echo 8.5 >>original_file &&
819 git add original_file &&
823 test_expect_success
'merge master into rename has correct extended markers' '
824 git checkout rename^0 &&
825 test_must_fail git merge -s recursive master^0 &&
827 cat >expected <<-\EOF &&
836 <<<<<<< HEAD:renamed_file
840 >>>>>>> master^0:original_file
842 test_cmp expected renamed_file
845 test_expect_success
'merge rename into master has correct extended markers' '
847 git checkout master^0 &&
848 test_must_fail git merge -s recursive rename^0 &&
850 cat >expected <<-\EOF &&
859 <<<<<<< HEAD:original_file
863 >>>>>>> rename^0:renamed_file
865 test_cmp expected renamed_file
868 test_expect_success
'setup spurious "refusing to lose untracked" message' '
875 printf "1\n2\n3\n4\n5\n6\n7\n8\n" >original_file &&
876 git add irrelevant_file original_file &&
879 git checkout -b rename &&
880 git mv original_file renamed_file &&
883 git checkout master &&
884 git rm original_file &&
888 test_expect_success
'no spurious "refusing to lose untracked" message' '
889 git checkout master^0 &&
890 test_must_fail git merge rename^0 2>errors.txt &&
891 ! grep "refusing to lose untracked file" errors.txt
894 test_expect_success
'do not follow renames for empty files' '
895 git checkout -f -b empty-base &&
898 git commit -m base &&
899 echo content >empty1 &&
901 git commit -m fill &&
902 git checkout -b empty-topic HEAD^ &&
903 git mv empty1 empty2 &&
904 git commit -m rename &&
905 test_must_fail git merge empty-base &&
906 test_must_be_empty empty2