3 test_description
='Merge-recursive merging renames'
7 sed -e "$1" <"$2" >"$2.x" &&
11 test_expect_success setup \
14 a aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
15 b bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
16 c cccccccccccccccccccccccccccccccccccccccccccccccc
17 d dddddddddddddddddddddddddddddddddddddddddddddddd
18 e eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
19 f ffffffffffffffffffffffffffffffffffffffffffffffff
20 g gggggggggggggggggggggggggggggggggggggggggggggggg
21 h hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
22 i iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
23 j jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj
24 k kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
25 l llllllllllllllllllllllllllllllllllllllllllllllll
26 m mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
27 n nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
28 o oooooooooooooooooooooooooooooooooooooooooooooooo
32 A AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
33 B BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
34 C CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
35 D DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
36 E EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
37 F FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
38 G GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
39 H HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
40 I IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
41 J JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
42 K KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK
43 L LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
44 M MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
45 N NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
46 O OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
50 git commit -m "initial has A and M" &&
56 git branch change+rename &&
58 sed -e "/^g /s/.*/g : master changes a line/" <A >A+ &&
60 git commit -a -m "master updates A" &&
62 git checkout yellow &&
64 git commit -a -m "yellow removes M" &&
67 sed -e "/^g /s/.*/g : white changes a line/" <A >B &&
68 sed -e "/^G /s/.*/G : colored branch changes a line/" <M >N &&
70 git update-index --add --remove A B M N &&
71 git commit -m "white renames A->B, M->N" &&
74 sed -e "/^g /s/.*/g : red changes a line/" <A >B &&
75 sed -e "/^G /s/.*/G : colored branch changes a line/" <M >N &&
77 git update-index --add --remove A B M N &&
78 git commit -m "red renames A->B, M->N" &&
81 sed -e "/^g /s/.*/g : blue changes a line/" <A >C &&
82 sed -e "/^G /s/.*/G : colored branch changes a line/" <M >N &&
84 git update-index --add --remove A C M N &&
85 git commit -m "blue renames A->C, M->N" &&
87 git checkout change &&
88 sed -e "/^g /s/.*/g : changed line/" <A >A+ &&
90 git commit -q -a -m "changed" &&
92 git checkout change+rename &&
93 sed -e "/^g /s/.*/g : changed line/" <A >B &&
95 git update-index --add B &&
96 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 &&
245 GIT_MERGE_VERBOSITY=3 git merge change >out &&
246 test_i18ngrep "^Skipped B" out &&
247 git reset --hard HEAD^ &&
248 git checkout change &&
249 GIT_MERGE_VERBOSITY=3 git merge change+rename >out &&
250 test_i18ngrep "^Skipped B" out
253 test_expect_success
'setup for rename + d/f conflicts' '
255 git checkout --orphan dir-in-way &&
261 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >sub/file &&
262 echo foo >dir/file-in-the-way &&
264 git commit -m "Common commit" &&
266 echo 11 >>sub/file &&
267 echo more >>dir/file-in-the-way &&
269 git commit -m "Commit to merge, with dir in the way" &&
271 git checkout -b dir-not-in-way &&
272 git reset --soft HEAD^ &&
274 git commit -m "Commit to merge, with dir removed" -- dir sub/file &&
276 git checkout -b renamed-file-has-no-conflicts dir-in-way~1 &&
279 printf "1\n2\n3\n4\n5555\n6\n7\n8\n9\n10\n" >dir &&
281 git commit -m "Independent change" &&
283 git checkout -b renamed-file-has-conflicts dir-in-way~1 &&
285 git mv sub/file dir &&
288 git commit -m "Conflicting change"
291 printf "1\n2\n3\n4\n5555\n6\n7\n8\n9\n10\n11\n" >expected
293 test_expect_success
'Rename+D/F conflict; renamed file merges + dir not in way' '
295 git checkout -q renamed-file-has-no-conflicts^0 &&
296 git merge --strategy=recursive dir-not-in-way &&
299 test_cmp expected dir
302 test_expect_success
'Rename+D/F conflict; renamed file merges but dir in way' '
305 git checkout -q renamed-file-has-no-conflicts^0 &&
306 test_must_fail git merge --strategy=recursive dir-in-way >output &&
308 test_i18ngrep "CONFLICT (modify/delete): dir/file-in-the-way" output &&
309 test_i18ngrep "Auto-merging dir" output &&
310 test_i18ngrep "Adding as dir~HEAD instead" output &&
312 test 3 -eq "$(git ls-files -u | wc -l)" &&
313 test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
315 test_must_fail git diff --quiet &&
316 test_must_fail git diff --cached --quiet &&
318 test -f dir/file-in-the-way &&
320 test_cmp expected dir~HEAD
323 test_expect_success
'Same as previous, but merged other way' '
326 git checkout -q dir-in-way^0 &&
327 test_must_fail git merge --strategy=recursive renamed-file-has-no-conflicts >output 2>errors &&
329 ! grep "error: refusing to lose untracked file at" errors &&
330 test_i18ngrep "CONFLICT (modify/delete): dir/file-in-the-way" output &&
331 test_i18ngrep "Auto-merging dir" output &&
332 test_i18ngrep "Adding as dir~renamed-file-has-no-conflicts instead" output &&
334 test 3 -eq "$(git ls-files -u | wc -l)" &&
335 test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
337 test_must_fail git diff --quiet &&
338 test_must_fail git diff --cached --quiet &&
340 test -f dir/file-in-the-way &&
341 test -f dir~renamed-file-has-no-conflicts &&
342 test_cmp expected dir~renamed-file-has-no-conflicts
345 cat >expected
<<\EOF
&&
360 >>>>>>> dir-not-in-way:sub/file
363 test_expect_success 'Rename+D/F conflict; renamed file cannot merge, dir not in way' '
366 git checkout -q renamed-file-has-conflicts^0 &&
367 test_must_fail git merge --strategy=recursive dir-not-in-way &&
369 test 3 -eq "$(git ls-files -u | wc -l)" &&
370 test 3 -eq "$(git ls-files -u dir | wc -l)" &&
372 test_must_fail git diff --quiet &&
373 test_must_fail git diff --cached --quiet &&
376 test_cmp expected dir
379 test_expect_success 'Rename+D/F conflict; renamed file cannot merge and dir in the way' '
380 modify s/dir-not-in-way/dir-in-way/ expected &&
384 git checkout -q renamed-file-has-conflicts^0 &&
385 test_must_fail git merge --strategy=recursive dir-in-way &&
387 test 5 -eq "$(git ls-files -u | wc -l)" &&
388 test 3 -eq "$(git ls-files -u dir | grep -v file-in-the-way | wc -l)" &&
389 test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
391 test_must_fail git diff --quiet &&
392 test_must_fail git diff --cached --quiet &&
394 test -f dir/file-in-the-way &&
396 test_cmp expected dir~HEAD
399 cat >expected <<\EOF &&
410 <<<<<<< HEAD:sub/file
414 >>>>>>> renamed-file-has-conflicts:dir
417 test_expect_success 'Same as previous
, but merged other way
' '
420 git checkout
-q dir-in-way^
0 &&
421 test_must_fail git merge
--strategy=recursive renamed-file-has-conflicts
&&
423 test 5 -eq "$(git ls-files -u | wc -l)" &&
424 test 3 -eq "$(git ls-files -u dir | grep -v file-in-the-way | wc -l)" &&
425 test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
427 test_must_fail git
diff --quiet &&
428 test_must_fail git
diff --cached --quiet &&
430 test -f dir
/file-in-the-way
&&
431 test -f dir~renamed-file-has-conflicts
&&
432 test_cmp expected dir~renamed-file-has-conflicts
435 test_expect_success 'setup both rename
source and destination involved
in D
/F conflict
' '
437 git checkout
--orphan rename-dest
&&
442 echo stuff
>one
/file &&
444 git commit
-m "Common commit" &&
446 git
mv one
/file destdir
&&
447 git commit
-m "Renamed to destdir" &&
449 git checkout
-b source-conflict HEAD~
1 &&
452 touch one destdir
/foo
&&
454 git commit
-m "Conflicts in the way"
457 test_expect_success 'both rename
source and destination involved
in D
/F conflict
' '
460 git checkout
-q rename-dest^
0 &&
461 test_must_fail git merge
--strategy=recursive source-conflict
&&
463 test 1 -eq "$(git ls-files -u | wc -l)" &&
465 test_must_fail git
diff --quiet &&
467 test -f destdir
/foo
&&
469 test -f destdir~HEAD
&&
470 test "stuff" = "$(cat destdir~HEAD)"
473 test_expect_success 'setup pair rename to parent of other
(D
/F conflicts
)' '
475 git checkout
--orphan rename-two
&&
481 echo stuff
>one
/file &&
482 echo other
>two
/file &&
484 git commit
-m "Common commit" &&
487 git
mv two
/file one
&&
488 git commit
-m "Rename two/file -> one" &&
490 git checkout
-b rename-one HEAD~
1 &&
492 git
mv one
/file two
&&
494 git commit
-m "Rename one/file -> two"
497 test_expect_success 'pair rename to parent of other
(D
/F conflicts
) w
/ untracked dir
' '
498 git checkout
-q rename-one^
0 &&
500 test_must_fail git merge
--strategy=recursive rename-two
&&
502 test 2 -eq "$(git ls-files -u | wc -l)" &&
503 test 1 -eq "$(git ls-files -u one | wc -l)" &&
504 test 1 -eq "$(git ls-files -u two | wc -l)" &&
506 test_must_fail git
diff --quiet &&
508 test 4 -eq $
(find . |
grep -v .git |
wc -l) &&
511 test -f one~rename-two
&&
513 test "other" = $
(cat one~rename-two
) &&
514 test "stuff" = $
(cat two
)
517 test_expect_success 'pair rename to parent of other
(D
/F conflicts
) w
/ clean start
' '
520 test_must_fail git merge
--strategy=recursive rename-two
&&
522 test 2 -eq "$(git ls-files -u | wc -l)" &&
523 test 1 -eq "$(git ls-files -u one | wc -l)" &&
524 test 1 -eq "$(git ls-files -u two | wc -l)" &&
526 test_must_fail git
diff --quiet &&
528 test 3 -eq $
(find . |
grep -v .git |
wc -l) &&
532 test "other" = $
(cat one
) &&
533 test "stuff" = $
(cat two
)
536 test_expect_success 'setup rename of one
file to two
, with directories
in the way
' '
538 git checkout
--orphan first-rename
&&
542 echo stuff
>original
&&
544 git commit
-m "Common commit" &&
549 git
mv original one
&&
550 git commit
-m "Put two/file in the way, rename to one" &&
552 git checkout
-b second-rename HEAD~
1 &&
556 git
mv original two
&&
557 git commit
-m "Put one/file in the way, rename to two"
560 test_expect_success 'check handling of differently renamed
file with D
/F conflicts
' '
561 git checkout
-q first-rename^
0 &&
562 test_must_fail git merge
--strategy=recursive second-rename
&&
564 test 5 -eq "$(git ls-files -s | wc -l)" &&
565 test 3 -eq "$(git ls-files -u | wc -l)" &&
566 test 1 -eq "$(git ls-files -u one | wc -l)" &&
567 test 1 -eq "$(git ls-files -u two | wc -l)" &&
568 test 1 -eq "$(git ls-files -u original | wc -l)" &&
569 test 2 -eq "$(git ls-files -o | wc -l)" &&
574 test -f two~second-rename
&&
578 test_expect_success 'setup rename one
file to two
; directories moving out of the way
' '
580 git checkout
--orphan first-rename-redo
&&
584 echo stuff
>original
&&
586 touch one
/file two
/file &&
588 git commit
-m "Common commit" &&
591 git
mv original one
&&
592 git commit
-m "Rename to one" &&
594 git checkout
-b second-rename-redo HEAD~
1 &&
596 git
mv original two
&&
597 git commit
-m "Rename to two"
600 test_expect_success 'check handling of differently renamed
file with D
/F conflicts
' '
601 git checkout
-q first-rename-redo^
0 &&
602 test_must_fail git merge
--strategy=recursive second-rename-redo
&&
604 test 3 -eq "$(git ls-files -u | wc -l)" &&
605 test 1 -eq "$(git ls-files -u one | wc -l)" &&
606 test 1 -eq "$(git ls-files -u two | wc -l)" &&
607 test 1 -eq "$(git ls-files -u original | wc -l)" &&
608 test 0 -eq "$(git ls-files -o | wc -l)" &&
615 test_expect_success 'setup avoid unnecessary update
, normal rename
' '
617 git checkout
--orphan avoid-unnecessary-update-1
&&
621 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >original
&&
623 git commit
-m "Common commit" &&
625 git
mv original rename
&&
628 git commit
-m "Renamed and modified" &&
630 git checkout
-b merge-branch-1 HEAD~
1 &&
631 echo "random content" >random-file
&&
633 git commit
-m "Random, unrelated changes"
636 test_expect_success 'avoid unnecessary update
, normal rename
' '
637 git checkout
-q avoid-unnecessary-update-1^
0 &&
638 test-chmtime
=1000000000 rename
&&
639 test-chmtime
-v +0 rename
>expect
&&
640 git merge merge-branch-1
&&
641 test-chmtime
-v +0 rename
>actual
&&
642 test_cmp expect actual
# "rename" should have stayed intact
645 test_expect_success 'setup to
test avoiding unnecessary update
, with D
/F conflict
' '
647 git checkout
--orphan avoid-unnecessary-update-2
&&
652 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >df
/file &&
654 git commit
-m "Common commit" &&
656 git
mv df
/file temp
&&
661 git commit
-m "Renamed and modified" &&
663 git checkout
-b merge-branch-2 HEAD~
1 &&
665 git add unrelated-change
&&
666 git commit
-m "Only unrelated changes"
669 test_expect_success 'avoid unnecessary update
, with D
/F conflict
' '
670 git checkout
-q avoid-unnecessary-update-2^
0 &&
671 test-chmtime
=1000000000 df
&&
672 test-chmtime
-v +0 df
>expect
&&
673 git merge merge-branch-2
&&
674 test-chmtime
-v +0 df
>actual
&&
675 test_cmp expect actual
# "df" should have stayed intact
678 test_expect_success 'setup avoid unnecessary update
, dir-
>(file,nothing
)' '
690 git checkout
-b side
&&
694 git checkout master
&&
698 git commit
-m "Add a newfile"
701 test_expect_success 'avoid unnecessary update
, dir-
>(file,nothing
)' '
702 git checkout
-q master^
0 &&
703 test-chmtime
=1000000000 df
&&
704 test-chmtime
-v +0 df
>expect
&&
706 test-chmtime
-v +0 df
>actual
&&
707 test_cmp expect actual
# "df" should have stayed intact
710 test_expect_success 'setup avoid unnecessary update
, modify
/delete
' '
721 git checkout
-b side
&&
723 git commit
-m "Delete file" &&
725 git checkout master
&&
728 git commit
-m "Modify file"
731 test_expect_success 'avoid unnecessary update
, modify
/delete
' '
732 git checkout
-q master^
0 &&
733 test-chmtime
=1000000000 file &&
734 test-chmtime
-v +0 file >expect
&&
735 test_must_fail git merge side
&&
736 test-chmtime
-v +0 file >actual
&&
737 test_cmp expect actual
# "file" should have stayed intact
740 test_expect_success 'setup avoid unnecessary update
, rename
/add-dest
' '
746 printf "1\n2\n3\n4\n5\n6\n7\n8\n" >file &&
750 git checkout
-b side
&&
753 git commit
-m "Add file copy" &&
755 git checkout master
&&
756 git
mv file newfile
&&
757 git commit
-m "Rename file"
760 test_expect_success 'avoid unnecessary update
, rename
/add-dest
' '
761 git checkout
-q master^
0 &&
762 test-chmtime
=1000000000 newfile
&&
763 test-chmtime
-v +0 newfile
>expect
&&
765 test-chmtime
-v +0 newfile
>actual
&&
766 test_cmp expect actual
# "file" should have stayed intact
769 test_expect_success 'setup merge of rename
+ small change
' '
771 git checkout
--orphan rename-plus-small-change
&&
775 echo ORIGINAL
>file &&
779 git commit
-m Initial
&&
780 git checkout
-b rename_branch
&&
781 git
mv file renamed_file
&&
782 git commit
-m Rename
&&
783 git checkout rename-plus-small-change
&&
784 echo NEW-VERSION
>file &&
785 git commit
-a -m Reformat
788 test_expect_success 'merge rename
+ small change
' '
789 git merge rename_branch
&&
791 test 1 -eq $
(git ls-files
-s |
wc -l) &&
792 test 0 -eq $
(git ls-files
-o |
wc -l) &&
793 test $
(git rev-parse HEAD
:renamed_file
) = $
(git rev-parse HEAD~
1:file)
796 test_expect_success 'setup
for use of extended merge markers
' '
802 printf "1\n2\n3\n4\n5\n6\n7\n8\n" >original_file
&&
803 git add original_file
&&
806 git checkout
-b rename
&&
807 echo 9 >>original_file
&&
808 git add original_file
&&
809 git
mv original_file renamed_file
&&
812 git checkout master
&&
813 echo 8.5 >>original_file
&&
814 git add original_file
&&
818 cat >expected <<\EOF &&
827 <<<<<<< HEAD:renamed_file
831 >>>>>>> master^0:original_file
834 test_expect_success 'merge master into rename has correct extended markers
' '
835 git checkout rename^
0 &&
836 test_must_fail git merge
-s recursive master^
0 &&
837 test_cmp expected renamed_file
840 cat >expected <<\EOF &&
849 <<<<<<< HEAD:original_file
853 >>>>>>> rename^0:renamed_file
856 test_expect_success 'merge rename into master has correct extended markers
' '
858 git checkout master^
0 &&
859 test_must_fail git merge
-s recursive rename^
0 &&
860 test_cmp expected renamed_file
863 test_expect_success 'setup spurious
"refusing to lose untracked" message
' '
870 printf "1\n2\n3\n4\n5\n6\n7\n8\n" >original_file
&&
871 git add irrelevant_file original_file
&&
874 git checkout
-b rename
&&
875 git
mv original_file renamed_file
&&
878 git checkout master
&&
879 git
rm original_file
&&
883 test_expect_success 'no spurious
"refusing to lose untracked" message
' '
884 git checkout master^
0 &&
885 test_must_fail git merge rename^
0 2>errors.txt
&&
886 ! grep "refusing to lose untracked file" errors.txt
889 test_expect_success 'do not follow renames
for empty files
' '
890 git checkout
-f -b empty-base
&&
893 git commit
-m base
&&
894 echo content
>empty1
&&
896 git commit
-m fill
&&
897 git checkout
-b empty-topic HEAD^
&&
898 git
mv empty1 empty2
&&
899 git commit
-m rename
&&
900 test_must_fail git merge empty-base
&&
902 test_cmp expect empty2