Merge branch 'ds/add-rm-with-sparse-index'
[git/debian.git] / t / t6402-merge-rename.sh
blob3a32b1a45cf8e4bf2a7b42eeec98923262b3e470
1 #!/bin/sh
3 test_description='Merge-recursive merging renames'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7 . ./test-lib.sh
9 modify () {
10 sed -e "$1" <"$2" >"$2.x" &&
11 mv "$2.x" "$2"
14 test_expect_success 'setup' '
15 cat >A <<-\EOF &&
16 a aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
17 b bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
18 c cccccccccccccccccccccccccccccccccccccccccccccccc
19 d dddddddddddddddddddddddddddddddddddddddddddddddd
20 e eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
21 f ffffffffffffffffffffffffffffffffffffffffffffffff
22 g gggggggggggggggggggggggggggggggggggggggggggggggg
23 h hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
24 i iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
25 j jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj
26 k kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
27 l llllllllllllllllllllllllllllllllllllllllllllllll
28 m mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
29 n nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
30 o oooooooooooooooooooooooooooooooooooooooooooooooo
31 EOF
33 cat >M <<-\EOF &&
34 A AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
35 B BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
36 C CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
37 D DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
38 E EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
39 F FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
40 G GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
41 H HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
42 I IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
43 J JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
44 K KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK
45 L LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
46 M MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
47 N NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
48 O OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
49 EOF
51 git add A M &&
52 git commit -m "initial has A and M" &&
53 git branch white &&
54 git branch red &&
55 git branch blue &&
56 git branch yellow &&
57 git branch change &&
58 git branch change+rename &&
60 sed -e "/^g /s/.*/g : main changes a line/" <A >A+ &&
61 mv A+ A &&
62 git commit -a -m "main updates A" &&
64 git checkout yellow &&
65 rm -f M &&
66 git commit -a -m "yellow removes M" &&
68 git checkout white &&
69 sed -e "/^g /s/.*/g : white changes a line/" <A >B &&
70 sed -e "/^G /s/.*/G : colored branch changes a line/" <M >N &&
71 rm -f A M &&
72 git update-index --add --remove A B M N &&
73 git commit -m "white renames A->B, M->N" &&
75 git checkout red &&
76 sed -e "/^g /s/.*/g : red changes a line/" <A >B &&
77 sed -e "/^G /s/.*/G : colored branch changes a line/" <M >N &&
78 rm -f A M &&
79 git update-index --add --remove A B M N &&
80 git commit -m "red renames A->B, M->N" &&
82 git checkout blue &&
83 sed -e "/^g /s/.*/g : blue changes a line/" <A >C &&
84 sed -e "/^G /s/.*/G : colored branch changes a line/" <M >N &&
85 rm -f A M &&
86 git update-index --add --remove A C M N &&
87 git commit -m "blue renames A->C, M->N" &&
89 git checkout change &&
90 sed -e "/^g /s/.*/g : changed line/" <A >A+ &&
91 mv A+ A &&
92 git commit -q -a -m "changed" &&
94 git checkout change+rename &&
95 sed -e "/^g /s/.*/g : changed line/" <A >B &&
96 rm A &&
97 git update-index --add B &&
98 git commit -q -a -m "changed and renamed" &&
100 git checkout main
103 test_expect_success 'pull renaming branch into unrenaming one' \
105 git show-branch &&
106 test_expect_code 1 git pull --no-rebase . white &&
107 git ls-files -s &&
108 test_stdout_line_count = 3 git ls-files -u B &&
109 test_stdout_line_count = 1 git ls-files -s N &&
110 sed -ne "/^g/{
113 }" B | grep main &&
114 git diff --exit-code white N
117 test_expect_success 'pull renaming branch into another renaming one' \
119 rm -f B &&
120 git reset --hard &&
121 git checkout red &&
122 test_expect_code 1 git pull --no-rebase . white &&
123 test_stdout_line_count = 3 git ls-files -u B &&
124 test_stdout_line_count = 1 git ls-files -s N &&
125 sed -ne "/^g/{
128 }" B | grep red &&
129 git diff --exit-code white N
132 test_expect_success 'pull unrenaming branch into renaming one' \
134 git reset --hard &&
135 git show-branch &&
136 test_expect_code 1 git pull --no-rebase . main &&
137 test_stdout_line_count = 3 git ls-files -u B &&
138 test_stdout_line_count = 1 git ls-files -s N &&
139 sed -ne "/^g/{
142 }" B | grep red &&
143 git diff --exit-code white N
146 test_expect_success 'pull conflicting renames' \
148 git reset --hard &&
149 git show-branch &&
150 test_expect_code 1 git pull --no-rebase . blue &&
151 test_stdout_line_count = 1 git ls-files -u A &&
152 test_stdout_line_count = 1 git ls-files -u B &&
153 test_stdout_line_count = 1 git ls-files -u C &&
154 test_stdout_line_count = 1 git ls-files -s N &&
155 sed -ne "/^g/{
158 }" B | grep red &&
159 git diff --exit-code white N
162 test_expect_success 'interference with untracked working tree file' '
163 git reset --hard &&
164 git show-branch &&
165 echo >A this file should not matter &&
166 test_expect_code 1 git pull --no-rebase . white &&
167 test_path_is_file A
170 test_expect_success 'interference with untracked working tree file' '
171 git reset --hard &&
172 git checkout white &&
173 git show-branch &&
174 rm -f A &&
175 echo >A this file should not matter &&
176 test_expect_code 1 git pull --no-rebase . red &&
177 test_path_is_file A
180 test_expect_success 'interference with untracked working tree file' '
181 git reset --hard &&
182 rm -f A M &&
183 git checkout -f main &&
184 git tag -f anchor &&
185 git show-branch &&
186 git pull --no-rebase . yellow &&
187 test_path_is_missing M &&
188 git reset --hard anchor
191 test_expect_success 'updated working tree file should prevent the merge' '
192 git reset --hard &&
193 rm -f A M &&
194 git checkout -f main &&
195 git tag -f anchor &&
196 git show-branch &&
197 echo >>M one line addition &&
198 cat M >M.saved &&
199 test_expect_code 128 git pull . yellow &&
200 test_cmp M M.saved &&
201 rm -f M.saved
204 test_expect_success 'updated working tree file should prevent the merge' '
205 git reset --hard &&
206 rm -f A M &&
207 git checkout -f main &&
208 git tag -f anchor &&
209 git show-branch &&
210 echo >>M one line addition &&
211 cat M >M.saved &&
212 git update-index M &&
213 test_expect_code 128 git pull --no-rebase . yellow &&
214 test_cmp M M.saved &&
215 rm -f M.saved
218 test_expect_success 'interference with untracked working tree file' '
219 git reset --hard &&
220 rm -f A M &&
221 git checkout -f yellow &&
222 git tag -f anchor &&
223 git show-branch &&
224 echo >M this file should not matter &&
225 git pull --no-rebase . main &&
226 test_path_is_file M &&
228 git ls-files -s |
229 grep M
230 } &&
231 git reset --hard anchor
234 test_expect_success 'merge of identical changes in a renamed file' '
235 rm -f A M N &&
236 git reset --hard &&
237 git checkout change+rename &&
239 test-tool chmtime --get -3600 B >old-mtime &&
240 GIT_MERGE_VERBOSITY=3 git merge change >out &&
242 test-tool chmtime --get B >new-mtime &&
243 test_cmp old-mtime new-mtime &&
245 git reset --hard HEAD^ &&
246 git checkout change &&
248 # A will be renamed to B; we check mtimes and file presence
249 test_path_is_missing B &&
250 test-tool chmtime --get -3600 A >old-mtime &&
251 GIT_MERGE_VERBOSITY=3 git merge change+rename >out &&
253 test_path_is_missing A &&
254 test-tool chmtime --get B >new-mtime &&
255 test $(cat old-mtime) -lt $(cat new-mtime)
258 test_expect_success 'setup for rename + d/f conflicts' '
259 git reset --hard &&
260 git checkout --orphan dir-in-way &&
261 git rm -rf . &&
262 git clean -fdqx &&
264 mkdir sub &&
265 mkdir dir &&
266 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >sub/file &&
267 echo foo >dir/file-in-the-way &&
268 git add -A &&
269 git commit -m "Common commit" &&
271 echo 11 >>sub/file &&
272 echo more >>dir/file-in-the-way &&
273 git add -u &&
274 git commit -m "Commit to merge, with dir in the way" &&
276 git checkout -b dir-not-in-way &&
277 git reset --soft HEAD^ &&
278 git rm -rf dir &&
279 git commit -m "Commit to merge, with dir removed" -- dir sub/file &&
281 git checkout -b renamed-file-has-no-conflicts dir-in-way~1 &&
282 git rm -rf dir &&
283 git rm sub/file &&
284 printf "1\n2\n3\n4\n5555\n6\n7\n8\n9\n10\n" >dir &&
285 git add dir &&
286 git commit -m "Independent change" &&
288 git checkout -b renamed-file-has-conflicts dir-in-way~1 &&
289 git rm -rf dir &&
290 git mv sub/file dir &&
291 echo 12 >>dir &&
292 git add dir &&
293 git commit -m "Conflicting change"
296 test_expect_success 'Rename+D/F conflict; renamed file merges + dir not in way' '
297 git reset --hard &&
298 git checkout -q renamed-file-has-no-conflicts^0 &&
300 git merge --strategy=recursive dir-not-in-way &&
302 git diff --quiet &&
303 test_path_is_file dir &&
304 test_write_lines 1 2 3 4 5555 6 7 8 9 10 11 >expected &&
305 test_cmp expected dir
308 test_expect_success 'Rename+D/F conflict; renamed file merges but dir in way' '
309 git reset --hard &&
310 rm -rf dir~* &&
311 git checkout -q renamed-file-has-no-conflicts^0 &&
312 test_must_fail git merge --strategy=recursive dir-in-way >output &&
314 test_i18ngrep "CONFLICT (modify/delete): dir/file-in-the-way" output &&
315 test_i18ngrep "Auto-merging dir" output &&
316 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
317 then
318 test_i18ngrep "moving it to dir~HEAD instead" output
319 else
320 test_i18ngrep "Adding as dir~HEAD instead" output
321 fi &&
323 test_stdout_line_count = 3 git ls-files -u &&
324 test_stdout_line_count = 2 git ls-files -u dir/file-in-the-way &&
326 test_must_fail git diff --quiet &&
327 test_must_fail git diff --cached --quiet &&
329 test_path_is_file dir/file-in-the-way &&
330 test_path_is_file dir~HEAD &&
331 test_cmp expected dir~HEAD
334 test_expect_success 'Same as previous, but merged other way' '
335 git reset --hard &&
336 rm -rf dir~* &&
337 git checkout -q dir-in-way^0 &&
338 test_must_fail git merge --strategy=recursive renamed-file-has-no-conflicts >output 2>errors &&
340 ! grep "error: refusing to lose untracked file at" errors &&
341 test_i18ngrep "CONFLICT (modify/delete): dir/file-in-the-way" output &&
342 test_i18ngrep "Auto-merging dir" output &&
343 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
344 then
345 test_i18ngrep "moving it to dir~renamed-file-has-no-conflicts instead" output
346 else
347 test_i18ngrep "Adding as dir~renamed-file-has-no-conflicts instead" output
348 fi &&
350 test_stdout_line_count = 3 git ls-files -u &&
351 test_stdout_line_count = 2 git ls-files -u dir/file-in-the-way &&
353 test_must_fail git diff --quiet &&
354 test_must_fail git diff --cached --quiet &&
356 test_path_is_file dir/file-in-the-way &&
357 test_path_is_file dir~renamed-file-has-no-conflicts &&
358 test_cmp expected dir~renamed-file-has-no-conflicts
361 test_expect_success 'Rename+D/F conflict; renamed file cannot merge, dir not in way' '
362 git reset --hard &&
363 rm -rf dir~* &&
364 git checkout -q renamed-file-has-conflicts^0 &&
365 test_must_fail git merge --strategy=recursive dir-not-in-way &&
367 test_stdout_line_count = 3 git ls-files -u &&
368 test_stdout_line_count = 3 git ls-files -u dir &&
370 test_must_fail git diff --quiet &&
371 test_must_fail git diff --cached --quiet &&
373 test_path_is_file dir &&
374 cat >expected <<-\EOF &&
385 <<<<<<< HEAD:dir
387 =======
389 >>>>>>> dir-not-in-way:sub/file
391 test_cmp expected dir
394 test_expect_success 'Rename+D/F conflict; renamed file cannot merge and dir in the way' '
395 modify s/dir-not-in-way/dir-in-way/ expected &&
397 git reset --hard &&
398 rm -rf dir~* &&
399 git checkout -q renamed-file-has-conflicts^0 &&
400 test_must_fail git merge --strategy=recursive dir-in-way &&
402 test_stdout_line_count = 5 git ls-files -u &&
403 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
404 then
405 test_stdout_line_count = 3 git ls-files -u dir~HEAD
406 else
407 git ls-files -u dir >out &&
408 test 3 -eq $(grep -v file-in-the-way out | wc -l) &&
409 rm -f out
410 fi &&
411 test_stdout_line_count = 2 git ls-files -u dir/file-in-the-way &&
413 test_must_fail git diff --quiet &&
414 test_must_fail git diff --cached --quiet &&
416 test_path_is_file dir/file-in-the-way &&
417 test_path_is_file dir~HEAD &&
418 test_cmp expected dir~HEAD
421 test_expect_success 'Same as previous, but merged other way' '
422 git reset --hard &&
423 rm -rf dir~* &&
424 git checkout -q dir-in-way^0 &&
425 test_must_fail git merge --strategy=recursive renamed-file-has-conflicts &&
427 test_stdout_line_count = 5 git ls-files -u &&
428 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
429 then
430 test_stdout_line_count = 3 git ls-files -u dir~renamed-file-has-conflicts
431 else
432 git ls-files -u dir >out &&
433 test 3 -eq $(grep -v file-in-the-way out | wc -l) &&
434 rm -f out
435 fi &&
436 test_stdout_line_count = 2 git ls-files -u dir/file-in-the-way &&
438 test_must_fail git diff --quiet &&
439 test_must_fail git diff --cached --quiet &&
441 test_path_is_file dir/file-in-the-way &&
442 test_path_is_file dir~renamed-file-has-conflicts &&
443 cat >expected <<-\EOF &&
454 <<<<<<< HEAD:sub/file
456 =======
458 >>>>>>> renamed-file-has-conflicts:dir
460 test_cmp expected dir~renamed-file-has-conflicts
463 test_expect_success 'setup both rename source and destination involved in D/F conflict' '
464 git reset --hard &&
465 git checkout --orphan rename-dest &&
466 git rm -rf . &&
467 git clean -fdqx &&
469 mkdir one &&
470 echo stuff >one/file &&
471 git add -A &&
472 git commit -m "Common commit" &&
474 git mv one/file destdir &&
475 git commit -m "Renamed to destdir" &&
477 git checkout -b source-conflict HEAD~1 &&
478 git rm -rf one &&
479 mkdir destdir &&
480 touch one destdir/foo &&
481 git add -A &&
482 git commit -m "Conflicts in the way"
485 test_expect_success 'both rename source and destination involved in D/F conflict' '
486 git reset --hard &&
487 rm -rf dir~* &&
488 git checkout -q rename-dest^0 &&
489 test_must_fail git merge --strategy=recursive source-conflict &&
491 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
492 then
493 test_stdout_line_count = 2 git ls-files -u
494 else
495 test_stdout_line_count = 1 git ls-files -u
496 fi &&
498 test_must_fail git diff --quiet &&
500 test_path_is_file destdir/foo &&
501 test_path_is_file one &&
502 test_path_is_file destdir~HEAD &&
503 test "stuff" = "$(cat destdir~HEAD)"
506 test_expect_success 'setup pair rename to parent of other (D/F conflicts)' '
507 git reset --hard &&
508 git checkout --orphan rename-two &&
509 git rm -rf . &&
510 git clean -fdqx &&
512 mkdir one &&
513 mkdir two &&
514 echo stuff >one/file &&
515 echo other >two/file &&
516 git add -A &&
517 git commit -m "Common commit" &&
519 git rm -rf one &&
520 git mv two/file one &&
521 git commit -m "Rename two/file -> one" &&
523 git checkout -b rename-one HEAD~1 &&
524 git rm -rf two &&
525 git mv one/file two &&
526 rm -r one &&
527 git commit -m "Rename one/file -> two"
530 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
531 then
532 test_expect_success 'pair rename to parent of other (D/F conflicts) w/ untracked dir' '
533 git checkout -q rename-one^0 &&
534 mkdir one &&
535 test_must_fail git merge --strategy=recursive rename-two &&
537 test_stdout_line_count = 4 git ls-files -u &&
538 test_stdout_line_count = 2 git ls-files -u one &&
539 test_stdout_line_count = 2 git ls-files -u two &&
541 test_must_fail git diff --quiet &&
543 test 3 -eq $(find . | grep -v .git | wc -l) &&
545 test_path_is_file one &&
546 test_path_is_file two &&
547 test "other" = $(cat one) &&
548 test "stuff" = $(cat two)
550 else
551 test_expect_success 'pair rename to parent of other (D/F conflicts) w/ untracked dir' '
552 git checkout -q rename-one^0 &&
553 mkdir one &&
554 test_must_fail git merge --strategy=recursive rename-two &&
556 test_stdout_line_count = 2 git ls-files -u &&
557 test_stdout_line_count = 1 git ls-files -u one &&
558 test_stdout_line_count = 1 git ls-files -u two &&
560 test_must_fail git diff --quiet &&
562 test 4 -eq $(find . | grep -v .git | wc -l) &&
564 test_path_is_dir one &&
565 test_path_is_file one~rename-two &&
566 test_path_is_file two &&
567 test "other" = $(cat one~rename-two) &&
568 test "stuff" = $(cat two)
572 test_expect_success 'pair rename to parent of other (D/F conflicts) w/ clean start' '
573 git reset --hard &&
574 git clean -fdqx &&
575 test_must_fail git merge --strategy=recursive rename-two &&
577 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
578 then
579 test_stdout_line_count = 4 git ls-files -u &&
580 test_stdout_line_count = 2 git ls-files -u one &&
581 test_stdout_line_count = 2 git ls-files -u two
582 else
583 test_stdout_line_count = 2 git ls-files -u &&
584 test_stdout_line_count = 1 git ls-files -u one &&
585 test_stdout_line_count = 1 git ls-files -u two
586 fi &&
588 test_must_fail git diff --quiet &&
590 test 3 -eq $(find . | grep -v .git | wc -l) &&
592 test_path_is_file one &&
593 test_path_is_file two &&
594 test "other" = $(cat one) &&
595 test "stuff" = $(cat two)
598 test_expect_success 'setup rename of one file to two, with directories in the way' '
599 git reset --hard &&
600 git checkout --orphan first-rename &&
601 git rm -rf . &&
602 git clean -fdqx &&
604 echo stuff >original &&
605 git add -A &&
606 git commit -m "Common commit" &&
608 mkdir two &&
609 >two/file &&
610 git add two/file &&
611 git mv original one &&
612 git commit -m "Put two/file in the way, rename to one" &&
614 git checkout -b second-rename HEAD~1 &&
615 mkdir one &&
616 >one/file &&
617 git add one/file &&
618 git mv original two &&
619 git commit -m "Put one/file in the way, rename to two"
622 test_expect_success 'check handling of differently renamed file with D/F conflicts' '
623 git checkout -q first-rename^0 &&
624 test_must_fail git merge --strategy=recursive second-rename &&
626 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
627 then
628 test_stdout_line_count = 5 git ls-files -s &&
629 test_stdout_line_count = 3 git ls-files -u &&
630 test_stdout_line_count = 1 git ls-files -u one~HEAD &&
631 test_stdout_line_count = 1 git ls-files -u two~second-rename &&
632 test_stdout_line_count = 1 git ls-files -u original &&
633 test_stdout_line_count = 0 git ls-files -o
634 else
635 test_stdout_line_count = 5 git ls-files -s &&
636 test_stdout_line_count = 3 git ls-files -u &&
637 test_stdout_line_count = 1 git ls-files -u one &&
638 test_stdout_line_count = 1 git ls-files -u two &&
639 test_stdout_line_count = 1 git ls-files -u original &&
640 test_stdout_line_count = 2 git ls-files -o
641 fi &&
643 test_path_is_file one/file &&
644 test_path_is_file two/file &&
645 test_path_is_file one~HEAD &&
646 test_path_is_file two~second-rename &&
647 test_path_is_missing original
650 test_expect_success 'setup rename one file to two; directories moving out of the way' '
651 git reset --hard &&
652 git checkout --orphan first-rename-redo &&
653 git rm -rf . &&
654 git clean -fdqx &&
656 echo stuff >original &&
657 mkdir one two &&
658 touch one/file two/file &&
659 git add -A &&
660 git commit -m "Common commit" &&
662 git rm -rf one &&
663 git mv original one &&
664 git commit -m "Rename to one" &&
666 git checkout -b second-rename-redo HEAD~1 &&
667 git rm -rf two &&
668 git mv original two &&
669 git commit -m "Rename to two"
672 test_expect_success 'check handling of differently renamed file with D/F conflicts' '
673 git checkout -q first-rename-redo^0 &&
674 test_must_fail git merge --strategy=recursive second-rename-redo &&
676 test_stdout_line_count = 3 git ls-files -u &&
677 test_stdout_line_count = 1 git ls-files -u one &&
678 test_stdout_line_count = 1 git ls-files -u two &&
679 test_stdout_line_count = 1 git ls-files -u original &&
680 test_stdout_line_count = 0 git ls-files -o &&
682 test_path_is_file one &&
683 test_path_is_file two &&
684 test_path_is_missing original
687 test_expect_success 'setup avoid unnecessary update, normal rename' '
688 git reset --hard &&
689 git checkout --orphan avoid-unnecessary-update-1 &&
690 git rm -rf . &&
691 git clean -fdqx &&
693 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >original &&
694 git add -A &&
695 git commit -m "Common commit" &&
697 git mv original rename &&
698 echo 11 >>rename &&
699 git add -u &&
700 git commit -m "Renamed and modified" &&
702 git checkout -b merge-branch-1 HEAD~1 &&
703 echo "random content" >random-file &&
704 git add -A &&
705 git commit -m "Random, unrelated changes"
708 test_expect_success 'avoid unnecessary update, normal rename' '
709 git checkout -q avoid-unnecessary-update-1^0 &&
710 test-tool chmtime --get -3600 rename >expect &&
711 git merge merge-branch-1 &&
712 test-tool chmtime --get rename >actual &&
713 test_cmp expect actual # "rename" should have stayed intact
716 test_expect_success 'setup to test avoiding unnecessary update, with D/F conflict' '
717 git reset --hard &&
718 git checkout --orphan avoid-unnecessary-update-2 &&
719 git rm -rf . &&
720 git clean -fdqx &&
722 mkdir df &&
723 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >df/file &&
724 git add -A &&
725 git commit -m "Common commit" &&
727 git mv df/file temp &&
728 rm -rf df &&
729 git mv temp df &&
730 echo 11 >>df &&
731 git add -u &&
732 git commit -m "Renamed and modified" &&
734 git checkout -b merge-branch-2 HEAD~1 &&
735 >unrelated-change &&
736 git add unrelated-change &&
737 git commit -m "Only unrelated changes"
740 test_expect_success 'avoid unnecessary update, with D/F conflict' '
741 git checkout -q avoid-unnecessary-update-2^0 &&
742 test-tool chmtime --get -3600 df >expect &&
743 git merge merge-branch-2 &&
744 test-tool chmtime --get df >actual &&
745 test_cmp expect actual # "df" should have stayed intact
748 test_expect_success 'setup avoid unnecessary update, dir->(file,nothing)' '
749 git rm -rf . &&
750 git clean -fdqx &&
751 rm -rf .git &&
752 git init &&
754 >irrelevant &&
755 mkdir df &&
756 >df/file &&
757 git add -A &&
758 git commit -mA &&
760 git checkout -b side &&
761 git rm -rf df &&
762 git commit -mB &&
764 git checkout main &&
765 git rm -rf df &&
766 echo bla >df &&
767 git add -A &&
768 git commit -m "Add a newfile"
771 test_expect_success 'avoid unnecessary update, dir->(file,nothing)' '
772 git checkout -q main^0 &&
773 test-tool chmtime --get -3600 df >expect &&
774 git merge side &&
775 test-tool chmtime --get df >actual &&
776 test_cmp expect actual # "df" should have stayed intact
779 test_expect_success 'setup avoid unnecessary update, modify/delete' '
780 git rm -rf . &&
781 git clean -fdqx &&
782 rm -rf .git &&
783 git init &&
785 >irrelevant &&
786 >file &&
787 git add -A &&
788 git commit -mA &&
790 git checkout -b side &&
791 git rm -f file &&
792 git commit -m "Delete file" &&
794 git checkout main &&
795 echo bla >file &&
796 git add -A &&
797 git commit -m "Modify file"
800 test_expect_success 'avoid unnecessary update, modify/delete' '
801 git checkout -q main^0 &&
802 test-tool chmtime --get -3600 file >expect &&
803 test_must_fail git merge side &&
804 test-tool chmtime --get file >actual &&
805 test_cmp expect actual # "file" should have stayed intact
808 test_expect_success 'setup avoid unnecessary update, rename/add-dest' '
809 git rm -rf . &&
810 git clean -fdqx &&
811 rm -rf .git &&
812 git init &&
814 printf "1\n2\n3\n4\n5\n6\n7\n8\n" >file &&
815 git add -A &&
816 git commit -mA &&
818 git checkout -b side &&
819 cp file newfile &&
820 git add -A &&
821 git commit -m "Add file copy" &&
823 git checkout main &&
824 git mv file newfile &&
825 git commit -m "Rename file"
828 test_expect_success 'avoid unnecessary update, rename/add-dest' '
829 git checkout -q main^0 &&
830 test-tool chmtime --get -3600 newfile >expect &&
831 git merge side &&
832 test-tool chmtime --get newfile >actual &&
833 test_cmp expect actual # "file" should have stayed intact
836 test_expect_success 'setup merge of rename + small change' '
837 git reset --hard &&
838 git checkout --orphan rename-plus-small-change &&
839 git rm -rf . &&
840 git clean -fdqx &&
842 echo ORIGINAL >file &&
843 git add file &&
845 test_tick &&
846 git commit -m Initial &&
847 git checkout -b rename_branch &&
848 git mv file renamed_file &&
849 git commit -m Rename &&
850 git checkout rename-plus-small-change &&
851 echo NEW-VERSION >file &&
852 git commit -a -m Reformat
855 test_expect_success 'merge rename + small change' '
856 git merge rename_branch &&
858 test_stdout_line_count = 1 git ls-files -s &&
859 test_stdout_line_count = 0 git ls-files -o &&
860 newhash=$(git rev-parse HEAD:renamed_file) &&
861 oldhash=$(git rev-parse HEAD~1:file) &&
862 test $newhash = $oldhash
865 test_expect_success 'setup for use of extended merge markers' '
866 git rm -rf . &&
867 git clean -fdqx &&
868 rm -rf .git &&
869 git init &&
871 printf "1\n2\n3\n4\n5\n6\n7\n8\n" >original_file &&
872 git add original_file &&
873 git commit -mA &&
875 git checkout -b rename &&
876 echo 9 >>original_file &&
877 git add original_file &&
878 git mv original_file renamed_file &&
879 git commit -mB &&
881 git checkout main &&
882 echo 8.5 >>original_file &&
883 git add original_file &&
884 git commit -mC
887 test_expect_success 'merge main into rename has correct extended markers' '
888 git checkout rename^0 &&
889 test_must_fail git merge -s recursive main^0 &&
891 cat >expected <<-\EOF &&
900 <<<<<<< HEAD:renamed_file
902 =======
904 >>>>>>> main^0:original_file
906 test_cmp expected renamed_file
909 test_expect_success 'merge rename into main has correct extended markers' '
910 git reset --hard &&
911 git checkout main^0 &&
912 test_must_fail git merge -s recursive rename^0 &&
914 cat >expected <<-\EOF &&
923 <<<<<<< HEAD:original_file
925 =======
927 >>>>>>> rename^0:renamed_file
929 test_cmp expected renamed_file
932 test_expect_success 'setup spurious "refusing to lose untracked" message' '
933 git rm -rf . &&
934 git clean -fdqx &&
935 rm -rf .git &&
936 git init &&
938 > irrelevant_file &&
939 printf "1\n2\n3\n4\n5\n6\n7\n8\n" >original_file &&
940 git add irrelevant_file original_file &&
941 git commit -mA &&
943 git checkout -b rename &&
944 git mv original_file renamed_file &&
945 git commit -mB &&
947 git checkout main &&
948 git rm original_file &&
949 git commit -mC
952 test_expect_success 'no spurious "refusing to lose untracked" message' '
953 git checkout main^0 &&
954 test_must_fail git merge rename^0 2>errors.txt &&
955 ! grep "refusing to lose untracked file" errors.txt
958 test_expect_success 'do not follow renames for empty files' '
959 git checkout -f -b empty-base &&
960 >empty1 &&
961 git add empty1 &&
962 git commit -m base &&
963 echo content >empty1 &&
964 git add empty1 &&
965 git commit -m fill &&
966 git checkout -b empty-topic HEAD^ &&
967 git mv empty1 empty2 &&
968 git commit -m rename &&
969 test_must_fail git merge empty-base &&
970 test_must_be_empty empty2
973 test_done