]> git.ipfire.org Git - thirdparty/git.git/blame - t/t6402-merge-rename.sh
Merge branch 'pb/ref-filter-with-crlf'
[thirdparty/git.git] / t / t6402-merge-rename.sh
CommitLineData
b825e6ff
JH
1#!/bin/sh
2
3test_description='Merge-recursive merging renames'
4. ./test-lib.sh
5
af6e1751
EN
6modify () {
7 sed -e "$1" <"$2" >"$2.x" &&
8 mv "$2.x" "$2"
9}
10
42d180dd
EN
11test_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
29
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
47
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 &&
56
57 sed -e "/^g /s/.*/g : master changes a line/" <A >A+ &&
58 mv A+ A &&
59 git commit -a -m "master updates A" &&
60
61 git checkout yellow &&
62 rm -f M &&
63 git commit -a -m "yellow removes M" &&
64
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" &&
71
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" &&
78
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" &&
85
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" &&
90
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" &&
96
97 git checkout master
98'
b825e6ff
JH
99
100test_expect_success 'pull renaming branch into unrenaming one' \
101'
cae3aa79
JN
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 &&
b825e6ff
JH
109 sed -ne "/^g/{
110 p
111 q
cae3aa79
JN
112 }" B | grep master &&
113 git diff --exit-code white N
b825e6ff
JH
114'
115
116test_expect_success 'pull renaming branch into another renaming one' \
117'
cae3aa79
JN
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 &&
b825e6ff
JH
126 sed -ne "/^g/{
127 p
128 q
cae3aa79
JN
129 }" B | grep red &&
130 git diff --exit-code white N
b825e6ff
JH
131'
132
133test_expect_success 'pull unrenaming branch into renaming one' \
134'
cae3aa79
JN
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 &&
b825e6ff
JH
142 sed -ne "/^g/{
143 p
144 q
cae3aa79
JN
145 }" B | grep red &&
146 git diff --exit-code white N
b825e6ff
JH
147'
148
724b511d
JH
149test_expect_success 'pull conflicting renames' \
150'
cae3aa79
JN
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 &&
724b511d
JH
162 sed -ne "/^g/{
163 p
164 q
cae3aa79
JN
165 }" B | grep red &&
166 git diff --exit-code white N
5b329a5f
JH
167'
168
169test_expect_success 'interference with untracked working tree file' '
cae3aa79
JN
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
5b329a5f
JH
175'
176
177test_expect_success 'interference with untracked working tree file' '
cae3aa79
JN
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
5b329a5f
JH
185'
186
187test_expect_success 'interference with untracked working tree file' '
cae3aa79
JN
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 &&
5b329a5f
JH
195 git reset --hard anchor
196'
197
198test_expect_success 'updated working tree file should prevent the merge' '
cae3aa79
JN
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 &&
5b329a5f
JH
208 rm -f M.saved
209'
210
211test_expect_success 'updated working tree file should prevent the merge' '
cae3aa79
JN
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 &&
5b329a5f
JH
222 rm -f M.saved
223'
224
225test_expect_success 'interference with untracked working tree file' '
cae3aa79
JN
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 &&
234 ! {
235 git ls-files -s |
236 grep M
237 } &&
5b329a5f 238 git reset --hard anchor
724b511d
JH
239'
240
8a359819 241test_expect_success 'merge of identical changes in a renamed file' '
cae3aa79 242 rm -f A M N &&
8a359819
AR
243 git reset --hard &&
244 git checkout change+rename &&
9f697ded 245
70e24186 246 test-tool chmtime --get -3600 B >old-mtime &&
cc04adc2 247 GIT_MERGE_VERBOSITY=3 git merge change >out &&
9f697ded
EN
248
249 test-tool chmtime --get B >new-mtime &&
250 test_cmp old-mtime new-mtime &&
251
8a359819
AR
252 git reset --hard HEAD^ &&
253 git checkout change &&
9f697ded 254
70e24186
EN
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 &&
cc04adc2 258 GIT_MERGE_VERBOSITY=3 git merge change+rename >out &&
9f697ded 259
70e24186 260 test_path_is_missing A &&
9f697ded
EN
261 test-tool chmtime --get B >new-mtime &&
262 test $(cat old-mtime) -lt $(cat new-mtime)
8a359819
AR
263'
264
af6e1751
EN
265test_expect_success 'setup for rename + d/f conflicts' '
266 git reset --hard &&
267 git checkout --orphan dir-in-way &&
268 git rm -rf . &&
5b5261ba 269 git clean -fdqx &&
af6e1751
EN
270
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 &&
a316b954 276 git commit -m "Common commit" &&
af6e1751
EN
277
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" &&
282
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 &&
287
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" &&
294
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"
301'
302
af6e1751
EN
303test_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 &&
42d180dd 306
af6e1751 307 git merge --strategy=recursive dir-not-in-way &&
42d180dd 308
af6e1751 309 git diff --quiet &&
b821ca78
EN
310 test_path_is_file dir &&
311 test_write_lines 1 2 3 4 5555 6 7 8 9 10 11 >expected &&
af6e1751
EN
312 test_cmp expected dir
313'
314
4ab9a157 315test_expect_success 'Rename+D/F conflict; renamed file merges but dir in way' '
af6e1751
EN
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 &&
320
55653a68
JX
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 &&
af6e1751 324
51931bf0 325 test 3 -eq "$(git ls-files -u | wc -l)" &&
9f6cea97 326 test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
af6e1751
EN
327
328 test_must_fail git diff --quiet &&
329 test_must_fail git diff --cached --quiet &&
330
b821ca78
EN
331 test_path_is_file dir/file-in-the-way &&
332 test_path_is_file dir~HEAD &&
af6e1751
EN
333 test_cmp expected dir~HEAD
334'
335
4ab9a157 336test_expect_success 'Same as previous, but merged other way' '
3398f2f5
EN
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 &&
341
342 ! grep "error: refusing to lose untracked file at" errors &&
55653a68
JX
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 &&
3398f2f5 346
51931bf0 347 test 3 -eq "$(git ls-files -u | wc -l)" &&
9f6cea97 348 test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
3398f2f5
EN
349
350 test_must_fail git diff --quiet &&
351 test_must_fail git diff --cached --quiet &&
352
b821ca78
EN
353 test_path_is_file dir/file-in-the-way &&
354 test_path_is_file dir~renamed-file-has-no-conflicts &&
3398f2f5
EN
355 test_cmp expected dir~renamed-file-has-no-conflicts
356'
357
882fd11a 358test_expect_success 'Rename+D/F conflict; renamed file cannot merge, dir not in way' '
af6e1751
EN
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 &&
363
9f6cea97
BG
364 test 3 -eq "$(git ls-files -u | wc -l)" &&
365 test 3 -eq "$(git ls-files -u dir | wc -l)" &&
af6e1751
EN
366
367 test_must_fail git diff --quiet &&
368 test_must_fail git diff --cached --quiet &&
369
b821ca78 370 test_path_is_file dir &&
42d180dd
EN
371 cat >expected <<-\EOF &&
372 1
373 2
374 3
375 4
376 5
377 6
378 7
379 8
380 9
381 10
382 <<<<<<< HEAD:dir
383 12
384 =======
385 11
386 >>>>>>> dir-not-in-way:sub/file
387 EOF
af6e1751
EN
388 test_cmp expected dir
389'
390
4ab9a157 391test_expect_success 'Rename+D/F conflict; renamed file cannot merge and dir in the way' '
af6e1751
EN
392 modify s/dir-not-in-way/dir-in-way/ expected &&
393
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 &&
398
9f6cea97
BG
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)" &&
af6e1751
EN
402
403 test_must_fail git diff --quiet &&
404 test_must_fail git diff --cached --quiet &&
405
b821ca78
EN
406 test_path_is_file dir/file-in-the-way &&
407 test_path_is_file dir~HEAD &&
af6e1751
EN
408 test_cmp expected dir~HEAD
409'
410
4ab9a157 411test_expect_success 'Same as previous, but merged other way' '
3398f2f5
EN
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 &&
416
9f6cea97
BG
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)" &&
3398f2f5
EN
420
421 test_must_fail git diff --quiet &&
422 test_must_fail git diff --cached --quiet &&
423
b821ca78
EN
424 test_path_is_file dir/file-in-the-way &&
425 test_path_is_file dir~renamed-file-has-conflicts &&
42d180dd
EN
426 cat >expected <<-\EOF &&
427 1
428 2
429 3
430 4
431 5
432 6
433 7
434 8
435 9
436 10
437 <<<<<<< HEAD:sub/file
438 11
439 =======
440 12
441 >>>>>>> renamed-file-has-conflicts:dir
442 EOF
3398f2f5
EN
443 test_cmp expected dir~renamed-file-has-conflicts
444'
445
588504b6
EN
446test_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 &&
451
452 mkdir one &&
453 echo stuff >one/file &&
454 git add -A &&
a316b954 455 git commit -m "Common commit" &&
588504b6
EN
456
457 git mv one/file destdir &&
458 git commit -m "Renamed to destdir" &&
459
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"
466'
467
a0de2f6b 468test_expect_success 'both rename source and destination involved in D/F conflict' '
588504b6
EN
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 &&
473
9f6cea97 474 test 1 -eq "$(git ls-files -u | wc -l)" &&
588504b6
EN
475
476 test_must_fail git diff --quiet &&
477
b821ca78
EN
478 test_path_is_file destdir/foo &&
479 test_path_is_file one &&
480 test_path_is_file destdir~HEAD &&
588504b6
EN
481 test "stuff" = "$(cat destdir~HEAD)"
482'
483
52304ecd
EN
484test_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 &&
489
490 mkdir one &&
491 mkdir two &&
492 echo stuff >one/file &&
493 echo other >two/file &&
494 git add -A &&
a316b954 495 git commit -m "Common commit" &&
52304ecd
EN
496
497 git rm -rf one &&
498 git mv two/file one &&
499 git commit -m "Rename two/file -> one" &&
500
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"
506'
507
a0de2f6b 508test_expect_success 'pair rename to parent of other (D/F conflicts) w/ untracked dir' '
52304ecd
EN
509 git checkout -q rename-one^0 &&
510 mkdir one &&
511 test_must_fail git merge --strategy=recursive rename-two &&
512
9f6cea97
BG
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)" &&
52304ecd
EN
516
517 test_must_fail git diff --quiet &&
518
9f6cea97 519 test 4 -eq $(find . | grep -v .git | wc -l) &&
52304ecd 520
b821ca78
EN
521 test_path_is_dir one &&
522 test_path_is_file one~rename-two &&
523 test_path_is_file two &&
52304ecd
EN
524 test "other" = $(cat one~rename-two) &&
525 test "stuff" = $(cat two)
526'
527
528test_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 &&
532
9f6cea97
BG
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)" &&
52304ecd
EN
536
537 test_must_fail git diff --quiet &&
538
9f6cea97 539 test 3 -eq $(find . | grep -v .git | wc -l) &&
52304ecd 540
b821ca78
EN
541 test_path_is_file one &&
542 test_path_is_file two &&
52304ecd
EN
543 test "other" = $(cat one) &&
544 test "stuff" = $(cat two)
545'
546
70798348
EN
547test_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 &&
552
553 echo stuff >original &&
554 git add -A &&
a316b954 555 git commit -m "Common commit" &&
70798348
EN
556
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" &&
562
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"
569'
570
07413c5a 571test_expect_success 'check handling of differently renamed file with D/F conflicts' '
70798348
EN
572 git checkout -q first-rename^0 &&
573 test_must_fail git merge --strategy=recursive second-rename &&
574
9f6cea97
BG
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)" &&
70798348 581
b821ca78
EN
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
70798348
EN
587'
588
589test_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 &&
594
595 echo stuff >original &&
596 mkdir one two &&
597 touch one/file two/file &&
598 git add -A &&
a316b954 599 git commit -m "Common commit" &&
70798348
EN
600
601 git rm -rf one &&
602 git mv original one &&
603 git commit -m "Rename to one" &&
604
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"
609'
610
2adc7dcc 611test_expect_success 'check handling of differently renamed file with D/F conflicts' '
70798348
EN
612 git checkout -q first-rename-redo^0 &&
613 test_must_fail git merge --strategy=recursive second-rename-redo &&
614
9f6cea97
BG
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)" &&
70798348 620
b821ca78
EN
621 test_path_is_file one &&
622 test_path_is_file two &&
623 test_path_is_missing original
70798348
EN
624'
625
f1a0f457
EN
626test_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 &&
631
632 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >original &&
633 git add -A &&
a316b954 634 git commit -m "Common commit" &&
f1a0f457
EN
635
636 git mv original rename &&
637 echo 11 >>rename &&
638 git add -u &&
639 git commit -m "Renamed and modified" &&
640
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"
645'
646
5b448b85 647test_expect_success 'avoid unnecessary update, normal rename' '
f1a0f457 648 git checkout -q avoid-unnecessary-update-1^0 &&
70e24186 649 test-tool chmtime --get -3600 rename >expect &&
f1a0f457 650 git merge merge-branch-1 &&
deb9845a 651 test-tool chmtime --get rename >actual &&
f1a0f457
EN
652 test_cmp expect actual # "rename" should have stayed intact
653'
654
655test_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 &&
660
661 mkdir df &&
662 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >df/file &&
663 git add -A &&
a316b954 664 git commit -m "Common commit" &&
f1a0f457
EN
665
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" &&
672
673 git checkout -b merge-branch-2 HEAD~1 &&
674 >unrelated-change &&
675 git add unrelated-change &&
676 git commit -m "Only unrelated changes"
677'
678
5b448b85 679test_expect_success 'avoid unnecessary update, with D/F conflict' '
f1a0f457 680 git checkout -q avoid-unnecessary-update-2^0 &&
70e24186 681 test-tool chmtime --get -3600 df >expect &&
f1a0f457 682 git merge merge-branch-2 &&
deb9845a 683 test-tool chmtime --get df >actual &&
f1a0f457
EN
684 test_cmp expect actual # "df" should have stayed intact
685'
686
3e333a61
EN
687test_expect_success 'setup avoid unnecessary update, dir->(file,nothing)' '
688 git rm -rf . &&
689 git clean -fdqx &&
690 rm -rf .git &&
691 git init &&
692
693 >irrelevant &&
694 mkdir df &&
695 >df/file &&
696 git add -A &&
697 git commit -mA &&
698
99094a7a 699 git checkout -b side &&
3e333a61
EN
700 git rm -rf df &&
701 git commit -mB &&
702
703 git checkout master &&
704 git rm -rf df &&
705 echo bla >df &&
706 git add -A &&
707 git commit -m "Add a newfile"
708'
709
35a74abf 710test_expect_success 'avoid unnecessary update, dir->(file,nothing)' '
3e333a61 711 git checkout -q master^0 &&
70e24186 712 test-tool chmtime --get -3600 df >expect &&
3e333a61 713 git merge side &&
deb9845a 714 test-tool chmtime --get df >actual &&
3e333a61
EN
715 test_cmp expect actual # "df" should have stayed intact
716'
717
718test_expect_success 'setup avoid unnecessary update, modify/delete' '
719 git rm -rf . &&
720 git clean -fdqx &&
721 rm -rf .git &&
722 git init &&
723
724 >irrelevant &&
725 >file &&
726 git add -A &&
727 git commit -mA &&
728
99094a7a 729 git checkout -b side &&
3e333a61
EN
730 git rm -f file &&
731 git commit -m "Delete file" &&
732
733 git checkout master &&
734 echo bla >file &&
735 git add -A &&
736 git commit -m "Modify file"
737'
738
35a74abf 739test_expect_success 'avoid unnecessary update, modify/delete' '
3e333a61 740 git checkout -q master^0 &&
70e24186 741 test-tool chmtime --get -3600 file >expect &&
3e333a61 742 test_must_fail git merge side &&
deb9845a 743 test-tool chmtime --get file >actual &&
3e333a61
EN
744 test_cmp expect actual # "file" should have stayed intact
745'
746
747test_expect_success 'setup avoid unnecessary update, rename/add-dest' '
748 git rm -rf . &&
749 git clean -fdqx &&
750 rm -rf .git &&
751 git init &&
752
753 printf "1\n2\n3\n4\n5\n6\n7\n8\n" >file &&
754 git add -A &&
755 git commit -mA &&
756
99094a7a 757 git checkout -b side &&
3e333a61
EN
758 cp file newfile &&
759 git add -A &&
760 git commit -m "Add file copy" &&
761
762 git checkout master &&
763 git mv file newfile &&
764 git commit -m "Rename file"
765'
766
35a74abf 767test_expect_success 'avoid unnecessary update, rename/add-dest' '
3e333a61 768 git checkout -q master^0 &&
70e24186 769 test-tool chmtime --get -3600 newfile >expect &&
3e333a61 770 git merge side &&
deb9845a 771 test-tool chmtime --get newfile >actual &&
3e333a61
EN
772 test_cmp expect actual # "file" should have stayed intact
773'
774
7dd9c304
EN
775test_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 &&
780
781 echo ORIGINAL >file &&
782 git add file &&
783
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
792'
793
794test_expect_success 'merge rename + small change' '
795 git merge rename_branch &&
796
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)
800'
801
3c217c07
EN
802test_expect_success 'setup for use of extended merge markers' '
803 git rm -rf . &&
804 git clean -fdqx &&
805 rm -rf .git &&
806 git init &&
807
808 printf "1\n2\n3\n4\n5\n6\n7\n8\n" >original_file &&
809 git add original_file &&
810 git commit -mA &&
811
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 &&
817
818 git checkout master &&
819 echo 8.5 >>original_file &&
820 git add original_file &&
821 git commit -mC
822'
823
3c217c07
EN
824test_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 &&
42d180dd
EN
827
828 cat >expected <<-\EOF &&
829 1
830 2
831 3
832 4
833 5
834 6
835 7
836 8
837 <<<<<<< HEAD:renamed_file
838 9
839 =======
840 8.5
841 >>>>>>> master^0:original_file
842 EOF
3c217c07
EN
843 test_cmp expected renamed_file
844'
845
3c217c07
EN
846test_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 &&
42d180dd
EN
850
851 cat >expected <<-\EOF &&
852 1
853 2
854 3
855 4
856 5
857 6
858 7
859 8
860 <<<<<<< HEAD:original_file
861 8.5
862 =======
863 9
864 >>>>>>> rename^0:renamed_file
865 EOF
3c217c07
EN
866 test_cmp expected renamed_file
867'
868
3f680ff0
EN
869test_expect_success 'setup spurious "refusing to lose untracked" message' '
870 git rm -rf . &&
871 git clean -fdqx &&
872 rm -rf .git &&
873 git init &&
874
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 &&
879
880 git checkout -b rename &&
881 git mv original_file renamed_file &&
882 git commit -mB &&
883
884 git checkout master &&
885 git rm original_file &&
886 git commit -mC
887'
888
f53d3977 889test_expect_success 'no spurious "refusing to lose untracked" message' '
3f680ff0
EN
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
893'
894
4f7cb99a
JK
895test_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 &&
d3c6751b 907 test_must_be_empty empty2
4f7cb99a
JK
908'
909
b825e6ff 910test_done