]> git.ipfire.org Git - thirdparty/git.git/blame - t/t6402-merge-rename.sh
The third batch
[thirdparty/git.git] / t / t6402-merge-rename.sh
CommitLineData
b825e6ff
JH
1#!/bin/sh
2
3test_description='Merge-recursive merging renames'
5902f5f4 4GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
5export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
b825e6ff
JH
7. ./test-lib.sh
8
af6e1751
EN
9modify () {
10 sed -e "$1" <"$2" >"$2.x" &&
11 mv "$2.x" "$2"
12}
13
42d180dd
EN
14test_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
32
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
50
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 &&
59
5902f5f4 60 sed -e "/^g /s/.*/g : main changes a line/" <A >A+ &&
42d180dd 61 mv A+ A &&
5902f5f4 62 git commit -a -m "main updates A" &&
42d180dd
EN
63
64 git checkout yellow &&
65 rm -f M &&
66 git commit -a -m "yellow removes M" &&
67
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" &&
74
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" &&
81
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" &&
88
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" &&
93
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" &&
99
5902f5f4 100 git checkout main
42d180dd 101'
b825e6ff
JH
102
103test_expect_success 'pull renaming branch into unrenaming one' \
104'
cae3aa79 105 git show-branch &&
031e2f7a 106 test_expect_code 1 git pull --no-rebase . white &&
cae3aa79 107 git ls-files -s &&
ba8c2680
ĐTCD
108 test_stdout_line_count = 3 git ls-files -u B &&
109 test_stdout_line_count = 1 git ls-files -s N &&
b825e6ff
JH
110 sed -ne "/^g/{
111 p
112 q
5902f5f4 113 }" B | grep main &&
cae3aa79 114 git diff --exit-code white N
b825e6ff
JH
115'
116
117test_expect_success 'pull renaming branch into another renaming one' \
118'
cae3aa79
JN
119 rm -f B &&
120 git reset --hard &&
121 git checkout red &&
031e2f7a 122 test_expect_code 1 git pull --no-rebase . white &&
ba8c2680
ĐTCD
123 test_stdout_line_count = 3 git ls-files -u B &&
124 test_stdout_line_count = 1 git ls-files -s N &&
b825e6ff
JH
125 sed -ne "/^g/{
126 p
127 q
cae3aa79
JN
128 }" B | grep red &&
129 git diff --exit-code white N
b825e6ff
JH
130'
131
132test_expect_success 'pull unrenaming branch into renaming one' \
133'
cae3aa79
JN
134 git reset --hard &&
135 git show-branch &&
031e2f7a 136 test_expect_code 1 git pull --no-rebase . main &&
ba8c2680
ĐTCD
137 test_stdout_line_count = 3 git ls-files -u B &&
138 test_stdout_line_count = 1 git ls-files -s N &&
b825e6ff
JH
139 sed -ne "/^g/{
140 p
141 q
cae3aa79
JN
142 }" B | grep red &&
143 git diff --exit-code white N
b825e6ff
JH
144'
145
724b511d
JH
146test_expect_success 'pull conflicting renames' \
147'
cae3aa79
JN
148 git reset --hard &&
149 git show-branch &&
031e2f7a 150 test_expect_code 1 git pull --no-rebase . blue &&
ba8c2680
ĐTCD
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 &&
724b511d
JH
155 sed -ne "/^g/{
156 p
157 q
cae3aa79
JN
158 }" B | grep red &&
159 git diff --exit-code white N
5b329a5f
JH
160'
161
162test_expect_success 'interference with untracked working tree file' '
cae3aa79
JN
163 git reset --hard &&
164 git show-branch &&
165 echo >A this file should not matter &&
031e2f7a 166 test_expect_code 1 git pull --no-rebase . white &&
cae3aa79 167 test_path_is_file A
5b329a5f
JH
168'
169
170test_expect_success 'interference with untracked working tree file' '
cae3aa79
JN
171 git reset --hard &&
172 git checkout white &&
173 git show-branch &&
174 rm -f A &&
175 echo >A this file should not matter &&
031e2f7a 176 test_expect_code 1 git pull --no-rebase . red &&
cae3aa79 177 test_path_is_file A
5b329a5f
JH
178'
179
180test_expect_success 'interference with untracked working tree file' '
cae3aa79
JN
181 git reset --hard &&
182 rm -f A M &&
5902f5f4 183 git checkout -f main &&
cae3aa79
JN
184 git tag -f anchor &&
185 git show-branch &&
031e2f7a 186 git pull --no-rebase . yellow &&
cae3aa79 187 test_path_is_missing M &&
5b329a5f
JH
188 git reset --hard anchor
189'
190
191test_expect_success 'updated working tree file should prevent the merge' '
cae3aa79
JN
192 git reset --hard &&
193 rm -f A M &&
5902f5f4 194 git checkout -f main &&
cae3aa79
JN
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 &&
5b329a5f
JH
201 rm -f M.saved
202'
203
204test_expect_success 'updated working tree file should prevent the merge' '
cae3aa79
JN
205 git reset --hard &&
206 rm -f A M &&
5902f5f4 207 git checkout -f main &&
cae3aa79
JN
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 &&
8f240b8b 213 test_expect_code 2 git pull --no-rebase . yellow &&
cae3aa79 214 test_cmp M M.saved &&
5b329a5f
JH
215 rm -f M.saved
216'
217
218test_expect_success 'interference with untracked working tree file' '
cae3aa79
JN
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 &&
031e2f7a 225 git pull --no-rebase . main &&
cae3aa79
JN
226 test_path_is_file M &&
227 ! {
228 git ls-files -s |
229 grep M
230 } &&
5b329a5f 231 git reset --hard anchor
724b511d
JH
232'
233
8a359819 234test_expect_success 'merge of identical changes in a renamed file' '
cae3aa79 235 rm -f A M N &&
8a359819
AR
236 git reset --hard &&
237 git checkout change+rename &&
9f697ded 238
70e24186 239 test-tool chmtime --get -3600 B >old-mtime &&
cc04adc2 240 GIT_MERGE_VERBOSITY=3 git merge change >out &&
9f697ded
EN
241
242 test-tool chmtime --get B >new-mtime &&
243 test_cmp old-mtime new-mtime &&
244
8a359819
AR
245 git reset --hard HEAD^ &&
246 git checkout change &&
9f697ded 247
70e24186
EN
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 &&
cc04adc2 251 GIT_MERGE_VERBOSITY=3 git merge change+rename >out &&
9f697ded 252
70e24186 253 test_path_is_missing A &&
9f697ded
EN
254 test-tool chmtime --get B >new-mtime &&
255 test $(cat old-mtime) -lt $(cat new-mtime)
8a359819
AR
256'
257
af6e1751
EN
258test_expect_success 'setup for rename + d/f conflicts' '
259 git reset --hard &&
260 git checkout --orphan dir-in-way &&
261 git rm -rf . &&
5b5261ba 262 git clean -fdqx &&
af6e1751
EN
263
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 &&
a316b954 269 git commit -m "Common commit" &&
af6e1751
EN
270
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" &&
275
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 &&
280
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" &&
287
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"
294'
295
af6e1751
EN
296test_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 &&
42d180dd 299
af6e1751 300 git merge --strategy=recursive dir-not-in-way &&
42d180dd 301
af6e1751 302 git diff --quiet &&
b821ca78
EN
303 test_path_is_file dir &&
304 test_write_lines 1 2 3 4 5555 6 7 8 9 10 11 >expected &&
af6e1751
EN
305 test_cmp expected dir
306'
307
4ab9a157 308test_expect_success 'Rename+D/F conflict; renamed file merges but dir in way' '
af6e1751
EN
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 &&
313
6789275d
JH
314 test_grep "CONFLICT (modify/delete): dir/file-in-the-way" output &&
315 test_grep "Auto-merging dir" output &&
c8c35f6a
EN
316 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
317 then
6789275d 318 test_grep "moving it to dir~HEAD instead" output
c8c35f6a 319 else
6789275d 320 test_grep "Adding as dir~HEAD instead" output
c8c35f6a 321 fi &&
af6e1751 322
ba8c2680
ĐTCD
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 &&
af6e1751
EN
325
326 test_must_fail git diff --quiet &&
327 test_must_fail git diff --cached --quiet &&
328
b821ca78
EN
329 test_path_is_file dir/file-in-the-way &&
330 test_path_is_file dir~HEAD &&
af6e1751
EN
331 test_cmp expected dir~HEAD
332'
333
4ab9a157 334test_expect_success 'Same as previous, but merged other way' '
3398f2f5
EN
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 &&
339
340 ! grep "error: refusing to lose untracked file at" errors &&
6789275d
JH
341 test_grep "CONFLICT (modify/delete): dir/file-in-the-way" output &&
342 test_grep "Auto-merging dir" output &&
c8c35f6a
EN
343 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
344 then
6789275d 345 test_grep "moving it to dir~renamed-file-has-no-conflicts instead" output
c8c35f6a 346 else
6789275d 347 test_grep "Adding as dir~renamed-file-has-no-conflicts instead" output
c8c35f6a 348 fi &&
3398f2f5 349
ba8c2680
ĐTCD
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 &&
3398f2f5
EN
352
353 test_must_fail git diff --quiet &&
354 test_must_fail git diff --cached --quiet &&
355
b821ca78
EN
356 test_path_is_file dir/file-in-the-way &&
357 test_path_is_file dir~renamed-file-has-no-conflicts &&
3398f2f5
EN
358 test_cmp expected dir~renamed-file-has-no-conflicts
359'
360
882fd11a 361test_expect_success 'Rename+D/F conflict; renamed file cannot merge, dir not in way' '
af6e1751
EN
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 &&
366
ba8c2680
ĐTCD
367 test_stdout_line_count = 3 git ls-files -u &&
368 test_stdout_line_count = 3 git ls-files -u dir &&
af6e1751
EN
369
370 test_must_fail git diff --quiet &&
371 test_must_fail git diff --cached --quiet &&
372
b821ca78 373 test_path_is_file dir &&
42d180dd
EN
374 cat >expected <<-\EOF &&
375 1
376 2
377 3
378 4
379 5
380 6
381 7
382 8
383 9
384 10
385 <<<<<<< HEAD:dir
386 12
387 =======
388 11
389 >>>>>>> dir-not-in-way:sub/file
390 EOF
af6e1751
EN
391 test_cmp expected dir
392'
393
4ab9a157 394test_expect_success 'Rename+D/F conflict; renamed file cannot merge and dir in the way' '
af6e1751
EN
395 modify s/dir-not-in-way/dir-in-way/ expected &&
396
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 &&
401
ba8c2680 402 test_stdout_line_count = 5 git ls-files -u &&
ef527787
EN
403 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
404 then
ba8c2680 405 test_stdout_line_count = 3 git ls-files -u dir~HEAD
ef527787 406 else
ba8c2680
ĐTCD
407 git ls-files -u dir >out &&
408 test 3 -eq $(grep -v file-in-the-way out | wc -l) &&
409 rm -f out
ef527787 410 fi &&
ba8c2680 411 test_stdout_line_count = 2 git ls-files -u dir/file-in-the-way &&
af6e1751
EN
412
413 test_must_fail git diff --quiet &&
414 test_must_fail git diff --cached --quiet &&
415
b821ca78
EN
416 test_path_is_file dir/file-in-the-way &&
417 test_path_is_file dir~HEAD &&
af6e1751
EN
418 test_cmp expected dir~HEAD
419'
420
4ab9a157 421test_expect_success 'Same as previous, but merged other way' '
3398f2f5
EN
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 &&
426
ba8c2680 427 test_stdout_line_count = 5 git ls-files -u &&
ef527787
EN
428 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
429 then
ba8c2680 430 test_stdout_line_count = 3 git ls-files -u dir~renamed-file-has-conflicts
ef527787 431 else
ba8c2680
ĐTCD
432 git ls-files -u dir >out &&
433 test 3 -eq $(grep -v file-in-the-way out | wc -l) &&
434 rm -f out
ef527787 435 fi &&
ba8c2680 436 test_stdout_line_count = 2 git ls-files -u dir/file-in-the-way &&
3398f2f5
EN
437
438 test_must_fail git diff --quiet &&
439 test_must_fail git diff --cached --quiet &&
440
b821ca78
EN
441 test_path_is_file dir/file-in-the-way &&
442 test_path_is_file dir~renamed-file-has-conflicts &&
42d180dd
EN
443 cat >expected <<-\EOF &&
444 1
445 2
446 3
447 4
448 5
449 6
450 7
451 8
452 9
453 10
454 <<<<<<< HEAD:sub/file
455 11
456 =======
457 12
458 >>>>>>> renamed-file-has-conflicts:dir
459 EOF
3398f2f5
EN
460 test_cmp expected dir~renamed-file-has-conflicts
461'
462
588504b6
EN
463test_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 &&
468
469 mkdir one &&
470 echo stuff >one/file &&
471 git add -A &&
a316b954 472 git commit -m "Common commit" &&
588504b6
EN
473
474 git mv one/file destdir &&
475 git commit -m "Renamed to destdir" &&
476
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"
483'
484
a0de2f6b 485test_expect_success 'both rename source and destination involved in D/F conflict' '
588504b6
EN
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 &&
490
ef527787
EN
491 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
492 then
ba8c2680 493 test_stdout_line_count = 2 git ls-files -u
ef527787 494 else
ba8c2680 495 test_stdout_line_count = 1 git ls-files -u
ef527787 496 fi &&
588504b6
EN
497
498 test_must_fail git diff --quiet &&
499
b821ca78
EN
500 test_path_is_file destdir/foo &&
501 test_path_is_file one &&
502 test_path_is_file destdir~HEAD &&
588504b6
EN
503 test "stuff" = "$(cat destdir~HEAD)"
504'
505
52304ecd
EN
506test_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 &&
511
512 mkdir one &&
513 mkdir two &&
514 echo stuff >one/file &&
515 echo other >two/file &&
516 git add -A &&
a316b954 517 git commit -m "Common commit" &&
52304ecd
EN
518
519 git rm -rf one &&
520 git mv two/file one &&
521 git commit -m "Rename two/file -> one" &&
522
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"
528'
529
ef527787
EN
530if test "$GIT_TEST_MERGE_ALGORITHM" = ort
531then
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 &&
52304ecd 536
ba8c2680
ĐTCD
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 &&
52304ecd 540
ef527787 541 test_must_fail git diff --quiet &&
52304ecd 542
ef527787 543 test 3 -eq $(find . | grep -v .git | wc -l) &&
52304ecd 544
ef527787
EN
545 test_path_is_file one &&
546 test_path_is_file two &&
547 test "other" = $(cat one) &&
548 test "stuff" = $(cat two)
549 '
550else
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 &&
555
ba8c2680
ĐTCD
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 &&
ef527787
EN
559
560 test_must_fail git diff --quiet &&
561
562 test 4 -eq $(find . | grep -v .git | wc -l) &&
563
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)
569 '
570fi
52304ecd
EN
571
572test_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 &&
576
ef527787
EN
577 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
578 then
ba8c2680
ĐTCD
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
ef527787 582 else
ba8c2680
ĐTCD
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
ef527787 586 fi &&
52304ecd
EN
587
588 test_must_fail git diff --quiet &&
589
9f6cea97 590 test 3 -eq $(find . | grep -v .git | wc -l) &&
52304ecd 591
b821ca78
EN
592 test_path_is_file one &&
593 test_path_is_file two &&
52304ecd
EN
594 test "other" = $(cat one) &&
595 test "stuff" = $(cat two)
596'
597
70798348
EN
598test_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 &&
603
604 echo stuff >original &&
605 git add -A &&
a316b954 606 git commit -m "Common commit" &&
70798348
EN
607
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" &&
613
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"
620'
621
07413c5a 622test_expect_success 'check handling of differently renamed file with D/F conflicts' '
70798348
EN
623 git checkout -q first-rename^0 &&
624 test_must_fail git merge --strategy=recursive second-rename &&
625
ef527787
EN
626 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
627 then
ba8c2680
ĐTCD
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
ef527787 634 else
ba8c2680
ĐTCD
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
ef527787 641 fi &&
70798348 642
b821ca78
EN
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
70798348
EN
648'
649
650test_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 &&
655
656 echo stuff >original &&
657 mkdir one two &&
658 touch one/file two/file &&
659 git add -A &&
a316b954 660 git commit -m "Common commit" &&
70798348
EN
661
662 git rm -rf one &&
663 git mv original one &&
664 git commit -m "Rename to one" &&
665
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"
670'
671
2adc7dcc 672test_expect_success 'check handling of differently renamed file with D/F conflicts' '
70798348
EN
673 git checkout -q first-rename-redo^0 &&
674 test_must_fail git merge --strategy=recursive second-rename-redo &&
675
ba8c2680
ĐTCD
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 &&
70798348 681
b821ca78
EN
682 test_path_is_file one &&
683 test_path_is_file two &&
684 test_path_is_missing original
70798348
EN
685'
686
f1a0f457
EN
687test_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 &&
692
693 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >original &&
694 git add -A &&
a316b954 695 git commit -m "Common commit" &&
f1a0f457
EN
696
697 git mv original rename &&
698 echo 11 >>rename &&
699 git add -u &&
700 git commit -m "Renamed and modified" &&
701
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"
706'
707
5b448b85 708test_expect_success 'avoid unnecessary update, normal rename' '
f1a0f457 709 git checkout -q avoid-unnecessary-update-1^0 &&
70e24186 710 test-tool chmtime --get -3600 rename >expect &&
f1a0f457 711 git merge merge-branch-1 &&
deb9845a 712 test-tool chmtime --get rename >actual &&
f1a0f457
EN
713 test_cmp expect actual # "rename" should have stayed intact
714'
715
716test_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 &&
721
722 mkdir df &&
723 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >df/file &&
724 git add -A &&
a316b954 725 git commit -m "Common commit" &&
f1a0f457
EN
726
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" &&
733
734 git checkout -b merge-branch-2 HEAD~1 &&
735 >unrelated-change &&
736 git add unrelated-change &&
737 git commit -m "Only unrelated changes"
738'
739
5b448b85 740test_expect_success 'avoid unnecessary update, with D/F conflict' '
f1a0f457 741 git checkout -q avoid-unnecessary-update-2^0 &&
70e24186 742 test-tool chmtime --get -3600 df >expect &&
f1a0f457 743 git merge merge-branch-2 &&
deb9845a 744 test-tool chmtime --get df >actual &&
f1a0f457
EN
745 test_cmp expect actual # "df" should have stayed intact
746'
747
3e333a61
EN
748test_expect_success 'setup avoid unnecessary update, dir->(file,nothing)' '
749 git rm -rf . &&
750 git clean -fdqx &&
751 rm -rf .git &&
752 git init &&
753
754 >irrelevant &&
755 mkdir df &&
756 >df/file &&
757 git add -A &&
758 git commit -mA &&
759
99094a7a 760 git checkout -b side &&
3e333a61
EN
761 git rm -rf df &&
762 git commit -mB &&
763
5902f5f4 764 git checkout main &&
3e333a61
EN
765 git rm -rf df &&
766 echo bla >df &&
767 git add -A &&
768 git commit -m "Add a newfile"
769'
770
35a74abf 771test_expect_success 'avoid unnecessary update, dir->(file,nothing)' '
5902f5f4 772 git checkout -q main^0 &&
70e24186 773 test-tool chmtime --get -3600 df >expect &&
3e333a61 774 git merge side &&
deb9845a 775 test-tool chmtime --get df >actual &&
3e333a61
EN
776 test_cmp expect actual # "df" should have stayed intact
777'
778
779test_expect_success 'setup avoid unnecessary update, modify/delete' '
780 git rm -rf . &&
781 git clean -fdqx &&
782 rm -rf .git &&
783 git init &&
784
785 >irrelevant &&
786 >file &&
787 git add -A &&
788 git commit -mA &&
789
99094a7a 790 git checkout -b side &&
3e333a61
EN
791 git rm -f file &&
792 git commit -m "Delete file" &&
793
5902f5f4 794 git checkout main &&
3e333a61
EN
795 echo bla >file &&
796 git add -A &&
797 git commit -m "Modify file"
798'
799
35a74abf 800test_expect_success 'avoid unnecessary update, modify/delete' '
5902f5f4 801 git checkout -q main^0 &&
70e24186 802 test-tool chmtime --get -3600 file >expect &&
3e333a61 803 test_must_fail git merge side &&
deb9845a 804 test-tool chmtime --get file >actual &&
3e333a61
EN
805 test_cmp expect actual # "file" should have stayed intact
806'
807
808test_expect_success 'setup avoid unnecessary update, rename/add-dest' '
809 git rm -rf . &&
810 git clean -fdqx &&
811 rm -rf .git &&
812 git init &&
813
814 printf "1\n2\n3\n4\n5\n6\n7\n8\n" >file &&
815 git add -A &&
816 git commit -mA &&
817
99094a7a 818 git checkout -b side &&
3e333a61
EN
819 cp file newfile &&
820 git add -A &&
821 git commit -m "Add file copy" &&
822
5902f5f4 823 git checkout main &&
3e333a61
EN
824 git mv file newfile &&
825 git commit -m "Rename file"
826'
827
35a74abf 828test_expect_success 'avoid unnecessary update, rename/add-dest' '
5902f5f4 829 git checkout -q main^0 &&
70e24186 830 test-tool chmtime --get -3600 newfile >expect &&
3e333a61 831 git merge side &&
deb9845a 832 test-tool chmtime --get newfile >actual &&
3e333a61
EN
833 test_cmp expect actual # "file" should have stayed intact
834'
835
7dd9c304
EN
836test_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 &&
841
842 echo ORIGINAL >file &&
843 git add file &&
844
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
853'
854
855test_expect_success 'merge rename + small change' '
856 git merge rename_branch &&
857
ba8c2680
ĐTCD
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
7dd9c304
EN
863'
864
3c217c07
EN
865test_expect_success 'setup for use of extended merge markers' '
866 git rm -rf . &&
867 git clean -fdqx &&
868 rm -rf .git &&
869 git init &&
870
871 printf "1\n2\n3\n4\n5\n6\n7\n8\n" >original_file &&
872 git add original_file &&
873 git commit -mA &&
874
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 &&
880
5902f5f4 881 git checkout main &&
3c217c07
EN
882 echo 8.5 >>original_file &&
883 git add original_file &&
884 git commit -mC
885'
886
5902f5f4 887test_expect_success 'merge main into rename has correct extended markers' '
3c217c07 888 git checkout rename^0 &&
5902f5f4 889 test_must_fail git merge -s recursive main^0 &&
42d180dd
EN
890
891 cat >expected <<-\EOF &&
892 1
893 2
894 3
895 4
896 5
897 6
898 7
899 8
900 <<<<<<< HEAD:renamed_file
901 9
902 =======
903 8.5
5902f5f4 904 >>>>>>> main^0:original_file
42d180dd 905 EOF
3c217c07
EN
906 test_cmp expected renamed_file
907'
908
5902f5f4 909test_expect_success 'merge rename into main has correct extended markers' '
3c217c07 910 git reset --hard &&
5902f5f4 911 git checkout main^0 &&
3c217c07 912 test_must_fail git merge -s recursive rename^0 &&
42d180dd
EN
913
914 cat >expected <<-\EOF &&
915 1
916 2
917 3
918 4
919 5
920 6
921 7
922 8
923 <<<<<<< HEAD:original_file
924 8.5
925 =======
926 9
927 >>>>>>> rename^0:renamed_file
928 EOF
3c217c07
EN
929 test_cmp expected renamed_file
930'
931
3f680ff0
EN
932test_expect_success 'setup spurious "refusing to lose untracked" message' '
933 git rm -rf . &&
934 git clean -fdqx &&
935 rm -rf .git &&
936 git init &&
937
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 &&
942
943 git checkout -b rename &&
944 git mv original_file renamed_file &&
945 git commit -mB &&
946
5902f5f4 947 git checkout main &&
3f680ff0
EN
948 git rm original_file &&
949 git commit -mC
950'
951
f53d3977 952test_expect_success 'no spurious "refusing to lose untracked" message' '
5902f5f4 953 git checkout main^0 &&
3f680ff0
EN
954 test_must_fail git merge rename^0 2>errors.txt &&
955 ! grep "refusing to lose untracked file" errors.txt
956'
957
4f7cb99a
JK
958test_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 &&
d3c6751b 970 test_must_be_empty empty2
4f7cb99a
JK
971'
972
b825e6ff 973test_done