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 | grep "^Skipped B" &&
246 git reset --hard HEAD^ &&
247 git checkout change &&
248 GIT_MERGE_VERBOSITY=3 git merge change+rename | grep "^Skipped B"
251 test_expect_success
'setup for rename + d/f conflicts' '
253 git checkout --orphan dir-in-way &&
258 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >sub/file &&
259 echo foo >dir/file-in-the-way &&
261 git commit -m "Common commmit" &&
263 echo 11 >>sub/file &&
264 echo more >>dir/file-in-the-way &&
266 git commit -m "Commit to merge, with dir in the way" &&
268 git checkout -b dir-not-in-way &&
269 git reset --soft HEAD^ &&
271 git commit -m "Commit to merge, with dir removed" -- dir sub/file &&
273 git checkout -b renamed-file-has-no-conflicts dir-in-way~1 &&
276 printf "1\n2\n3\n4\n5555\n6\n7\n8\n9\n10\n" >dir &&
278 git commit -m "Independent change" &&
280 git checkout -b renamed-file-has-conflicts dir-in-way~1 &&
282 git mv sub/file dir &&
285 git commit -m "Conflicting change"
288 printf "1\n2\n3\n4\n5555\n6\n7\n8\n9\n10\n11\n" >expected
290 test_expect_success
'Rename+D/F conflict; renamed file merges + dir not in way' '
292 git checkout -q renamed-file-has-no-conflicts^0 &&
293 git merge --strategy=recursive dir-not-in-way &&
296 test_cmp expected dir
299 test_expect_success
'Rename+D/F conflict; renamed file merges but dir in way' '
302 git checkout -q renamed-file-has-no-conflicts^0 &&
303 test_must_fail git merge --strategy=recursive dir-in-way >output &&
305 grep "CONFLICT (delete/modify): dir/file-in-the-way" output &&
306 grep "Auto-merging dir" output &&
307 grep "Adding as dir~HEAD instead" output &&
309 test 2 -eq "$(git ls-files -u | wc -l)" &&
310 test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
312 test_must_fail git diff --quiet &&
313 test_must_fail git diff --cached --quiet &&
315 test -f dir/file-in-the-way &&
317 test_cmp expected dir~HEAD
320 test_expect_success
'Same as previous, but merged other way' '
323 git checkout -q dir-in-way^0 &&
324 test_must_fail git merge --strategy=recursive renamed-file-has-no-conflicts >output 2>errors &&
326 ! grep "error: refusing to lose untracked file at" errors &&
327 grep "CONFLICT (delete/modify): dir/file-in-the-way" output &&
328 grep "Auto-merging dir" output &&
329 grep "Adding as dir~renamed-file-has-no-conflicts instead" output &&
331 test 2 -eq "$(git ls-files -u | wc -l)" &&
332 test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
334 test_must_fail git diff --quiet &&
335 test_must_fail git diff --cached --quiet &&
337 test -f dir/file-in-the-way &&
338 test -f dir~renamed-file-has-no-conflicts &&
339 test_cmp expected dir~renamed-file-has-no-conflicts
342 cat >expected
<<\EOF
&&
357 >>>>>>> dir-not-in-way
360 test_expect_success 'Rename+D/F conflict; renamed file cannot merge, dir not in way' '
363 git checkout -q renamed-file-has-conflicts^0 &&
364 test_must_fail git merge --strategy=recursive dir-not-in-way &&
366 test 3 -eq "$(git ls-files -u | wc -l)" &&
367 test 3 -eq "$(git ls-files -u dir | wc -l)" &&
369 test_must_fail git diff --quiet &&
370 test_must_fail git diff --cached --quiet &&
373 test_cmp expected dir
376 test_expect_success 'Rename+D/F conflict; renamed file cannot merge and dir in the way' '
377 modify s/dir-not-in-way/dir-in-way/ expected &&
381 git checkout -q renamed-file-has-conflicts^0 &&
382 test_must_fail git merge --strategy=recursive dir-in-way &&
384 test 5 -eq "$(git ls-files -u | wc -l)" &&
385 test 3 -eq "$(git ls-files -u dir | grep -v file-in-the-way | wc -l)" &&
386 test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
388 test_must_fail git diff --quiet &&
389 test_must_fail git diff --cached --quiet &&
391 test -f dir/file-in-the-way &&
393 test_cmp expected dir~HEAD
396 cat >expected <<\EOF &&
411 >>>>>>> renamed-file-has-conflicts
414 test_expect_success 'Same as previous
, but merged other way
' '
417 git checkout
-q dir-in-way^
0 &&
418 test_must_fail git merge
--strategy=recursive renamed-file-has-conflicts
&&
420 test 5 -eq "$(git ls-files -u | wc -l)" &&
421 test 3 -eq "$(git ls-files -u dir | grep -v file-in-the-way | wc -l)" &&
422 test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
424 test_must_fail git
diff --quiet &&
425 test_must_fail git
diff --cached --quiet &&
427 test -f dir
/file-in-the-way
&&
428 test -f dir~renamed-file-has-conflicts
&&
429 test_cmp expected dir~renamed-file-has-conflicts
432 test_expect_success 'setup both rename
source and destination involved
in D
/F conflict
' '
434 git checkout
--orphan rename-dest
&&
439 echo stuff
>one
/file &&
441 git commit
-m "Common commmit" &&
443 git
mv one
/file destdir
&&
444 git commit
-m "Renamed to destdir" &&
446 git checkout
-b source-conflict HEAD~
1 &&
449 touch one destdir
/foo
&&
451 git commit
-m "Conflicts in the way"
454 test_expect_success 'both rename
source and destination involved
in D
/F conflict
' '
457 git checkout
-q rename-dest^
0 &&
458 test_must_fail git merge
--strategy=recursive source-conflict
&&
460 test 1 -eq "$(git ls-files -u | wc -l)" &&
462 test_must_fail git
diff --quiet &&
464 test -f destdir
/foo
&&
466 test -f destdir~HEAD
&&
467 test "stuff" = "$(cat destdir~HEAD)"
470 test_expect_success 'setup pair rename to parent of other
(D
/F conflicts
)' '
472 git checkout
--orphan rename-two
&&
478 echo stuff
>one
/file &&
479 echo other
>two
/file &&
481 git commit
-m "Common commmit" &&
484 git
mv two
/file one
&&
485 git commit
-m "Rename two/file -> one" &&
487 git checkout
-b rename-one HEAD~
1 &&
489 git
mv one
/file two
&&
491 git commit
-m "Rename one/file -> two"
494 test_expect_success 'pair rename to parent of other
(D
/F conflicts
) w
/ untracked dir
' '
495 git checkout
-q rename-one^
0 &&
497 test_must_fail git merge
--strategy=recursive rename-two
&&
499 test 2 -eq "$(git ls-files -u | wc -l)" &&
500 test 1 -eq "$(git ls-files -u one | wc -l)" &&
501 test 1 -eq "$(git ls-files -u two | wc -l)" &&
503 test_must_fail git
diff --quiet &&
505 test 4 -eq $
(find . |
grep -v .git |
wc -l) &&
508 test -f one~rename-two
&&
510 test "other" = $
(cat one~rename-two
) &&
511 test "stuff" = $
(cat two
)
514 test_expect_success 'pair rename to parent of other
(D
/F conflicts
) w
/ clean start
' '
517 test_must_fail git merge
--strategy=recursive rename-two
&&
519 test 2 -eq "$(git ls-files -u | wc -l)" &&
520 test 1 -eq "$(git ls-files -u one | wc -l)" &&
521 test 1 -eq "$(git ls-files -u two | wc -l)" &&
523 test_must_fail git
diff --quiet &&
525 test 3 -eq $
(find . |
grep -v .git |
wc -l) &&
529 test "other" = $
(cat one
) &&
530 test "stuff" = $
(cat two
)
533 test_expect_success 'setup rename of one
file to two
, with directories
in the way
' '
535 git checkout
--orphan first-rename
&&
539 echo stuff
>original
&&
541 git commit
-m "Common commmit" &&
546 git
mv original one
&&
547 git commit
-m "Put two/file in the way, rename to one" &&
549 git checkout
-b second-rename HEAD~
1 &&
553 git
mv original two
&&
554 git commit
-m "Put one/file in the way, rename to two"
557 test_expect_success 'check handling of differently renamed
file with D
/F conflicts
' '
558 git checkout
-q first-rename^
0 &&
559 test_must_fail git merge
--strategy=recursive second-rename
&&
561 test 5 -eq "$(git ls-files -s | wc -l)" &&
562 test 3 -eq "$(git ls-files -u | wc -l)" &&
563 test 1 -eq "$(git ls-files -u one | wc -l)" &&
564 test 1 -eq "$(git ls-files -u two | wc -l)" &&
565 test 1 -eq "$(git ls-files -u original | wc -l)" &&
566 test 2 -eq "$(git ls-files -o | wc -l)" &&
571 test -f two~second-rename
&&
575 test_expect_success 'setup rename one
file to two
; directories moving out of the way
' '
577 git checkout
--orphan first-rename-redo
&&
581 echo stuff
>original
&&
583 touch one
/file two
/file &&
585 git commit
-m "Common commmit" &&
588 git
mv original one
&&
589 git commit
-m "Rename to one" &&
591 git checkout
-b second-rename-redo HEAD~
1 &&
593 git
mv original two
&&
594 git commit
-m "Rename to two"
597 test_expect_success 'check handling of differently renamed
file with D
/F conflicts
' '
598 git checkout
-q first-rename-redo^
0 &&
599 test_must_fail git merge
--strategy=recursive second-rename-redo
&&
601 test 3 -eq "$(git ls-files -u | wc -l)" &&
602 test 1 -eq "$(git ls-files -u one | wc -l)" &&
603 test 1 -eq "$(git ls-files -u two | wc -l)" &&
604 test 1 -eq "$(git ls-files -u original | wc -l)" &&
605 test 0 -eq "$(git ls-files -o | wc -l)" &&
612 test_expect_success 'setup avoid unnecessary update
, normal rename
' '
614 git checkout
--orphan avoid-unnecessary-update-1
&&
618 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >original
&&
620 git commit
-m "Common commmit" &&
622 git
mv original rename
&&
625 git commit
-m "Renamed and modified" &&
627 git checkout
-b merge-branch-1 HEAD~
1 &&
628 echo "random content" >random-file
&&
630 git commit
-m "Random, unrelated changes"
633 test_expect_success 'avoid unnecessary update
, normal rename
' '
634 git checkout
-q avoid-unnecessary-update-1^
0 &&
635 test-chmtime
=1000000000 rename
&&
636 test-chmtime
-v +0 rename
>expect
&&
637 git merge merge-branch-1
&&
638 test-chmtime
-v +0 rename
>actual
&&
639 test_cmp expect actual
# "rename" should have stayed intact
642 test_expect_success 'setup to
test avoiding unnecessary update
, with D
/F conflict
' '
644 git checkout
--orphan avoid-unnecessary-update-2
&&
649 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >df
/file &&
651 git commit
-m "Common commmit" &&
653 git
mv df
/file temp
&&
658 git commit
-m "Renamed and modified" &&
660 git checkout
-b merge-branch-2 HEAD~
1 &&
662 git add unrelated-change
&&
663 git commit
-m "Only unrelated changes"
666 test_expect_failure 'avoid unnecessary update
, with D
/F conflict
' '
667 git checkout
-q avoid-unnecessary-update-2^
0 &&
668 test-chmtime
=1000000000 df
&&
669 test-chmtime
-v +0 df
>expect
&&
670 git merge merge-branch-2
&&
671 test-chmtime
-v +0 df
>actual
&&
672 test_cmp expect actual
# "df" should have stayed intact