worktree: drop get_worktrees() special-purpose sorting option
[git.git] / t / t6022-merge-rename.sh
blobbbbba3dcbf0de73a65f0c7258c6b5c5b3278e542
1 #!/bin/sh
3 test_description='Merge-recursive merging renames'
4 . ./test-lib.sh
6 modify () {
7 sed -e "$1" <"$2" >"$2.x" &&
8 mv "$2.x" "$2"
11 test_expect_success 'setup' '
12 cat >A <<-\EOF &&
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
28 EOF
30 cat >M <<-\EOF &&
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
46 EOF
48 git add A M &&
49 git commit -m "initial has A and M" &&
50 git branch white &&
51 git branch red &&
52 git branch blue &&
53 git branch yellow &&
54 git branch change &&
55 git branch change+rename &&
57 sed -e "/^g /s/.*/g : master changes a line/" <A >A+ &&
58 mv A+ A &&
59 git commit -a -m "master updates A" &&
61 git checkout yellow &&
62 rm -f M &&
63 git commit -a -m "yellow removes M" &&
65 git checkout white &&
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 &&
68 rm -f A M &&
69 git update-index --add --remove A B M N &&
70 git commit -m "white renames A->B, M->N" &&
72 git checkout red &&
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 &&
75 rm -f A M &&
76 git update-index --add --remove A B M N &&
77 git commit -m "red renames A->B, M->N" &&
79 git checkout blue &&
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 &&
82 rm -f A M &&
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+ &&
88 mv A+ A &&
89 git commit -q -a -m "changed" &&
91 git checkout change+rename &&
92 sed -e "/^g /s/.*/g : changed line/" <A >B &&
93 rm A &&
94 git update-index --add B &&
95 git commit -q -a -m "changed and renamed" &&
97 git checkout master
100 test_expect_success 'pull renaming branch into unrenaming one' \
102 git show-branch &&
103 test_expect_code 1 git pull . white &&
104 git ls-files -s &&
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 &&
109 sed -ne "/^g/{
112 }" B | grep master &&
113 git diff --exit-code white N
116 test_expect_success 'pull renaming branch into another renaming one' \
118 rm -f B &&
119 git reset --hard &&
120 git checkout red &&
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 &&
126 sed -ne "/^g/{
129 }" B | grep red &&
130 git diff --exit-code white N
133 test_expect_success 'pull unrenaming branch into renaming one' \
135 git reset --hard &&
136 git show-branch &&
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 &&
142 sed -ne "/^g/{
145 }" B | grep red &&
146 git diff --exit-code white N
149 test_expect_success 'pull conflicting renames' \
151 git reset --hard &&
152 git show-branch &&
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 &&
162 sed -ne "/^g/{
165 }" B | grep red &&
166 git diff --exit-code white N
169 test_expect_success 'interference with untracked working tree file' '
170 git reset --hard &&
171 git show-branch &&
172 echo >A this file should not matter &&
173 test_expect_code 1 git pull . white &&
174 test_path_is_file A
177 test_expect_success 'interference with untracked working tree file' '
178 git reset --hard &&
179 git checkout white &&
180 git show-branch &&
181 rm -f A &&
182 echo >A this file should not matter &&
183 test_expect_code 1 git pull . red &&
184 test_path_is_file A
187 test_expect_success 'interference with untracked working tree file' '
188 git reset --hard &&
189 rm -f A M &&
190 git checkout -f master &&
191 git tag -f anchor &&
192 git show-branch &&
193 git pull . yellow &&
194 test_path_is_missing M &&
195 git reset --hard anchor
198 test_expect_success 'updated working tree file should prevent the merge' '
199 git reset --hard &&
200 rm -f A M &&
201 git checkout -f master &&
202 git tag -f anchor &&
203 git show-branch &&
204 echo >>M one line addition &&
205 cat M >M.saved &&
206 test_expect_code 128 git pull . yellow &&
207 test_cmp M M.saved &&
208 rm -f M.saved
211 test_expect_success 'updated working tree file should prevent the merge' '
212 git reset --hard &&
213 rm -f A M &&
214 git checkout -f master &&
215 git tag -f anchor &&
216 git show-branch &&
217 echo >>M one line addition &&
218 cat M >M.saved &&
219 git update-index M &&
220 test_expect_code 128 git pull . yellow &&
221 test_cmp M M.saved &&
222 rm -f M.saved
225 test_expect_success 'interference with untracked working tree file' '
226 git reset --hard &&
227 rm -f A M &&
228 git checkout -f yellow &&
229 git tag -f anchor &&
230 git show-branch &&
231 echo >M this file should not matter &&
232 git pull . master &&
233 test_path_is_file M &&
235 git ls-files -s |
236 grep M
237 } &&
238 git reset --hard anchor
241 test_expect_success 'merge of identical changes in a renamed file' '
242 rm -f A M N &&
243 git reset --hard &&
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' '
266 git reset --hard &&
267 git checkout --orphan dir-in-way &&
268 git rm -rf . &&
269 git clean -fdqx &&
271 mkdir sub &&
272 mkdir dir &&
273 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >sub/file &&
274 echo foo >dir/file-in-the-way &&
275 git add -A &&
276 git commit -m "Common commit" &&
278 echo 11 >>sub/file &&
279 echo more >>dir/file-in-the-way &&
280 git add -u &&
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^ &&
285 git rm -rf dir &&
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 &&
289 git rm -rf dir &&
290 git rm sub/file &&
291 printf "1\n2\n3\n4\n5555\n6\n7\n8\n9\n10\n" >dir &&
292 git add dir &&
293 git commit -m "Independent change" &&
295 git checkout -b renamed-file-has-conflicts dir-in-way~1 &&
296 git rm -rf dir &&
297 git mv sub/file dir &&
298 echo 12 >>dir &&
299 git add dir &&
300 git commit -m "Conflicting change"
303 test_expect_success 'Rename+D/F conflict; renamed file merges + dir not in way' '
304 git reset --hard &&
305 git checkout -q renamed-file-has-no-conflicts^0 &&
307 git merge --strategy=recursive dir-not-in-way &&
309 git diff --quiet &&
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' '
316 git reset --hard &&
317 rm -rf dir~* &&
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' '
337 git reset --hard &&
338 rm -rf dir~* &&
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' '
359 git reset --hard &&
360 rm -rf dir~* &&
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 &&
382 <<<<<<< HEAD:dir
384 =======
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 &&
394 git reset --hard &&
395 rm -rf dir~* &&
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 test 3 -eq "$(git ls-files -u dir | grep -v file-in-the-way | wc -l)" &&
401 test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
403 test_must_fail git diff --quiet &&
404 test_must_fail git diff --cached --quiet &&
406 test_path_is_file dir/file-in-the-way &&
407 test_path_is_file dir~HEAD &&
408 test_cmp expected dir~HEAD
411 test_expect_success 'Same as previous, but merged other way' '
412 git reset --hard &&
413 rm -rf dir~* &&
414 git checkout -q dir-in-way^0 &&
415 test_must_fail git merge --strategy=recursive renamed-file-has-conflicts &&
417 test 5 -eq "$(git ls-files -u | wc -l)" &&
418 test 3 -eq "$(git ls-files -u dir | grep -v file-in-the-way | wc -l)" &&
419 test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
421 test_must_fail git diff --quiet &&
422 test_must_fail git diff --cached --quiet &&
424 test_path_is_file dir/file-in-the-way &&
425 test_path_is_file dir~renamed-file-has-conflicts &&
426 cat >expected <<-\EOF &&
437 <<<<<<< HEAD:sub/file
439 =======
441 >>>>>>> renamed-file-has-conflicts:dir
443 test_cmp expected dir~renamed-file-has-conflicts
446 test_expect_success 'setup both rename source and destination involved in D/F conflict' '
447 git reset --hard &&
448 git checkout --orphan rename-dest &&
449 git rm -rf . &&
450 git clean -fdqx &&
452 mkdir one &&
453 echo stuff >one/file &&
454 git add -A &&
455 git commit -m "Common commit" &&
457 git mv one/file destdir &&
458 git commit -m "Renamed to destdir" &&
460 git checkout -b source-conflict HEAD~1 &&
461 git rm -rf one &&
462 mkdir destdir &&
463 touch one destdir/foo &&
464 git add -A &&
465 git commit -m "Conflicts in the way"
468 test_expect_success 'both rename source and destination involved in D/F conflict' '
469 git reset --hard &&
470 rm -rf dir~* &&
471 git checkout -q rename-dest^0 &&
472 test_must_fail git merge --strategy=recursive source-conflict &&
474 test 1 -eq "$(git ls-files -u | wc -l)" &&
476 test_must_fail git diff --quiet &&
478 test_path_is_file destdir/foo &&
479 test_path_is_file one &&
480 test_path_is_file destdir~HEAD &&
481 test "stuff" = "$(cat destdir~HEAD)"
484 test_expect_success 'setup pair rename to parent of other (D/F conflicts)' '
485 git reset --hard &&
486 git checkout --orphan rename-two &&
487 git rm -rf . &&
488 git clean -fdqx &&
490 mkdir one &&
491 mkdir two &&
492 echo stuff >one/file &&
493 echo other >two/file &&
494 git add -A &&
495 git commit -m "Common commit" &&
497 git rm -rf one &&
498 git mv two/file one &&
499 git commit -m "Rename two/file -> one" &&
501 git checkout -b rename-one HEAD~1 &&
502 git rm -rf two &&
503 git mv one/file two &&
504 rm -r one &&
505 git commit -m "Rename one/file -> two"
508 test_expect_success 'pair rename to parent of other (D/F conflicts) w/ untracked dir' '
509 git checkout -q rename-one^0 &&
510 mkdir one &&
511 test_must_fail git merge --strategy=recursive rename-two &&
513 test 2 -eq "$(git ls-files -u | wc -l)" &&
514 test 1 -eq "$(git ls-files -u one | wc -l)" &&
515 test 1 -eq "$(git ls-files -u two | wc -l)" &&
517 test_must_fail git diff --quiet &&
519 test 4 -eq $(find . | grep -v .git | wc -l) &&
521 test_path_is_dir one &&
522 test_path_is_file one~rename-two &&
523 test_path_is_file two &&
524 test "other" = $(cat one~rename-two) &&
525 test "stuff" = $(cat two)
528 test_expect_success 'pair rename to parent of other (D/F conflicts) w/ clean start' '
529 git reset --hard &&
530 git clean -fdqx &&
531 test_must_fail git merge --strategy=recursive rename-two &&
533 test 2 -eq "$(git ls-files -u | wc -l)" &&
534 test 1 -eq "$(git ls-files -u one | wc -l)" &&
535 test 1 -eq "$(git ls-files -u two | wc -l)" &&
537 test_must_fail git diff --quiet &&
539 test 3 -eq $(find . | grep -v .git | wc -l) &&
541 test_path_is_file one &&
542 test_path_is_file two &&
543 test "other" = $(cat one) &&
544 test "stuff" = $(cat two)
547 test_expect_success 'setup rename of one file to two, with directories in the way' '
548 git reset --hard &&
549 git checkout --orphan first-rename &&
550 git rm -rf . &&
551 git clean -fdqx &&
553 echo stuff >original &&
554 git add -A &&
555 git commit -m "Common commit" &&
557 mkdir two &&
558 >two/file &&
559 git add two/file &&
560 git mv original one &&
561 git commit -m "Put two/file in the way, rename to one" &&
563 git checkout -b second-rename HEAD~1 &&
564 mkdir one &&
565 >one/file &&
566 git add one/file &&
567 git mv original two &&
568 git commit -m "Put one/file in the way, rename to two"
571 test_expect_success 'check handling of differently renamed file with D/F conflicts' '
572 git checkout -q first-rename^0 &&
573 test_must_fail git merge --strategy=recursive second-rename &&
575 test 5 -eq "$(git ls-files -s | wc -l)" &&
576 test 3 -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)" &&
579 test 1 -eq "$(git ls-files -u original | wc -l)" &&
580 test 2 -eq "$(git ls-files -o | wc -l)" &&
582 test_path_is_file one/file &&
583 test_path_is_file two/file &&
584 test_path_is_file one~HEAD &&
585 test_path_is_file two~second-rename &&
586 test_path_is_missing original
589 test_expect_success 'setup rename one file to two; directories moving out of the way' '
590 git reset --hard &&
591 git checkout --orphan first-rename-redo &&
592 git rm -rf . &&
593 git clean -fdqx &&
595 echo stuff >original &&
596 mkdir one two &&
597 touch one/file two/file &&
598 git add -A &&
599 git commit -m "Common commit" &&
601 git rm -rf one &&
602 git mv original one &&
603 git commit -m "Rename to one" &&
605 git checkout -b second-rename-redo HEAD~1 &&
606 git rm -rf two &&
607 git mv original two &&
608 git commit -m "Rename to two"
611 test_expect_success 'check handling of differently renamed file with D/F conflicts' '
612 git checkout -q first-rename-redo^0 &&
613 test_must_fail git merge --strategy=recursive second-rename-redo &&
615 test 3 -eq "$(git ls-files -u | wc -l)" &&
616 test 1 -eq "$(git ls-files -u one | wc -l)" &&
617 test 1 -eq "$(git ls-files -u two | wc -l)" &&
618 test 1 -eq "$(git ls-files -u original | wc -l)" &&
619 test 0 -eq "$(git ls-files -o | wc -l)" &&
621 test_path_is_file one &&
622 test_path_is_file two &&
623 test_path_is_missing original
626 test_expect_success 'setup avoid unnecessary update, normal rename' '
627 git reset --hard &&
628 git checkout --orphan avoid-unnecessary-update-1 &&
629 git rm -rf . &&
630 git clean -fdqx &&
632 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >original &&
633 git add -A &&
634 git commit -m "Common commit" &&
636 git mv original rename &&
637 echo 11 >>rename &&
638 git add -u &&
639 git commit -m "Renamed and modified" &&
641 git checkout -b merge-branch-1 HEAD~1 &&
642 echo "random content" >random-file &&
643 git add -A &&
644 git commit -m "Random, unrelated changes"
647 test_expect_success 'avoid unnecessary update, normal rename' '
648 git checkout -q avoid-unnecessary-update-1^0 &&
649 test-tool chmtime --get -3600 rename >expect &&
650 git merge merge-branch-1 &&
651 test-tool chmtime --get rename >actual &&
652 test_cmp expect actual # "rename" should have stayed intact
655 test_expect_success 'setup to test avoiding unnecessary update, with D/F conflict' '
656 git reset --hard &&
657 git checkout --orphan avoid-unnecessary-update-2 &&
658 git rm -rf . &&
659 git clean -fdqx &&
661 mkdir df &&
662 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >df/file &&
663 git add -A &&
664 git commit -m "Common commit" &&
666 git mv df/file temp &&
667 rm -rf df &&
668 git mv temp df &&
669 echo 11 >>df &&
670 git add -u &&
671 git commit -m "Renamed and modified" &&
673 git checkout -b merge-branch-2 HEAD~1 &&
674 >unrelated-change &&
675 git add unrelated-change &&
676 git commit -m "Only unrelated changes"
679 test_expect_success 'avoid unnecessary update, with D/F conflict' '
680 git checkout -q avoid-unnecessary-update-2^0 &&
681 test-tool chmtime --get -3600 df >expect &&
682 git merge merge-branch-2 &&
683 test-tool chmtime --get df >actual &&
684 test_cmp expect actual # "df" should have stayed intact
687 test_expect_success 'setup avoid unnecessary update, dir->(file,nothing)' '
688 git rm -rf . &&
689 git clean -fdqx &&
690 rm -rf .git &&
691 git init &&
693 >irrelevant &&
694 mkdir df &&
695 >df/file &&
696 git add -A &&
697 git commit -mA &&
699 git checkout -b side &&
700 git rm -rf df &&
701 git commit -mB &&
703 git checkout master &&
704 git rm -rf df &&
705 echo bla >df &&
706 git add -A &&
707 git commit -m "Add a newfile"
710 test_expect_success 'avoid unnecessary update, dir->(file,nothing)' '
711 git checkout -q master^0 &&
712 test-tool chmtime --get -3600 df >expect &&
713 git merge side &&
714 test-tool chmtime --get df >actual &&
715 test_cmp expect actual # "df" should have stayed intact
718 test_expect_success 'setup avoid unnecessary update, modify/delete' '
719 git rm -rf . &&
720 git clean -fdqx &&
721 rm -rf .git &&
722 git init &&
724 >irrelevant &&
725 >file &&
726 git add -A &&
727 git commit -mA &&
729 git checkout -b side &&
730 git rm -f file &&
731 git commit -m "Delete file" &&
733 git checkout master &&
734 echo bla >file &&
735 git add -A &&
736 git commit -m "Modify file"
739 test_expect_success 'avoid unnecessary update, modify/delete' '
740 git checkout -q master^0 &&
741 test-tool chmtime --get -3600 file >expect &&
742 test_must_fail git merge side &&
743 test-tool chmtime --get file >actual &&
744 test_cmp expect actual # "file" should have stayed intact
747 test_expect_success 'setup avoid unnecessary update, rename/add-dest' '
748 git rm -rf . &&
749 git clean -fdqx &&
750 rm -rf .git &&
751 git init &&
753 printf "1\n2\n3\n4\n5\n6\n7\n8\n" >file &&
754 git add -A &&
755 git commit -mA &&
757 git checkout -b side &&
758 cp file newfile &&
759 git add -A &&
760 git commit -m "Add file copy" &&
762 git checkout master &&
763 git mv file newfile &&
764 git commit -m "Rename file"
767 test_expect_success 'avoid unnecessary update, rename/add-dest' '
768 git checkout -q master^0 &&
769 test-tool chmtime --get -3600 newfile >expect &&
770 git merge side &&
771 test-tool chmtime --get newfile >actual &&
772 test_cmp expect actual # "file" should have stayed intact
775 test_expect_success 'setup merge of rename + small change' '
776 git reset --hard &&
777 git checkout --orphan rename-plus-small-change &&
778 git rm -rf . &&
779 git clean -fdqx &&
781 echo ORIGINAL >file &&
782 git add file &&
784 test_tick &&
785 git commit -m Initial &&
786 git checkout -b rename_branch &&
787 git mv file renamed_file &&
788 git commit -m Rename &&
789 git checkout rename-plus-small-change &&
790 echo NEW-VERSION >file &&
791 git commit -a -m Reformat
794 test_expect_success 'merge rename + small change' '
795 git merge rename_branch &&
797 test 1 -eq $(git ls-files -s | wc -l) &&
798 test 0 -eq $(git ls-files -o | wc -l) &&
799 test $(git rev-parse HEAD:renamed_file) = $(git rev-parse HEAD~1:file)
802 test_expect_success 'setup for use of extended merge markers' '
803 git rm -rf . &&
804 git clean -fdqx &&
805 rm -rf .git &&
806 git init &&
808 printf "1\n2\n3\n4\n5\n6\n7\n8\n" >original_file &&
809 git add original_file &&
810 git commit -mA &&
812 git checkout -b rename &&
813 echo 9 >>original_file &&
814 git add original_file &&
815 git mv original_file renamed_file &&
816 git commit -mB &&
818 git checkout master &&
819 echo 8.5 >>original_file &&
820 git add original_file &&
821 git commit -mC
824 test_expect_success 'merge master into rename has correct extended markers' '
825 git checkout rename^0 &&
826 test_must_fail git merge -s recursive master^0 &&
828 cat >expected <<-\EOF &&
837 <<<<<<< HEAD:renamed_file
839 =======
841 >>>>>>> master^0:original_file
843 test_cmp expected renamed_file
846 test_expect_success 'merge rename into master has correct extended markers' '
847 git reset --hard &&
848 git checkout master^0 &&
849 test_must_fail git merge -s recursive rename^0 &&
851 cat >expected <<-\EOF &&
860 <<<<<<< HEAD:original_file
862 =======
864 >>>>>>> rename^0:renamed_file
866 test_cmp expected renamed_file
869 test_expect_success 'setup spurious "refusing to lose untracked" message' '
870 git rm -rf . &&
871 git clean -fdqx &&
872 rm -rf .git &&
873 git init &&
875 > irrelevant_file &&
876 printf "1\n2\n3\n4\n5\n6\n7\n8\n" >original_file &&
877 git add irrelevant_file original_file &&
878 git commit -mA &&
880 git checkout -b rename &&
881 git mv original_file renamed_file &&
882 git commit -mB &&
884 git checkout master &&
885 git rm original_file &&
886 git commit -mC
889 test_expect_success 'no spurious "refusing to lose untracked" message' '
890 git checkout master^0 &&
891 test_must_fail git merge rename^0 2>errors.txt &&
892 ! grep "refusing to lose untracked file" errors.txt
895 test_expect_success 'do not follow renames for empty files' '
896 git checkout -f -b empty-base &&
897 >empty1 &&
898 git add empty1 &&
899 git commit -m base &&
900 echo content >empty1 &&
901 git add empty1 &&
902 git commit -m fill &&
903 git checkout -b empty-topic HEAD^ &&
904 git mv empty1 empty2 &&
905 git commit -m rename &&
906 test_must_fail git merge empty-base &&
907 test_must_be_empty empty2
910 test_done