]> git.ipfire.org Git - thirdparty/git.git/blame - t/t6423-merge-rename-directories.sh
t6422: fix multiple errors with the mod6 test expectations
[thirdparty/git.git] / t / t6423-merge-rename-directories.sh
CommitLineData
04550ab5
EN
1#!/bin/sh
2
3test_description="recursive merge with directory renames"
4# includes checking of many corner cases, with a similar methodology to:
5# t6042: corner cases with renames but not criss-cross merges
6# t6036: corner cases with both renames and criss-cross merges
7#
8# The setup for all of them, pictorially, is:
9#
10# A
11# o
12# / \
13# O o ?
14# \ /
15# o
16# B
17#
18# To help make it easier to follow the flow of tests, they have been
19# divided into sections and each test will start with a quick explanation
20# of what commits O, A, and B contain.
21#
22# Notation:
23# z/{b,c} means files z/b and z/c both exist
24# x/d_1 means file x/d exists with content d1. (Purpose of the
25# underscore notation is to differentiate different
26# files that might be renamed into each other's paths.)
27
28. ./test-lib.sh
29
30
31###########################################################################
32# SECTION 1: Basic cases we should be able to handle
33###########################################################################
34
35# Testcase 1a, Basic directory rename.
36# Commit O: z/{b,c}
37# Commit A: y/{b,c}
38# Commit B: z/{b,c,d,e/f}
39# Expected: y/{b,c,d,e/f}
40
da1e295e 41test_setup_1a () {
04550ab5
EN
42 test_create_repo 1a &&
43 (
44 cd 1a &&
45
46 mkdir z &&
47 echo b >z/b &&
48 echo c >z/c &&
49 git add z &&
50 test_tick &&
51 git commit -m "O" &&
52
53 git branch O &&
54 git branch A &&
55 git branch B &&
56
57 git checkout A &&
58 git mv z y &&
59 test_tick &&
60 git commit -m "A" &&
61
62 git checkout B &&
63 echo d >z/d &&
64 mkdir z/e &&
65 echo f >z/e/f &&
66 git add z/d z/e/f &&
67 test_tick &&
68 git commit -m "B"
69 )
da1e295e 70}
04550ab5 71
da1e295e
EN
72test_expect_success '1a: Simple directory rename detection' '
73 test_setup_1a &&
04550ab5
EN
74 (
75 cd 1a &&
76
77 git checkout A^0 &&
78
8c8e5bd6 79 git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
04550ab5
EN
80
81 git ls-files -s >out &&
82 test_line_count = 4 out &&
83
84 git rev-parse >actual \
85 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:y/e/f &&
86 git rev-parse >expect \
87 O:z/b O:z/c B:z/d B:z/e/f &&
88 test_cmp expect actual &&
89
90 git hash-object y/d >actual &&
91 git rev-parse B:z/d >expect &&
92 test_cmp expect actual &&
93
94 test_must_fail git rev-parse HEAD:z/d &&
95 test_must_fail git rev-parse HEAD:z/e/f &&
96 test_path_is_missing z/d &&
97 test_path_is_missing z/e/f
98 )
99'
100
101# Testcase 1b, Merge a directory with another
102# Commit O: z/{b,c}, y/d
103# Commit A: z/{b,c,e}, y/d
104# Commit B: y/{b,c,d}
105# Expected: y/{b,c,d,e}
106
da1e295e 107test_setup_1b () {
04550ab5
EN
108 test_create_repo 1b &&
109 (
110 cd 1b &&
111
112 mkdir z &&
113 echo b >z/b &&
114 echo c >z/c &&
115 mkdir y &&
116 echo d >y/d &&
117 git add z y &&
118 test_tick &&
119 git commit -m "O" &&
120
121 git branch O &&
122 git branch A &&
123 git branch B &&
124
125 git checkout A &&
126 echo e >z/e &&
127 git add z/e &&
128 test_tick &&
129 git commit -m "A" &&
130
131 git checkout B &&
132 git mv z/b y &&
133 git mv z/c y &&
134 rmdir z &&
135 test_tick &&
136 git commit -m "B"
137 )
da1e295e 138}
04550ab5 139
da1e295e
EN
140test_expect_success '1b: Merge a directory with another' '
141 test_setup_1b &&
04550ab5
EN
142 (
143 cd 1b &&
144
145 git checkout A^0 &&
146
8c8e5bd6 147 git -c merge.directoryRenames=true merge -s recursive B^0 &&
04550ab5
EN
148
149 git ls-files -s >out &&
150 test_line_count = 4 out &&
151
152 git rev-parse >actual \
153 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:y/e &&
154 git rev-parse >expect \
155 O:z/b O:z/c O:y/d A:z/e &&
156 test_cmp expect actual &&
157 test_must_fail git rev-parse HEAD:z/e
158 )
159'
160
161# Testcase 1c, Transitive renaming
162# (Related to testcases 3a and 6d -- when should a transitive rename apply?)
163# (Related to testcases 9c and 9d -- can transitivity repeat?)
bc71c4ee 164# (Related to testcase 12b -- joint-transitivity?)
04550ab5
EN
165# Commit O: z/{b,c}, x/d
166# Commit A: y/{b,c}, x/d
167# Commit B: z/{b,c,d}
168# Expected: y/{b,c,d} (because x/d -> z/d -> y/d)
169
da1e295e 170test_setup_1c () {
04550ab5
EN
171 test_create_repo 1c &&
172 (
173 cd 1c &&
174
175 mkdir z &&
176 echo b >z/b &&
177 echo c >z/c &&
178 mkdir x &&
179 echo d >x/d &&
180 git add z x &&
181 test_tick &&
182 git commit -m "O" &&
183
184 git branch O &&
185 git branch A &&
186 git branch B &&
187
188 git checkout A &&
189 git mv z y &&
190 test_tick &&
191 git commit -m "A" &&
192
193 git checkout B &&
194 git mv x/d z/d &&
195 test_tick &&
196 git commit -m "B"
197 )
da1e295e 198}
04550ab5 199
da1e295e
EN
200test_expect_success '1c: Transitive renaming' '
201 test_setup_1c &&
04550ab5
EN
202 (
203 cd 1c &&
204
205 git checkout A^0 &&
206
8c8e5bd6 207 git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
04550ab5
EN
208
209 git ls-files -s >out &&
210 test_line_count = 3 out &&
211
212 git rev-parse >actual \
213 HEAD:y/b HEAD:y/c HEAD:y/d &&
214 git rev-parse >expect \
215 O:z/b O:z/c O:x/d &&
216 test_cmp expect actual &&
217 test_must_fail git rev-parse HEAD:x/d &&
218 test_must_fail git rev-parse HEAD:z/d &&
219 test_path_is_missing z/d
220 )
221'
222
223# Testcase 1d, Directory renames (merging two directories into one new one)
224# cause a rename/rename(2to1) conflict
225# (Related to testcases 1c and 7b)
226# Commit O. z/{b,c}, y/{d,e}
227# Commit A. x/{b,c}, y/{d,e,m,wham_1}
228# Commit B. z/{b,c,n,wham_2}, x/{d,e}
229# Expected: x/{b,c,d,e,m,n}, CONFLICT:(y/wham_1 & z/wham_2 -> x/wham)
230# Note: y/m & z/n should definitely move into x. By the same token, both
231# y/wham_1 & z/wham_2 should too...giving us a conflict.
232
da1e295e 233test_setup_1d () {
04550ab5
EN
234 test_create_repo 1d &&
235 (
236 cd 1d &&
237
238 mkdir z &&
239 echo b >z/b &&
240 echo c >z/c &&
241 mkdir y &&
242 echo d >y/d &&
243 echo e >y/e &&
244 git add z y &&
245 test_tick &&
246 git commit -m "O" &&
247
248 git branch O &&
249 git branch A &&
250 git branch B &&
251
252 git checkout A &&
253 git mv z x &&
254 echo m >y/m &&
255 echo wham1 >y/wham &&
256 git add y &&
257 test_tick &&
258 git commit -m "A" &&
259
260 git checkout B &&
261 git mv y x &&
262 echo n >z/n &&
263 echo wham2 >z/wham &&
264 git add z &&
265 test_tick &&
266 git commit -m "B"
267 )
da1e295e 268}
04550ab5 269
da1e295e
EN
270test_expect_success '1d: Directory renames cause a rename/rename(2to1) conflict' '
271 test_setup_1d &&
04550ab5
EN
272 (
273 cd 1d &&
274
275 git checkout A^0 &&
276
8c8e5bd6 277 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
04550ab5
EN
278 test_i18ngrep "CONFLICT (rename/rename)" out &&
279
280 git ls-files -s >out &&
281 test_line_count = 8 out &&
282 git ls-files -u >out &&
283 test_line_count = 2 out &&
284 git ls-files -o >out &&
bbafc9c4 285 test_line_count = 1 out &&
04550ab5
EN
286
287 git rev-parse >actual \
288 :0:x/b :0:x/c :0:x/d :0:x/e :0:x/m :0:x/n &&
289 git rev-parse >expect \
290 O:z/b O:z/c O:y/d O:y/e A:y/m B:z/n &&
291 test_cmp expect actual &&
292
293 test_must_fail git rev-parse :0:x/wham &&
294 git rev-parse >actual \
295 :2:x/wham :3:x/wham &&
296 git rev-parse >expect \
297 A:y/wham B:z/wham &&
298 test_cmp expect actual &&
299
bbafc9c4
EN
300 # Test that the two-way merge in x/wham is as expected
301 git cat-file -p :2:x/wham >expect &&
302 git cat-file -p :3:x/wham >other &&
303 >empty &&
304 test_must_fail git merge-file \
305 -L "HEAD" \
306 -L "" \
307 -L "B^0" \
308 expect empty other &&
309 test_cmp expect x/wham
04550ab5
EN
310 )
311'
312
313# Testcase 1e, Renamed directory, with all filenames being renamed too
792e1371 314# (Related to testcases 9f & 9g)
04550ab5
EN
315# Commit O: z/{oldb,oldc}
316# Commit A: y/{newb,newc}
317# Commit B: z/{oldb,oldc,d}
318# Expected: y/{newb,newc,d}
319
da1e295e 320test_setup_1e () {
04550ab5
EN
321 test_create_repo 1e &&
322 (
323 cd 1e &&
324
325 mkdir z &&
326 echo b >z/oldb &&
327 echo c >z/oldc &&
328 git add z &&
329 test_tick &&
330 git commit -m "O" &&
331
332 git branch O &&
333 git branch A &&
334 git branch B &&
335
336 git checkout A &&
337 mkdir y &&
338 git mv z/oldb y/newb &&
339 git mv z/oldc y/newc &&
340 test_tick &&
341 git commit -m "A" &&
342
343 git checkout B &&
344 echo d >z/d &&
345 git add z/d &&
346 test_tick &&
347 git commit -m "B"
348 )
da1e295e 349}
04550ab5 350
da1e295e
EN
351test_expect_success '1e: Renamed directory, with all files being renamed too' '
352 test_setup_1e &&
04550ab5
EN
353 (
354 cd 1e &&
355
356 git checkout A^0 &&
357
8c8e5bd6 358 git -c merge.directoryRenames=true merge -s recursive B^0 &&
04550ab5
EN
359
360 git ls-files -s >out &&
361 test_line_count = 3 out &&
362
363 git rev-parse >actual \
364 HEAD:y/newb HEAD:y/newc HEAD:y/d &&
365 git rev-parse >expect \
366 O:z/oldb O:z/oldc B:z/d &&
367 test_cmp expect actual &&
368 test_must_fail git rev-parse HEAD:z/d
369 )
370'
371
372# Testcase 1f, Split a directory into two other directories
373# (Related to testcases 3a, all of section 2, and all of section 4)
374# Commit O: z/{b,c,d,e,f}
375# Commit A: z/{b,c,d,e,f,g}
376# Commit B: y/{b,c}, x/{d,e,f}
377# Expected: y/{b,c}, x/{d,e,f,g}
378
da1e295e 379test_setup_1f () {
04550ab5
EN
380 test_create_repo 1f &&
381 (
382 cd 1f &&
383
384 mkdir z &&
385 echo b >z/b &&
386 echo c >z/c &&
387 echo d >z/d &&
388 echo e >z/e &&
389 echo f >z/f &&
390 git add z &&
391 test_tick &&
392 git commit -m "O" &&
393
394 git branch O &&
395 git branch A &&
396 git branch B &&
397
398 git checkout A &&
399 echo g >z/g &&
400 git add z/g &&
401 test_tick &&
402 git commit -m "A" &&
403
404 git checkout B &&
405 mkdir y &&
406 mkdir x &&
407 git mv z/b y/ &&
408 git mv z/c y/ &&
409 git mv z/d x/ &&
410 git mv z/e x/ &&
411 git mv z/f x/ &&
412 rmdir z &&
413 test_tick &&
414 git commit -m "B"
415 )
da1e295e 416}
04550ab5 417
da1e295e
EN
418test_expect_success '1f: Split a directory into two other directories' '
419 test_setup_1f &&
04550ab5
EN
420 (
421 cd 1f &&
422
423 git checkout A^0 &&
424
8c8e5bd6 425 git -c merge.directoryRenames=true merge -s recursive B^0 &&
04550ab5
EN
426
427 git ls-files -s >out &&
428 test_line_count = 6 out &&
429
430 git rev-parse >actual \
431 HEAD:y/b HEAD:y/c HEAD:x/d HEAD:x/e HEAD:x/f HEAD:x/g &&
432 git rev-parse >expect \
433 O:z/b O:z/c O:z/d O:z/e O:z/f A:z/g &&
434 test_cmp expect actual &&
435 test_path_is_missing z/g &&
436 test_must_fail git rev-parse HEAD:z/g
437 )
438'
439
440###########################################################################
441# Rules suggested by testcases in section 1:
442#
443# We should still detect the directory rename even if it wasn't just
444# the directory renamed, but the files within it. (see 1b)
445#
446# If renames split a directory into two or more others, the directory
447# with the most renames, "wins" (see 1c). However, see the testcases
448# in section 2, plus testcases 3a and 4a.
449###########################################################################
450
509555d8
EN
451
452###########################################################################
453# SECTION 2: Split into multiple directories, with equal number of paths
454#
455# Explore the splitting-a-directory rules a bit; what happens in the
456# edge cases?
457#
458# Note that there is a closely related case of a directory not being
459# split on either side of history, but being renamed differently on
460# each side. See testcase 8e for that.
461###########################################################################
462
463# Testcase 2a, Directory split into two on one side, with equal numbers of paths
464# Commit O: z/{b,c}
465# Commit A: y/b, w/c
466# Commit B: z/{b,c,d}
467# Expected: y/b, w/c, z/d, with warning about z/ -> (y/ vs. w/) conflict
da1e295e 468test_setup_2a () {
509555d8
EN
469 test_create_repo 2a &&
470 (
471 cd 2a &&
472
473 mkdir z &&
474 echo b >z/b &&
475 echo c >z/c &&
476 git add z &&
477 test_tick &&
478 git commit -m "O" &&
479
480 git branch O &&
481 git branch A &&
482 git branch B &&
483
484 git checkout A &&
485 mkdir y &&
486 mkdir w &&
487 git mv z/b y/ &&
488 git mv z/c w/ &&
489 test_tick &&
490 git commit -m "A" &&
491
492 git checkout B &&
493 echo d >z/d &&
494 git add z/d &&
495 test_tick &&
496 git commit -m "B"
497 )
da1e295e 498}
509555d8 499
da1e295e
EN
500test_expect_success '2a: Directory split into two on one side, with equal numbers of paths' '
501 test_setup_2a &&
509555d8
EN
502 (
503 cd 2a &&
504
505 git checkout A^0 &&
506
8c8e5bd6 507 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
509555d8
EN
508 test_i18ngrep "CONFLICT.*directory rename split" out &&
509
510 git ls-files -s >out &&
511 test_line_count = 3 out &&
512 git ls-files -u >out &&
513 test_line_count = 0 out &&
514 git ls-files -o >out &&
515 test_line_count = 1 out &&
516
517 git rev-parse >actual \
518 :0:y/b :0:w/c :0:z/d &&
519 git rev-parse >expect \
520 O:z/b O:z/c B:z/d &&
521 test_cmp expect actual
522 )
523'
524
525# Testcase 2b, Directory split into two on one side, with equal numbers of paths
526# Commit O: z/{b,c}
527# Commit A: y/b, w/c
528# Commit B: z/{b,c}, x/d
529# Expected: y/b, w/c, x/d; No warning about z/ -> (y/ vs. w/) conflict
da1e295e 530test_setup_2b () {
509555d8
EN
531 test_create_repo 2b &&
532 (
533 cd 2b &&
534
535 mkdir z &&
536 echo b >z/b &&
537 echo c >z/c &&
538 git add z &&
539 test_tick &&
540 git commit -m "O" &&
541
542 git branch O &&
543 git branch A &&
544 git branch B &&
545
546 git checkout A &&
547 mkdir y &&
548 mkdir w &&
549 git mv z/b y/ &&
550 git mv z/c w/ &&
551 test_tick &&
552 git commit -m "A" &&
553
554 git checkout B &&
555 mkdir x &&
556 echo d >x/d &&
557 git add x/d &&
558 test_tick &&
559 git commit -m "B"
560 )
da1e295e 561}
509555d8 562
da1e295e
EN
563test_expect_success '2b: Directory split into two on one side, with equal numbers of paths' '
564 test_setup_2b &&
509555d8
EN
565 (
566 cd 2b &&
567
568 git checkout A^0 &&
569
8c8e5bd6 570 git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
509555d8
EN
571
572 git ls-files -s >out &&
573 test_line_count = 3 out &&
574 git ls-files -u >out &&
575 test_line_count = 0 out &&
576 git ls-files -o >out &&
577 test_line_count = 1 out &&
578
579 git rev-parse >actual \
580 :0:y/b :0:w/c :0:x/d &&
581 git rev-parse >expect \
582 O:z/b O:z/c B:x/d &&
583 test_cmp expect actual &&
584 test_i18ngrep ! "CONFLICT.*directory rename split" out
585 )
586'
587
588###########################################################################
589# Rules suggested by section 2:
590#
591# None; the rule was already covered in section 1. These testcases are
592# here just to make sure the conflict resolution and necessary warning
593# messages are handled correctly.
594###########################################################################
595
21b53733
EN
596
597###########################################################################
598# SECTION 3: Path in question is the source path for some rename already
599#
600# Combining cases from Section 1 and trying to handle them could lead to
601# directory renaming detection being over-applied. So, this section
602# provides some good testcases to check that the implementation doesn't go
603# too far.
604###########################################################################
605
606# Testcase 3a, Avoid implicit rename if involved as source on other side
792e1371 607# (Related to testcases 1c, 1f, and 9h)
21b53733
EN
608# Commit O: z/{b,c,d}
609# Commit A: z/{b,c,d} (no change)
610# Commit B: y/{b,c}, x/d
611# Expected: y/{b,c}, x/d
da1e295e 612test_setup_3a () {
21b53733
EN
613 test_create_repo 3a &&
614 (
615 cd 3a &&
616
617 mkdir z &&
618 echo b >z/b &&
619 echo c >z/c &&
620 echo d >z/d &&
621 git add z &&
622 test_tick &&
623 git commit -m "O" &&
624
625 git branch O &&
626 git branch A &&
627 git branch B &&
628
629 git checkout A &&
630 test_tick &&
631 git commit --allow-empty -m "A" &&
632
633 git checkout B &&
634 mkdir y &&
635 mkdir x &&
636 git mv z/b y/ &&
637 git mv z/c y/ &&
638 git mv z/d x/ &&
639 rmdir z &&
640 test_tick &&
641 git commit -m "B"
642 )
da1e295e 643}
21b53733 644
da1e295e
EN
645test_expect_success '3a: Avoid implicit rename if involved as source on other side' '
646 test_setup_3a &&
21b53733
EN
647 (
648 cd 3a &&
649
650 git checkout A^0 &&
651
8c8e5bd6 652 git -c merge.directoryRenames=true merge -s recursive B^0 &&
21b53733
EN
653
654 git ls-files -s >out &&
655 test_line_count = 3 out &&
656
657 git rev-parse >actual \
658 HEAD:y/b HEAD:y/c HEAD:x/d &&
659 git rev-parse >expect \
660 O:z/b O:z/c O:z/d &&
661 test_cmp expect actual
662 )
663'
664
665# Testcase 3b, Avoid implicit rename if involved as source on other side
666# (Related to testcases 5c and 7c, also kind of 1e and 1f)
667# Commit O: z/{b,c,d}
668# Commit A: y/{b,c}, x/d
669# Commit B: z/{b,c}, w/d
670# Expected: y/{b,c}, CONFLICT:(z/d -> x/d vs. w/d)
671# NOTE: We're particularly checking that since z/d is already involved as
672# a source in a file rename on the same side of history, that we don't
673# get it involved in directory rename detection. If it were, we might
674# end up with CONFLICT:(z/d -> y/d vs. x/d vs. w/d), i.e. a
675# rename/rename/rename(1to3) conflict, which is just weird.
da1e295e 676test_setup_3b () {
21b53733
EN
677 test_create_repo 3b &&
678 (
679 cd 3b &&
680
681 mkdir z &&
682 echo b >z/b &&
683 echo c >z/c &&
684 echo d >z/d &&
685 git add z &&
686 test_tick &&
687 git commit -m "O" &&
688
689 git branch O &&
690 git branch A &&
691 git branch B &&
692
693 git checkout A &&
694 mkdir y &&
695 mkdir x &&
696 git mv z/b y/ &&
697 git mv z/c y/ &&
698 git mv z/d x/ &&
699 rmdir z &&
700 test_tick &&
701 git commit -m "A" &&
702
703 git checkout B &&
704 mkdir w &&
705 git mv z/d w/ &&
706 test_tick &&
707 git commit -m "B"
708 )
da1e295e 709}
21b53733 710
da1e295e
EN
711test_expect_success '3b: Avoid implicit rename if involved as source on current side' '
712 test_setup_3b &&
21b53733
EN
713 (
714 cd 3b &&
715
716 git checkout A^0 &&
717
8c8e5bd6 718 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
21b53733
EN
719 test_i18ngrep CONFLICT.*rename/rename.*z/d.*x/d.*w/d out &&
720 test_i18ngrep ! CONFLICT.*rename/rename.*y/d out &&
721
722 git ls-files -s >out &&
723 test_line_count = 5 out &&
724 git ls-files -u >out &&
725 test_line_count = 3 out &&
726 git ls-files -o >out &&
727 test_line_count = 1 out &&
728
729 git rev-parse >actual \
730 :0:y/b :0:y/c :1:z/d :2:x/d :3:w/d &&
731 git rev-parse >expect \
732 O:z/b O:z/c O:z/d O:z/d O:z/d &&
733 test_cmp expect actual &&
734
735 test_path_is_missing z/d &&
736 git hash-object >actual \
737 x/d w/d &&
738 git rev-parse >expect \
739 O:z/d O:z/d &&
740 test_cmp expect actual
741 )
742'
743
744###########################################################################
745# Rules suggested by section 3:
746#
747# Avoid directory-rename-detection for a path, if that path is the source
748# of a rename on either side of a merge.
749###########################################################################
750
de632e4e
EN
751
752###########################################################################
753# SECTION 4: Partially renamed directory; still exists on both sides of merge
754#
755# What if we were to attempt to do directory rename detection when someone
756# "mostly" moved a directory but still left some files around, or,
7a40cf15 757# equivalently, fully renamed a directory in one commit and then recreated
de632e4e
EN
758# that directory in a later commit adding some new files and then tried to
759# merge?
760#
761# It's hard to divine user intent in these cases, because you can make an
762# argument that, depending on the intermediate history of the side being
763# merged, that some users will want files in that directory to
764# automatically be detected and renamed, while users with a different
765# intermediate history wouldn't want that rename to happen.
766#
767# I think that it is best to simply not have directory rename detection
768# apply to such cases. My reasoning for this is four-fold: (1) it's
769# easiest for users in general to figure out what happened if we don't
770# apply directory rename detection in any such case, (2) it's an easy rule
771# to explain ["We don't do directory rename detection if the directory
772# still exists on both sides of the merge"], (3) we can get some hairy
773# edge/corner cases that would be really confusing and possibly not even
774# representable in the index if we were to even try, and [related to 3] (4)
775# attempting to resolve this issue of divining user intent by examining
776# intermediate history goes against the spirit of three-way merges and is a
777# path towards crazy corner cases that are far more complex than what we're
778# already dealing with.
779#
780# Note that the wording of the rule ("We don't do directory rename
781# detection if the directory still exists on both sides of the merge.")
782# also excludes "renaming" of a directory into a subdirectory of itself
783# (e.g. /some/dir/* -> /some/dir/subdir/*). It may be possible to carve
784# out an exception for "renaming"-beneath-itself cases without opening
785# weird edge/corner cases for other partial directory renames, but for now
786# we are keeping the rule simple.
787#
788# This section contains a test for a partially-renamed-directory case.
789###########################################################################
790
791# Testcase 4a, Directory split, with original directory still present
792# (Related to testcase 1f)
793# Commit O: z/{b,c,d,e}
794# Commit A: y/{b,c,d}, z/e
795# Commit B: z/{b,c,d,e,f}
796# Expected: y/{b,c,d}, z/{e,f}
797# NOTE: Even though most files from z moved to y, we don't want f to follow.
798
da1e295e 799test_setup_4a () {
de632e4e
EN
800 test_create_repo 4a &&
801 (
802 cd 4a &&
803
804 mkdir z &&
805 echo b >z/b &&
806 echo c >z/c &&
807 echo d >z/d &&
808 echo e >z/e &&
809 git add z &&
810 test_tick &&
811 git commit -m "O" &&
812
813 git branch O &&
814 git branch A &&
815 git branch B &&
816
817 git checkout A &&
818 mkdir y &&
819 git mv z/b y/ &&
820 git mv z/c y/ &&
821 git mv z/d y/ &&
822 test_tick &&
823 git commit -m "A" &&
824
825 git checkout B &&
826 echo f >z/f &&
827 git add z/f &&
828 test_tick &&
829 git commit -m "B"
830 )
da1e295e 831}
de632e4e 832
da1e295e
EN
833test_expect_success '4a: Directory split, with original directory still present' '
834 test_setup_4a &&
de632e4e
EN
835 (
836 cd 4a &&
837
838 git checkout A^0 &&
839
8c8e5bd6 840 git -c merge.directoryRenames=true merge -s recursive B^0 &&
de632e4e
EN
841
842 git ls-files -s >out &&
843 test_line_count = 5 out &&
844 git ls-files -u >out &&
845 test_line_count = 0 out &&
846 git ls-files -o >out &&
847 test_line_count = 1 out &&
848
849 git rev-parse >actual \
850 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:z/e HEAD:z/f &&
851 git rev-parse >expect \
852 O:z/b O:z/c O:z/d O:z/e B:z/f &&
853 test_cmp expect actual
854 )
855'
856
857###########################################################################
858# Rules suggested by section 4:
859#
860# Directory-rename-detection should be turned off for any directories (as
861# a source for renames) that exist on both sides of the merge. (The "as
862# a source for renames" clarification is due to cases like 1c where
863# the target directory exists on both sides and we do want the rename
864# detection.) But, sadly, see testcase 8b.
865###########################################################################
866
c449947a
EN
867
868###########################################################################
869# SECTION 5: Files/directories in the way of subset of to-be-renamed paths
870#
871# Implicitly renaming files due to a detected directory rename could run
872# into problems if there are files or directories in the way of the paths
873# we want to rename. Explore such cases in this section.
874###########################################################################
875
876# Testcase 5a, Merge directories, other side adds files to original and target
877# Commit O: z/{b,c}, y/d
878# Commit A: z/{b,c,e_1,f}, y/{d,e_2}
879# Commit B: y/{b,c,d}
880# Expected: z/e_1, y/{b,c,d,e_2,f} + CONFLICT warning
881# NOTE: While directory rename detection is active here causing z/f to
882# become y/f, we did not apply this for z/e_1 because that would
883# give us an add/add conflict for y/e_1 vs y/e_2. This problem with
884# this add/add, is that both versions of y/e are from the same side
885# of history, giving us no way to represent this conflict in the
886# index.
887
da1e295e 888test_setup_5a () {
c449947a
EN
889 test_create_repo 5a &&
890 (
891 cd 5a &&
892
893 mkdir z &&
894 echo b >z/b &&
895 echo c >z/c &&
896 mkdir y &&
897 echo d >y/d &&
898 git add z y &&
899 test_tick &&
900 git commit -m "O" &&
901
902 git branch O &&
903 git branch A &&
904 git branch B &&
905
906 git checkout A &&
907 echo e1 >z/e &&
908 echo f >z/f &&
909 echo e2 >y/e &&
910 git add z/e z/f y/e &&
911 test_tick &&
912 git commit -m "A" &&
913
914 git checkout B &&
915 git mv z/b y/ &&
916 git mv z/c y/ &&
917 rmdir z &&
918 test_tick &&
919 git commit -m "B"
920 )
da1e295e 921}
c449947a 922
da1e295e
EN
923test_expect_success '5a: Merge directories, other side adds files to original and target' '
924 test_setup_5a &&
c449947a
EN
925 (
926 cd 5a &&
927
928 git checkout A^0 &&
929
8c8e5bd6 930 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
c449947a
EN
931 test_i18ngrep "CONFLICT.*implicit dir rename" out &&
932
933 git ls-files -s >out &&
934 test_line_count = 6 out &&
935 git ls-files -u >out &&
936 test_line_count = 0 out &&
937 git ls-files -o >out &&
938 test_line_count = 1 out &&
939
940 git rev-parse >actual \
941 :0:y/b :0:y/c :0:y/d :0:y/e :0:z/e :0:y/f &&
942 git rev-parse >expect \
943 O:z/b O:z/c O:y/d A:y/e A:z/e A:z/f &&
944 test_cmp expect actual
945 )
946'
947
948# Testcase 5b, Rename/delete in order to get add/add/add conflict
949# (Related to testcase 8d; these may appear slightly inconsistent to users;
950# Also related to testcases 7d and 7e)
951# Commit O: z/{b,c,d_1}
952# Commit A: y/{b,c,d_2}
953# Commit B: z/{b,c,d_1,e}, y/d_3
954# Expected: y/{b,c,e}, CONFLICT(add/add: y/d_2 vs. y/d_3)
955# NOTE: If z/d_1 in commit B were to be involved in dir rename detection, as
7a40cf15 956# we normally would since z/ is being renamed to y/, then this would be
c449947a
EN
957# a rename/delete (z/d_1 -> y/d_1 vs. deleted) AND an add/add/add
958# conflict of y/d_1 vs. y/d_2 vs. y/d_3. Add/add/add is not
959# representable in the index, so the existence of y/d_3 needs to
960# cause us to bail on directory rename detection for that path, falling
961# back to git behavior without the directory rename detection.
962
da1e295e 963test_setup_5b () {
c449947a
EN
964 test_create_repo 5b &&
965 (
966 cd 5b &&
967
968 mkdir z &&
969 echo b >z/b &&
970 echo c >z/c &&
971 echo d1 >z/d &&
972 git add z &&
973 test_tick &&
974 git commit -m "O" &&
975
976 git branch O &&
977 git branch A &&
978 git branch B &&
979
980 git checkout A &&
981 git rm z/d &&
982 git mv z y &&
983 echo d2 >y/d &&
984 git add y/d &&
985 test_tick &&
986 git commit -m "A" &&
987
988 git checkout B &&
989 mkdir y &&
990 echo d3 >y/d &&
991 echo e >z/e &&
992 git add y/d z/e &&
993 test_tick &&
994 git commit -m "B"
995 )
da1e295e 996}
c449947a 997
da1e295e
EN
998test_expect_success '5b: Rename/delete in order to get add/add/add conflict' '
999 test_setup_5b &&
c449947a
EN
1000 (
1001 cd 5b &&
1002
1003 git checkout A^0 &&
1004
8c8e5bd6 1005 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
c449947a
EN
1006 test_i18ngrep "CONFLICT (add/add).* y/d" out &&
1007
1008 git ls-files -s >out &&
1009 test_line_count = 5 out &&
1010 git ls-files -u >out &&
1011 test_line_count = 2 out &&
1012 git ls-files -o >out &&
1013 test_line_count = 1 out &&
1014
1015 git rev-parse >actual \
1016 :0:y/b :0:y/c :0:y/e :2:y/d :3:y/d &&
1017 git rev-parse >expect \
1018 O:z/b O:z/c B:z/e A:y/d B:y/d &&
1019 test_cmp expect actual &&
1020
1021 test_must_fail git rev-parse :1:y/d &&
1022 test_path_is_file y/d
1023 )
1024'
1025
1026# Testcase 5c, Transitive rename would cause rename/rename/rename/add/add/add
1027# (Directory rename detection would result in transitive rename vs.
1028# rename/rename(1to2) and turn it into a rename/rename(1to3). Further,
1029# rename paths conflict with separate adds on the other side)
1030# (Related to testcases 3b and 7c)
1031# Commit O: z/{b,c}, x/d_1
1032# Commit A: y/{b,c,d_2}, w/d_1
1033# Commit B: z/{b,c,d_1,e}, w/d_3, y/d_4
1034# Expected: A mess, but only a rename/rename(1to2)/add/add mess. Use the
1035# presence of y/d_4 in B to avoid doing transitive rename of
1036# x/d_1 -> z/d_1 -> y/d_1, so that the only paths we have at
1037# y/d are y/d_2 and y/d_4. We still do the move from z/e to y/e,
1038# though, because it doesn't have anything in the way.
1039
da1e295e 1040test_setup_5c () {
c449947a
EN
1041 test_create_repo 5c &&
1042 (
1043 cd 5c &&
1044
1045 mkdir z &&
1046 echo b >z/b &&
1047 echo c >z/c &&
1048 mkdir x &&
1049 echo d1 >x/d &&
1050 git add z x &&
1051 test_tick &&
1052 git commit -m "O" &&
1053
1054 git branch O &&
1055 git branch A &&
1056 git branch B &&
1057
1058 git checkout A &&
1059 git mv z y &&
1060 echo d2 >y/d &&
1061 git add y/d &&
1062 git mv x w &&
1063 test_tick &&
1064 git commit -m "A" &&
1065
1066 git checkout B &&
1067 git mv x/d z/ &&
1068 mkdir w &&
1069 mkdir y &&
1070 echo d3 >w/d &&
1071 echo d4 >y/d &&
1072 echo e >z/e &&
1073 git add w/ y/ z/e &&
1074 test_tick &&
1075 git commit -m "B"
1076 )
da1e295e 1077}
c449947a 1078
da1e295e
EN
1079test_expect_success '5c: Transitive rename would cause rename/rename/rename/add/add/add' '
1080 test_setup_5c &&
c449947a
EN
1081 (
1082 cd 5c &&
1083
1084 git checkout A^0 &&
1085
8c8e5bd6 1086 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
c449947a
EN
1087 test_i18ngrep "CONFLICT (rename/rename).*x/d.*w/d.*z/d" out &&
1088 test_i18ngrep "CONFLICT (add/add).* y/d" out &&
1089
1090 git ls-files -s >out &&
1091 test_line_count = 9 out &&
1092 git ls-files -u >out &&
1093 test_line_count = 6 out &&
1094 git ls-files -o >out &&
48c9cb9d 1095 test_line_count = 1 out &&
c449947a
EN
1096
1097 git rev-parse >actual \
1098 :0:y/b :0:y/c :0:y/e &&
1099 git rev-parse >expect \
1100 O:z/b O:z/c B:z/e &&
1101 test_cmp expect actual &&
1102
1103 test_must_fail git rev-parse :1:y/d &&
1104 git rev-parse >actual \
1105 :2:w/d :3:w/d :1:x/d :2:y/d :3:y/d :3:z/d &&
1106 git rev-parse >expect \
1107 O:x/d B:w/d O:x/d A:y/d B:y/d O:x/d &&
1108 test_cmp expect actual &&
1109
1110 git hash-object >actual \
48c9cb9d 1111 z/d &&
c449947a 1112 git rev-parse >expect \
48c9cb9d 1113 O:x/d &&
c449947a
EN
1114 test_cmp expect actual &&
1115 test_path_is_missing x/d &&
1116 test_path_is_file y/d &&
1117 grep -q "<<<<" y/d # conflict markers should be present
1118 )
1119'
1120
1121# Testcase 5d, Directory/file/file conflict due to directory rename
1122# Commit O: z/{b,c}
1123# Commit A: y/{b,c,d_1}
1124# Commit B: z/{b,c,d_2,f}, y/d/e
1125# Expected: y/{b,c,d/e,f}, z/d_2, CONFLICT(file/directory), y/d_1~HEAD
1126# Note: The fact that y/d/ exists in B makes us bail on directory rename
1127# detection for z/d_2, but that doesn't prevent us from applying the
1128# directory rename detection for z/f -> y/f.
1129
da1e295e 1130test_setup_5d () {
c449947a
EN
1131 test_create_repo 5d &&
1132 (
1133 cd 5d &&
1134
1135 mkdir z &&
1136 echo b >z/b &&
1137 echo c >z/c &&
1138 git add z &&
1139 test_tick &&
1140 git commit -m "O" &&
1141
1142 git branch O &&
1143 git branch A &&
1144 git branch B &&
1145
1146 git checkout A &&
1147 git mv z y &&
1148 echo d1 >y/d &&
1149 git add y/d &&
1150 test_tick &&
1151 git commit -m "A" &&
1152
1153 git checkout B &&
1154 mkdir -p y/d &&
1155 echo e >y/d/e &&
1156 echo d2 >z/d &&
1157 echo f >z/f &&
1158 git add y/d/e z/d z/f &&
1159 test_tick &&
1160 git commit -m "B"
1161 )
da1e295e 1162}
c449947a 1163
da1e295e
EN
1164test_expect_success '5d: Directory/file/file conflict due to directory rename' '
1165 test_setup_5d &&
c449947a
EN
1166 (
1167 cd 5d &&
1168
1169 git checkout A^0 &&
1170
8c8e5bd6 1171 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
c449947a
EN
1172 test_i18ngrep "CONFLICT (file/directory).*y/d" out &&
1173
1174 git ls-files -s >out &&
1175 test_line_count = 6 out &&
1176 git ls-files -u >out &&
1177 test_line_count = 1 out &&
1178 git ls-files -o >out &&
1179 test_line_count = 2 out &&
1180
1181 git rev-parse >actual \
1182 :0:y/b :0:y/c :0:z/d :0:y/f :2:y/d :0:y/d/e &&
1183 git rev-parse >expect \
1184 O:z/b O:z/c B:z/d B:z/f A:y/d B:y/d/e &&
1185 test_cmp expect actual &&
1186
1187 git hash-object y/d~HEAD >actual &&
1188 git rev-parse A:y/d >expect &&
1189 test_cmp expect actual
1190 )
1191'
1192
1193###########################################################################
1194# Rules suggested by section 5:
1195#
1196# If a subset of to-be-renamed files have a file or directory in the way,
1197# "turn off" the directory rename for those specific sub-paths, falling
1198# back to old handling. But, sadly, see testcases 8a and 8b.
1199###########################################################################
1200
f3499876
EN
1201
1202###########################################################################
1203# SECTION 6: Same side of the merge was the one that did the rename
1204#
1205# It may sound obvious that you only want to apply implicit directory
1206# renames to directories if the _other_ side of history did the renaming.
1207# If you did make an implementation that didn't explicitly enforce this
1208# rule, the majority of cases that would fall under this section would
1209# also be solved by following the rules from the above sections. But
1210# there are still a few that stick out, so this section covers them just
1211# to make sure we also get them right.
1212###########################################################################
1213
1214# Testcase 6a, Tricky rename/delete
1215# Commit O: z/{b,c,d}
1216# Commit A: z/b
1217# Commit B: y/{b,c}, z/d
1218# Expected: y/b, CONFLICT(rename/delete, z/c -> y/c vs. NULL)
1219# Note: We're just checking here that the rename of z/b and z/c to put
1220# them under y/ doesn't accidentally catch z/d and make it look like
1221# it is also involved in a rename/delete conflict.
1222
da1e295e 1223test_setup_6a () {
f3499876
EN
1224 test_create_repo 6a &&
1225 (
1226 cd 6a &&
1227
1228 mkdir z &&
1229 echo b >z/b &&
1230 echo c >z/c &&
1231 echo d >z/d &&
1232 git add z &&
1233 test_tick &&
1234 git commit -m "O" &&
1235
1236 git branch O &&
1237 git branch A &&
1238 git branch B &&
1239
1240 git checkout A &&
1241 git rm z/c &&
1242 git rm z/d &&
1243 test_tick &&
1244 git commit -m "A" &&
1245
1246 git checkout B &&
1247 mkdir y &&
1248 git mv z/b y/ &&
1249 git mv z/c y/ &&
1250 test_tick &&
1251 git commit -m "B"
1252 )
da1e295e 1253}
f3499876 1254
da1e295e
EN
1255test_expect_success '6a: Tricky rename/delete' '
1256 test_setup_6a &&
f3499876
EN
1257 (
1258 cd 6a &&
1259
1260 git checkout A^0 &&
1261
8c8e5bd6 1262 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
f3499876
EN
1263 test_i18ngrep "CONFLICT (rename/delete).*z/c.*y/c" out &&
1264
1265 git ls-files -s >out &&
1266 test_line_count = 2 out &&
1267 git ls-files -u >out &&
1268 test_line_count = 1 out &&
1269 git ls-files -o >out &&
1270 test_line_count = 1 out &&
1271
1272 git rev-parse >actual \
1273 :0:y/b :3:y/c &&
1274 git rev-parse >expect \
1275 O:z/b O:z/c &&
1276 test_cmp expect actual
1277 )
1278'
1279
1280# Testcase 6b, Same rename done on both sides
1281# (Related to testcases 6c and 8e)
1282# Commit O: z/{b,c}
1283# Commit A: y/{b,c}
1284# Commit B: y/{b,c}, z/d
1285# Expected: y/{b,c}, z/d
1286# Note: If we did directory rename detection here, we'd move z/d into y/,
1287# but B did that rename and still decided to put the file into z/,
1288# so we probably shouldn't apply directory rename detection for it.
1289
da1e295e 1290test_setup_6b () {
f3499876
EN
1291 test_create_repo 6b &&
1292 (
1293 cd 6b &&
1294
1295 mkdir z &&
1296 echo b >z/b &&
1297 echo c >z/c &&
1298 git add z &&
1299 test_tick &&
1300 git commit -m "O" &&
1301
1302 git branch O &&
1303 git branch A &&
1304 git branch B &&
1305
1306 git checkout A &&
1307 git mv z y &&
1308 test_tick &&
1309 git commit -m "A" &&
1310
1311 git checkout B &&
1312 git mv z y &&
1313 mkdir z &&
1314 echo d >z/d &&
1315 git add z/d &&
1316 test_tick &&
1317 git commit -m "B"
1318 )
da1e295e 1319}
f3499876 1320
da1e295e
EN
1321test_expect_success '6b: Same rename done on both sides' '
1322 test_setup_6b &&
f3499876
EN
1323 (
1324 cd 6b &&
1325
1326 git checkout A^0 &&
1327
8c8e5bd6 1328 git -c merge.directoryRenames=true merge -s recursive B^0 &&
f3499876
EN
1329
1330 git ls-files -s >out &&
1331 test_line_count = 3 out &&
1332 git ls-files -u >out &&
1333 test_line_count = 0 out &&
1334 git ls-files -o >out &&
1335 test_line_count = 1 out &&
1336
1337 git rev-parse >actual \
1338 HEAD:y/b HEAD:y/c HEAD:z/d &&
1339 git rev-parse >expect \
1340 O:z/b O:z/c B:z/d &&
1341 test_cmp expect actual
1342 )
1343'
1344
1345# Testcase 6c, Rename only done on same side
1346# (Related to testcases 6b and 8e)
1347# Commit O: z/{b,c}
1348# Commit A: z/{b,c} (no change)
1349# Commit B: y/{b,c}, z/d
1350# Expected: y/{b,c}, z/d
1351# NOTE: Seems obvious, but just checking that the implementation doesn't
1352# "accidentally detect a rename" and give us y/{b,c,d}.
1353
da1e295e 1354test_setup_6c () {
f3499876
EN
1355 test_create_repo 6c &&
1356 (
1357 cd 6c &&
1358
1359 mkdir z &&
1360 echo b >z/b &&
1361 echo c >z/c &&
1362 git add z &&
1363 test_tick &&
1364 git commit -m "O" &&
1365
1366 git branch O &&
1367 git branch A &&
1368 git branch B &&
1369
1370 git checkout A &&
1371 test_tick &&
1372 git commit --allow-empty -m "A" &&
1373
1374 git checkout B &&
1375 git mv z y &&
1376 mkdir z &&
1377 echo d >z/d &&
1378 git add z/d &&
1379 test_tick &&
1380 git commit -m "B"
1381 )
da1e295e 1382}
f3499876 1383
da1e295e
EN
1384test_expect_success '6c: Rename only done on same side' '
1385 test_setup_6c &&
f3499876
EN
1386 (
1387 cd 6c &&
1388
1389 git checkout A^0 &&
1390
8c8e5bd6 1391 git -c merge.directoryRenames=true merge -s recursive B^0 &&
f3499876
EN
1392
1393 git ls-files -s >out &&
1394 test_line_count = 3 out &&
1395 git ls-files -u >out &&
1396 test_line_count = 0 out &&
1397 git ls-files -o >out &&
1398 test_line_count = 1 out &&
1399
1400 git rev-parse >actual \
1401 HEAD:y/b HEAD:y/c HEAD:z/d &&
1402 git rev-parse >expect \
1403 O:z/b O:z/c B:z/d &&
1404 test_cmp expect actual
1405 )
1406'
1407
1408# Testcase 6d, We don't always want transitive renaming
1409# (Related to testcase 1c)
1410# Commit O: z/{b,c}, x/d
1411# Commit A: z/{b,c}, x/d (no change)
1412# Commit B: y/{b,c}, z/d
1413# Expected: y/{b,c}, z/d
1414# NOTE: Again, this seems obvious but just checking that the implementation
1415# doesn't "accidentally detect a rename" and give us y/{b,c,d}.
1416
da1e295e 1417test_setup_6d () {
f3499876
EN
1418 test_create_repo 6d &&
1419 (
1420 cd 6d &&
1421
1422 mkdir z &&
1423 echo b >z/b &&
1424 echo c >z/c &&
1425 mkdir x &&
1426 echo d >x/d &&
1427 git add z x &&
1428 test_tick &&
1429 git commit -m "O" &&
1430
1431 git branch O &&
1432 git branch A &&
1433 git branch B &&
1434
1435 git checkout A &&
1436 test_tick &&
1437 git commit --allow-empty -m "A" &&
1438
1439 git checkout B &&
1440 git mv z y &&
1441 git mv x z &&
1442 test_tick &&
1443 git commit -m "B"
1444 )
da1e295e 1445}
f3499876 1446
da1e295e
EN
1447test_expect_success '6d: We do not always want transitive renaming' '
1448 test_setup_6d &&
f3499876
EN
1449 (
1450 cd 6d &&
1451
1452 git checkout A^0 &&
1453
8c8e5bd6 1454 git -c merge.directoryRenames=true merge -s recursive B^0 &&
f3499876
EN
1455
1456 git ls-files -s >out &&
1457 test_line_count = 3 out &&
1458 git ls-files -u >out &&
1459 test_line_count = 0 out &&
1460 git ls-files -o >out &&
1461 test_line_count = 1 out &&
1462
1463 git rev-parse >actual \
1464 HEAD:y/b HEAD:y/c HEAD:z/d &&
1465 git rev-parse >expect \
1466 O:z/b O:z/c O:x/d &&
1467 test_cmp expect actual
1468 )
1469'
1470
1471# Testcase 6e, Add/add from one-side
1472# Commit O: z/{b,c}
1473# Commit A: z/{b,c} (no change)
1474# Commit B: y/{b,c,d_1}, z/d_2
1475# Expected: y/{b,c,d_1}, z/d_2
1476# NOTE: Again, this seems obvious but just checking that the implementation
1477# doesn't "accidentally detect a rename" and give us y/{b,c} +
1478# add/add conflict on y/d_1 vs y/d_2.
1479
da1e295e 1480test_setup_6e () {
f3499876
EN
1481 test_create_repo 6e &&
1482 (
1483 cd 6e &&
1484
1485 mkdir z &&
1486 echo b >z/b &&
1487 echo c >z/c &&
1488 git add z &&
1489 test_tick &&
1490 git commit -m "O" &&
1491
1492 git branch O &&
1493 git branch A &&
1494 git branch B &&
1495
1496 git checkout A &&
1497 test_tick &&
1498 git commit --allow-empty -m "A" &&
1499
1500 git checkout B &&
1501 git mv z y &&
1502 echo d1 > y/d &&
1503 mkdir z &&
1504 echo d2 > z/d &&
1505 git add y/d z/d &&
1506 test_tick &&
1507 git commit -m "B"
1508 )
da1e295e 1509}
f3499876 1510
da1e295e
EN
1511test_expect_success '6e: Add/add from one side' '
1512 test_setup_6e &&
f3499876
EN
1513 (
1514 cd 6e &&
1515
1516 git checkout A^0 &&
1517
8c8e5bd6 1518 git -c merge.directoryRenames=true merge -s recursive B^0 &&
f3499876
EN
1519
1520 git ls-files -s >out &&
1521 test_line_count = 4 out &&
1522 git ls-files -u >out &&
1523 test_line_count = 0 out &&
1524 git ls-files -o >out &&
1525 test_line_count = 1 out &&
1526
1527 git rev-parse >actual \
1528 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:z/d &&
1529 git rev-parse >expect \
1530 O:z/b O:z/c B:y/d B:z/d &&
1531 test_cmp expect actual
1532 )
1533'
1534
1535###########################################################################
1536# Rules suggested by section 6:
1537#
1538# Only apply implicit directory renames to directories if the other
1539# side of history is the one doing the renaming.
1540###########################################################################
1541
f95de960
EN
1542
1543###########################################################################
1544# SECTION 7: More involved Edge/Corner cases
1545#
1546# The ruleset we have generated in the above sections seems to provide
1547# well-defined merges. But can we find edge/corner cases that either (a)
1548# are harder for users to understand, or (b) have a resolution that is
1549# non-intuitive or suboptimal?
1550#
1551# The testcases in this section dive into cases that I've tried to craft in
1552# a way to find some that might be surprising to users or difficult for
1553# them to understand (the next section will look at non-intuitive or
1554# suboptimal merge results). Some of the testcases are similar to ones
1555# from past sections, but have been simplified to try to highlight error
1556# messages using a "modified" path (due to the directory rename). Are
1557# users okay with these?
1558#
1559# In my opinion, testcases that are difficult to understand from this
1560# section is due to difficulty in the testcase rather than the directory
1561# renaming (similar to how t6042 and t6036 have difficult resolutions due
1562# to the problem setup itself being complex). And I don't think the
1563# error messages are a problem.
1564#
1565# On the other hand, the testcases in section 8 worry me slightly more...
1566###########################################################################
1567
1568# Testcase 7a, rename-dir vs. rename-dir (NOT split evenly) PLUS add-other-file
1569# Commit O: z/{b,c}
1570# Commit A: y/{b,c}
1571# Commit B: w/b, x/c, z/d
1572# Expected: y/d, CONFLICT(rename/rename for both z/b and z/c)
1573# NOTE: There's a rename of z/ here, y/ has more renames, so z/d -> y/d.
1574
da1e295e 1575test_setup_7a () {
f95de960
EN
1576 test_create_repo 7a &&
1577 (
1578 cd 7a &&
1579
1580 mkdir z &&
1581 echo b >z/b &&
1582 echo c >z/c &&
1583 git add z &&
1584 test_tick &&
1585 git commit -m "O" &&
1586
1587 git branch O &&
1588 git branch A &&
1589 git branch B &&
1590
1591 git checkout A &&
1592 git mv z y &&
1593 test_tick &&
1594 git commit -m "A" &&
1595
1596 git checkout B &&
1597 mkdir w &&
1598 mkdir x &&
1599 git mv z/b w/ &&
1600 git mv z/c x/ &&
1601 echo d > z/d &&
1602 git add z/d &&
1603 test_tick &&
1604 git commit -m "B"
1605 )
da1e295e 1606}
f95de960 1607
da1e295e
EN
1608test_expect_success '7a: rename-dir vs. rename-dir (NOT split evenly) PLUS add-other-file' '
1609 test_setup_7a &&
f95de960
EN
1610 (
1611 cd 7a &&
1612
1613 git checkout A^0 &&
1614
8c8e5bd6 1615 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
f95de960
EN
1616 test_i18ngrep "CONFLICT (rename/rename).*z/b.*y/b.*w/b" out &&
1617 test_i18ngrep "CONFLICT (rename/rename).*z/c.*y/c.*x/c" out &&
1618
1619 git ls-files -s >out &&
1620 test_line_count = 7 out &&
1621 git ls-files -u >out &&
1622 test_line_count = 6 out &&
1623 git ls-files -o >out &&
1624 test_line_count = 1 out &&
1625
1626 git rev-parse >actual \
1627 :1:z/b :2:y/b :3:w/b :1:z/c :2:y/c :3:x/c :0:y/d &&
1628 git rev-parse >expect \
1629 O:z/b O:z/b O:z/b O:z/c O:z/c O:z/c B:z/d &&
1630 test_cmp expect actual &&
1631
1632 git hash-object >actual \
1633 y/b w/b y/c x/c &&
1634 git rev-parse >expect \
1635 O:z/b O:z/b O:z/c O:z/c &&
1636 test_cmp expect actual
1637 )
1638'
1639
1640# Testcase 7b, rename/rename(2to1), but only due to transitive rename
1641# (Related to testcase 1d)
1642# Commit O: z/{b,c}, x/d_1, w/d_2
1643# Commit A: y/{b,c,d_2}, x/d_1
1644# Commit B: z/{b,c,d_1}, w/d_2
1645# Expected: y/{b,c}, CONFLICT(rename/rename(2to1): x/d_1, w/d_2 -> y_d)
1646
da1e295e 1647test_setup_7b () {
f95de960
EN
1648 test_create_repo 7b &&
1649 (
1650 cd 7b &&
1651
1652 mkdir z &&
1653 mkdir x &&
1654 mkdir w &&
1655 echo b >z/b &&
1656 echo c >z/c &&
1657 echo d1 > x/d &&
1658 echo d2 > w/d &&
1659 git add z x w &&
1660 test_tick &&
1661 git commit -m "O" &&
1662
1663 git branch O &&
1664 git branch A &&
1665 git branch B &&
1666
1667 git checkout A &&
1668 git mv z y &&
1669 git mv w/d y/ &&
1670 test_tick &&
1671 git commit -m "A" &&
1672
1673 git checkout B &&
1674 git mv x/d z/ &&
1675 rmdir x &&
1676 test_tick &&
1677 git commit -m "B"
1678 )
da1e295e 1679}
f95de960 1680
da1e295e
EN
1681test_expect_success '7b: rename/rename(2to1), but only due to transitive rename' '
1682 test_setup_7b &&
f95de960
EN
1683 (
1684 cd 7b &&
1685
1686 git checkout A^0 &&
1687
8c8e5bd6 1688 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
f95de960
EN
1689 test_i18ngrep "CONFLICT (rename/rename)" out &&
1690
1691 git ls-files -s >out &&
1692 test_line_count = 4 out &&
1693 git ls-files -u >out &&
1694 test_line_count = 2 out &&
1695 git ls-files -o >out &&
bbafc9c4 1696 test_line_count = 1 out &&
f95de960
EN
1697
1698 git rev-parse >actual \
1699 :0:y/b :0:y/c :2:y/d :3:y/d &&
1700 git rev-parse >expect \
1701 O:z/b O:z/c O:w/d O:x/d &&
1702 test_cmp expect actual &&
1703
bbafc9c4
EN
1704 # Test that the two-way merge in y/d is as expected
1705 git cat-file -p :2:y/d >expect &&
1706 git cat-file -p :3:y/d >other &&
1707 >empty &&
1708 test_must_fail git merge-file \
1709 -L "HEAD" \
1710 -L "" \
1711 -L "B^0" \
1712 expect empty other &&
1713 test_cmp expect y/d
f95de960
EN
1714 )
1715'
1716
1717# Testcase 7c, rename/rename(1to...2or3); transitive rename may add complexity
1718# (Related to testcases 3b and 5c)
1719# Commit O: z/{b,c}, x/d
1720# Commit A: y/{b,c}, w/d
1721# Commit B: z/{b,c,d}
1722# Expected: y/{b,c}, CONFLICT(x/d -> w/d vs. y/d)
1723# NOTE: z/ was renamed to y/ so we do want to report
1724# neither CONFLICT(x/d -> w/d vs. z/d)
1725# nor CONFLiCT x/d -> w/d vs. y/d vs. z/d)
1726
da1e295e 1727test_setup_7c () {
f95de960
EN
1728 test_create_repo 7c &&
1729 (
1730 cd 7c &&
1731
1732 mkdir z &&
1733 echo b >z/b &&
1734 echo c >z/c &&
1735 mkdir x &&
1736 echo d >x/d &&
1737 git add z x &&
1738 test_tick &&
1739 git commit -m "O" &&
1740
1741 git branch O &&
1742 git branch A &&
1743 git branch B &&
1744
1745 git checkout A &&
1746 git mv z y &&
1747 git mv x w &&
1748 test_tick &&
1749 git commit -m "A" &&
1750
1751 git checkout B &&
1752 git mv x/d z/ &&
1753 rmdir x &&
1754 test_tick &&
1755 git commit -m "B"
1756 )
da1e295e 1757}
f95de960 1758
da1e295e
EN
1759test_expect_success '7c: rename/rename(1to...2or3); transitive rename may add complexity' '
1760 test_setup_7c &&
f95de960
EN
1761 (
1762 cd 7c &&
1763
1764 git checkout A^0 &&
1765
8c8e5bd6 1766 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
f95de960
EN
1767 test_i18ngrep "CONFLICT (rename/rename).*x/d.*w/d.*y/d" out &&
1768
1769 git ls-files -s >out &&
1770 test_line_count = 5 out &&
1771 git ls-files -u >out &&
1772 test_line_count = 3 out &&
1773 git ls-files -o >out &&
1774 test_line_count = 1 out &&
1775
1776 git rev-parse >actual \
1777 :0:y/b :0:y/c :1:x/d :2:w/d :3:y/d &&
1778 git rev-parse >expect \
1779 O:z/b O:z/c O:x/d O:x/d O:x/d &&
1780 test_cmp expect actual
1781 )
1782'
1783
1784# Testcase 7d, transitive rename involved in rename/delete; how is it reported?
1785# (Related somewhat to testcases 5b and 8d)
1786# Commit O: z/{b,c}, x/d
1787# Commit A: y/{b,c}
1788# Commit B: z/{b,c,d}
1789# Expected: y/{b,c}, CONFLICT(delete x/d vs rename to y/d)
1790# NOTE: z->y so NOT CONFLICT(delete x/d vs rename to z/d)
1791
da1e295e 1792test_setup_7d () {
f95de960
EN
1793 test_create_repo 7d &&
1794 (
1795 cd 7d &&
1796
1797 mkdir z &&
1798 echo b >z/b &&
1799 echo c >z/c &&
1800 mkdir x &&
1801 echo d >x/d &&
1802 git add z x &&
1803 test_tick &&
1804 git commit -m "O" &&
1805
1806 git branch O &&
1807 git branch A &&
1808 git branch B &&
1809
1810 git checkout A &&
1811 git mv z y &&
1812 git rm -rf x &&
1813 test_tick &&
1814 git commit -m "A" &&
1815
1816 git checkout B &&
1817 git mv x/d z/ &&
1818 rmdir x &&
1819 test_tick &&
1820 git commit -m "B"
1821 )
da1e295e 1822}
f95de960 1823
da1e295e
EN
1824test_expect_success '7d: transitive rename involved in rename/delete; how is it reported?' '
1825 test_setup_7d &&
f95de960
EN
1826 (
1827 cd 7d &&
1828
1829 git checkout A^0 &&
1830
8c8e5bd6 1831 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
f95de960
EN
1832 test_i18ngrep "CONFLICT (rename/delete).*x/d.*y/d" out &&
1833
1834 git ls-files -s >out &&
1835 test_line_count = 3 out &&
1836 git ls-files -u >out &&
1837 test_line_count = 1 out &&
1838 git ls-files -o >out &&
1839 test_line_count = 1 out &&
1840
1841 git rev-parse >actual \
1842 :0:y/b :0:y/c :3:y/d &&
1843 git rev-parse >expect \
1844 O:z/b O:z/c O:x/d &&
1845 test_cmp expect actual
1846 )
1847'
1848
1849# Testcase 7e, transitive rename in rename/delete AND dirs in the way
1850# (Very similar to 'both rename source and destination involved in D/F conflict' from t6022-merge-rename.sh)
1851# (Also related to testcases 9c and 9d)
1852# Commit O: z/{b,c}, x/d_1
1853# Commit A: y/{b,c,d/g}, x/d/f
1854# Commit B: z/{b,c,d_1}
1855# Expected: rename/delete(x/d_1->y/d_1 vs. None) + D/F conflict on y/d
1856# y/{b,c,d/g}, y/d_1~B^0, x/d/f
1857
1858# NOTE: The main path of interest here is d_1 and where it ends up, but
1859# this is actually a case that has two potential directory renames
1860# involved and D/F conflict(s), so it makes sense to walk through
1861# each step.
1862#
1863# Commit A renames z/ -> y/. Thus everything that B adds to z/
1864# should be instead moved to y/. This gives us the D/F conflict on
1865# y/d because x/d_1 -> z/d_1 -> y/d_1 conflicts with y/d/g.
1866#
1867# Further, commit B renames x/ -> z/, thus everything A adds to x/
1868# should instead be moved to z/...BUT we removed z/ and renamed it
1869# to y/, so maybe everything should move not from x/ to z/, but
1870# from x/ to z/ to y/. Doing so might make sense from the logic so
1871# far, but note that commit A had both an x/ and a y/; it did the
1872# renaming of z/ to y/ and created x/d/f and it clearly made these
1873# things separate, so it doesn't make much sense to push these
1874# together. Doing so is what I'd call a doubly transitive rename;
1875# see testcases 9c and 9d for further discussion of this issue and
1876# how it's resolved.
1877
da1e295e 1878test_setup_7e () {
f95de960
EN
1879 test_create_repo 7e &&
1880 (
1881 cd 7e &&
1882
1883 mkdir z &&
1884 echo b >z/b &&
1885 echo c >z/c &&
1886 mkdir x &&
1887 echo d1 >x/d &&
1888 git add z x &&
1889 test_tick &&
1890 git commit -m "O" &&
1891
1892 git branch O &&
1893 git branch A &&
1894 git branch B &&
1895
1896 git checkout A &&
1897 git mv z y &&
1898 git rm x/d &&
1899 mkdir -p x/d &&
1900 mkdir -p y/d &&
1901 echo f >x/d/f &&
1902 echo g >y/d/g &&
1903 git add x/d/f y/d/g &&
1904 test_tick &&
1905 git commit -m "A" &&
1906
1907 git checkout B &&
1908 git mv x/d z/ &&
1909 rmdir x &&
1910 test_tick &&
1911 git commit -m "B"
1912 )
da1e295e 1913}
f95de960 1914
da1e295e
EN
1915test_expect_success '7e: transitive rename in rename/delete AND dirs in the way' '
1916 test_setup_7e &&
f95de960
EN
1917 (
1918 cd 7e &&
1919
1920 git checkout A^0 &&
1921
8c8e5bd6 1922 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
f95de960
EN
1923 test_i18ngrep "CONFLICT (rename/delete).*x/d.*y/d" out &&
1924
1925 git ls-files -s >out &&
1926 test_line_count = 5 out &&
1927 git ls-files -u >out &&
1928 test_line_count = 1 out &&
1929 git ls-files -o >out &&
1930 test_line_count = 2 out &&
1931
1932 git rev-parse >actual \
1933 :0:x/d/f :0:y/d/g :0:y/b :0:y/c :3:y/d &&
1934 git rev-parse >expect \
1935 A:x/d/f A:y/d/g O:z/b O:z/c O:x/d &&
1936 test_cmp expect actual &&
1937
1938 git hash-object y/d~B^0 >actual &&
1939 git rev-parse O:x/d >expect &&
1940 test_cmp expect actual
1941 )
1942'
1943
362ab315
EN
1944###########################################################################
1945# SECTION 8: Suboptimal merges
1946#
1947# As alluded to in the last section, the ruleset we have built up for
1948# detecting directory renames unfortunately has some special cases where it
1949# results in slightly suboptimal or non-intuitive behavior. This section
1950# explores these cases.
1951#
1952# To be fair, we already had non-intuitive or suboptimal behavior for most
1953# of these cases in git before introducing implicit directory rename
1954# detection, but it'd be nice if there was a modified ruleset out there
1955# that handled these cases a bit better.
1956###########################################################################
1957
1958# Testcase 8a, Dual-directory rename, one into the others' way
1959# Commit O. x/{a,b}, y/{c,d}
1960# Commit A. x/{a,b,e}, y/{c,d,f}
1961# Commit B. y/{a,b}, z/{c,d}
1962#
1963# Possible Resolutions:
1964# w/o dir-rename detection: y/{a,b,f}, z/{c,d}, x/e
1965# Currently expected: y/{a,b,e,f}, z/{c,d}
1966# Optimal: y/{a,b,e}, z/{c,d,f}
1967#
1968# Note: Both x and y got renamed and it'd be nice to detect both, and we do
1969# better with directory rename detection than git did without, but the
1970# simple rule from section 5 prevents me from handling this as optimally as
1971# we potentially could.
1972
da1e295e 1973test_setup_8a () {
362ab315
EN
1974 test_create_repo 8a &&
1975 (
1976 cd 8a &&
1977
1978 mkdir x &&
1979 mkdir y &&
1980 echo a >x/a &&
1981 echo b >x/b &&
1982 echo c >y/c &&
1983 echo d >y/d &&
1984 git add x y &&
1985 test_tick &&
1986 git commit -m "O" &&
1987
1988 git branch O &&
1989 git branch A &&
1990 git branch B &&
1991
1992 git checkout A &&
1993 echo e >x/e &&
1994 echo f >y/f &&
1995 git add x/e y/f &&
1996 test_tick &&
1997 git commit -m "A" &&
1998
1999 git checkout B &&
2000 git mv y z &&
2001 git mv x y &&
2002 test_tick &&
2003 git commit -m "B"
2004 )
da1e295e 2005}
362ab315 2006
da1e295e
EN
2007test_expect_success '8a: Dual-directory rename, one into the others way' '
2008 test_setup_8a &&
362ab315
EN
2009 (
2010 cd 8a &&
2011
2012 git checkout A^0 &&
2013
8c8e5bd6 2014 git -c merge.directoryRenames=true merge -s recursive B^0 &&
362ab315
EN
2015
2016 git ls-files -s >out &&
2017 test_line_count = 6 out &&
2018 git ls-files -u >out &&
2019 test_line_count = 0 out &&
2020 git ls-files -o >out &&
2021 test_line_count = 1 out &&
2022
2023 git rev-parse >actual \
2024 HEAD:y/a HEAD:y/b HEAD:y/e HEAD:y/f HEAD:z/c HEAD:z/d &&
2025 git rev-parse >expect \
2026 O:x/a O:x/b A:x/e A:y/f O:y/c O:y/d &&
2027 test_cmp expect actual
2028 )
2029'
2030
2031# Testcase 8b, Dual-directory rename, one into the others' way, with conflicting filenames
2032# Commit O. x/{a_1,b_1}, y/{a_2,b_2}
2033# Commit A. x/{a_1,b_1,e_1}, y/{a_2,b_2,e_2}
2034# Commit B. y/{a_1,b_1}, z/{a_2,b_2}
2035#
2036# w/o dir-rename detection: y/{a_1,b_1,e_2}, z/{a_2,b_2}, x/e_1
2037# Currently expected: <same>
2038# Scary: y/{a_1,b_1}, z/{a_2,b_2}, CONFLICT(add/add, e_1 vs. e_2)
2039# Optimal: y/{a_1,b_1,e_1}, z/{a_2,b_2,e_2}
2040#
2041# Note: Very similar to 8a, except instead of 'e' and 'f' in directories x and
2042# y, both are named 'e'. Without directory rename detection, neither file
2043# moves directories. Implement directory rename detection suboptimally, and
2044# you get an add/add conflict, but both files were added in commit A, so this
2045# is an add/add conflict where one side of history added both files --
2046# something we can't represent in the index. Obviously, we'd prefer the last
2047# resolution, but our previous rules are too coarse to allow it. Using both
2048# the rules from section 4 and section 5 save us from the Scary resolution,
2049# making us fall back to pre-directory-rename-detection behavior for both
2050# e_1 and e_2.
2051
da1e295e 2052test_setup_8b () {
362ab315
EN
2053 test_create_repo 8b &&
2054 (
2055 cd 8b &&
2056
2057 mkdir x &&
2058 mkdir y &&
2059 echo a1 >x/a &&
2060 echo b1 >x/b &&
2061 echo a2 >y/a &&
2062 echo b2 >y/b &&
2063 git add x y &&
2064 test_tick &&
2065 git commit -m "O" &&
2066
2067 git branch O &&
2068 git branch A &&
2069 git branch B &&
2070
2071 git checkout A &&
2072 echo e1 >x/e &&
2073 echo e2 >y/e &&
2074 git add x/e y/e &&
2075 test_tick &&
2076 git commit -m "A" &&
2077
2078 git checkout B &&
2079 git mv y z &&
2080 git mv x y &&
2081 test_tick &&
2082 git commit -m "B"
2083 )
da1e295e 2084}
362ab315 2085
da1e295e
EN
2086test_expect_success '8b: Dual-directory rename, one into the others way, with conflicting filenames' '
2087 test_setup_8b &&
362ab315
EN
2088 (
2089 cd 8b &&
2090
2091 git checkout A^0 &&
2092
8c8e5bd6 2093 git -c merge.directoryRenames=true merge -s recursive B^0 &&
362ab315
EN
2094
2095 git ls-files -s >out &&
2096 test_line_count = 6 out &&
2097 git ls-files -u >out &&
2098 test_line_count = 0 out &&
2099 git ls-files -o >out &&
2100 test_line_count = 1 out &&
2101
2102 git rev-parse >actual \
2103 HEAD:y/a HEAD:y/b HEAD:z/a HEAD:z/b HEAD:x/e HEAD:y/e &&
2104 git rev-parse >expect \
2105 O:x/a O:x/b O:y/a O:y/b A:x/e A:y/e &&
2106 test_cmp expect actual
2107 )
2108'
2109
6e7e027f
EN
2110# Testcase 8c, modify/delete or rename+modify/delete?
2111# (Related to testcases 5b, 8d, and 9h)
362ab315
EN
2112# Commit O: z/{b,c,d}
2113# Commit A: y/{b,c}
2114# Commit B: z/{b,c,d_modified,e}
6e7e027f 2115# Expected: y/{b,c,e}, CONFLICT(modify/delete: on z/d)
362ab315 2116#
6e7e027f
EN
2117# Note: It could easily be argued that the correct resolution here is
2118# y/{b,c,e}, CONFLICT(rename/delete: z/d -> y/d vs deleted)
7a40cf15 2119# and that the modified version of d should be present in y/ after
6e7e027f
EN
2120# the merge, just marked as conflicted. Indeed, I previously did
2121# argue that. But applying directory renames to the side of
2122# history where a file is merely modified results in spurious
2123# rename/rename(1to2) conflicts -- see testcase 9h. See also
2124# notes in 8d.
2125
da1e295e 2126test_setup_8c () {
362ab315
EN
2127 test_create_repo 8c &&
2128 (
2129 cd 8c &&
2130
2131 mkdir z &&
2132 echo b >z/b &&
2133 echo c >z/c &&
2134 test_seq 1 10 >z/d &&
2135 git add z &&
2136 test_tick &&
2137 git commit -m "O" &&
2138
2139 git branch O &&
2140 git branch A &&
2141 git branch B &&
2142
2143 git checkout A &&
2144 git rm z/d &&
2145 git mv z y &&
2146 test_tick &&
2147 git commit -m "A" &&
2148
2149 git checkout B &&
2150 echo 11 >z/d &&
2151 test_chmod +x z/d &&
2152 echo e >z/e &&
2153 git add z/d z/e &&
2154 test_tick &&
2155 git commit -m "B"
2156 )
da1e295e 2157}
362ab315 2158
da1e295e
EN
2159test_expect_success '8c: modify/delete or rename+modify/delete' '
2160 test_setup_8c &&
362ab315
EN
2161 (
2162 cd 8c &&
2163
2164 git checkout A^0 &&
2165
8c8e5bd6 2166 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
6e7e027f 2167 test_i18ngrep "CONFLICT (modify/delete).* z/d" out &&
362ab315
EN
2168
2169 git ls-files -s >out &&
6e7e027f 2170 test_line_count = 5 out &&
362ab315 2171 git ls-files -u >out &&
6e7e027f 2172 test_line_count = 2 out &&
362ab315
EN
2173 git ls-files -o >out &&
2174 test_line_count = 1 out &&
2175
2176 git rev-parse >actual \
6e7e027f 2177 :0:y/b :0:y/c :0:y/e :1:z/d :3:z/d &&
362ab315 2178 git rev-parse >expect \
6e7e027f 2179 O:z/b O:z/c B:z/e O:z/d B:z/d &&
362ab315
EN
2180 test_cmp expect actual &&
2181
6e7e027f
EN
2182 test_must_fail git rev-parse :2:z/d &&
2183 git ls-files -s z/d | grep ^100755 &&
2184 test_path_is_file z/d &&
2185 test_path_is_missing y/d
362ab315
EN
2186 )
2187'
2188
2189# Testcase 8d, rename/delete...or not?
2190# (Related to testcase 5b; these may appear slightly inconsistent to users;
2191# Also related to testcases 7d and 7e)
2192# Commit O: z/{b,c,d}
2193# Commit A: y/{b,c}
2194# Commit B: z/{b,c,d,e}
2195# Expected: y/{b,c,e}
2196#
2197# Note: It would also be somewhat reasonable to resolve this as
2198# y/{b,c,e}, CONFLICT(rename/delete: x/d -> y/d or deleted)
362ab315
EN
2199#
2200# In this case, I'm leaning towards: commit A was the one that deleted z/d
2201# and it did the rename of z to y, so the two "conflicts" (rename vs.
2202# delete) are both coming from commit A, which is illogical. Conflicts
2203# during merging are supposed to be about opposite sides doing things
2204# differently.
2205
da1e295e 2206test_setup_8d () {
362ab315
EN
2207 test_create_repo 8d &&
2208 (
2209 cd 8d &&
2210
2211 mkdir z &&
2212 echo b >z/b &&
2213 echo c >z/c &&
2214 test_seq 1 10 >z/d &&
2215 git add z &&
2216 test_tick &&
2217 git commit -m "O" &&
2218
2219 git branch O &&
2220 git branch A &&
2221 git branch B &&
2222
2223 git checkout A &&
2224 git rm z/d &&
2225 git mv z y &&
2226 test_tick &&
2227 git commit -m "A" &&
2228
2229 git checkout B &&
2230 echo e >z/e &&
2231 git add z/e &&
2232 test_tick &&
2233 git commit -m "B"
2234 )
da1e295e 2235}
362ab315 2236
da1e295e
EN
2237test_expect_success '8d: rename/delete...or not?' '
2238 test_setup_8d &&
362ab315
EN
2239 (
2240 cd 8d &&
2241
2242 git checkout A^0 &&
2243
8c8e5bd6 2244 git -c merge.directoryRenames=true merge -s recursive B^0 &&
362ab315
EN
2245
2246 git ls-files -s >out &&
2247 test_line_count = 3 out &&
2248
2249 git rev-parse >actual \
2250 HEAD:y/b HEAD:y/c HEAD:y/e &&
2251 git rev-parse >expect \
2252 O:z/b O:z/c B:z/e &&
2253 test_cmp expect actual
2254 )
2255'
2256
2257# Testcase 8e, Both sides rename, one side adds to original directory
2258# Commit O: z/{b,c}
2259# Commit A: y/{b,c}
2260# Commit B: w/{b,c}, z/d
2261#
2262# Possible Resolutions:
2263# w/o dir-rename detection: z/d, CONFLICT(z/b -> y/b vs. w/b),
2264# CONFLICT(z/c -> y/c vs. w/c)
2265# Currently expected: y/d, CONFLICT(z/b -> y/b vs. w/b),
2266# CONFLICT(z/c -> y/c vs. w/c)
2267# Optimal: ??
2268#
2269# Notes: In commit A, directory z got renamed to y. In commit B, directory z
2270# did NOT get renamed; the directory is still present; instead it is
2271# considered to have just renamed a subset of paths in directory z
2272# elsewhere. Therefore, the directory rename done in commit A to z/
2273# applies to z/d and maps it to y/d.
2274#
2275# It's possible that users would get confused about this, but what
2276# should we do instead? Silently leaving at z/d seems just as bad or
2277# maybe even worse. Perhaps we could print a big warning about z/d
2278# and how we're moving to y/d in this case, but when I started thinking
2279# about the ramifications of doing that, I didn't know how to rule out
2280# that opening other weird edge and corner cases so I just punted.
2281
da1e295e 2282test_setup_8e () {
362ab315
EN
2283 test_create_repo 8e &&
2284 (
2285 cd 8e &&
2286
2287 mkdir z &&
2288 echo b >z/b &&
2289 echo c >z/c &&
2290 git add z &&
2291 test_tick &&
2292 git commit -m "O" &&
2293
2294 git branch O &&
2295 git branch A &&
2296 git branch B &&
2297
2298 git checkout A &&
2299 git mv z y &&
2300 test_tick &&
2301 git commit -m "A" &&
2302
2303 git checkout B &&
2304 git mv z w &&
2305 mkdir z &&
2306 echo d >z/d &&
2307 git add z/d &&
2308 test_tick &&
2309 git commit -m "B"
2310 )
da1e295e 2311}
362ab315 2312
da1e295e
EN
2313test_expect_success '8e: Both sides rename, one side adds to original directory' '
2314 test_setup_8e &&
362ab315
EN
2315 (
2316 cd 8e &&
2317
2318 git checkout A^0 &&
2319
8c8e5bd6 2320 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
362ab315
EN
2321 test_i18ngrep CONFLICT.*rename/rename.*z/c.*y/c.*w/c out &&
2322 test_i18ngrep CONFLICT.*rename/rename.*z/b.*y/b.*w/b out &&
2323
2324 git ls-files -s >out &&
2325 test_line_count = 7 out &&
2326 git ls-files -u >out &&
2327 test_line_count = 6 out &&
2328 git ls-files -o >out &&
2329 test_line_count = 2 out &&
2330
2331 git rev-parse >actual \
2332 :1:z/b :2:y/b :3:w/b :1:z/c :2:y/c :3:w/c :0:y/d &&
2333 git rev-parse >expect \
2334 O:z/b O:z/b O:z/b O:z/c O:z/c O:z/c B:z/d &&
2335 test_cmp expect actual &&
2336
2337 git hash-object >actual \
2338 y/b w/b y/c w/c &&
2339 git rev-parse >expect \
2340 O:z/b O:z/b O:z/c O:z/c &&
2341 test_cmp expect actual &&
2342
2343 test_path_is_missing z/b &&
2344 test_path_is_missing z/c
2345 )
2346'
2347
792e1371
EN
2348###########################################################################
2349# SECTION 9: Other testcases
2350#
2351# This section consists of miscellaneous testcases I thought of during
2352# the implementation which round out the testing.
2353###########################################################################
2354
2355# Testcase 9a, Inner renamed directory within outer renamed directory
2356# (Related to testcase 1f)
2357# Commit O: z/{b,c,d/{e,f,g}}
2358# Commit A: y/{b,c}, x/w/{e,f,g}
2359# Commit B: z/{b,c,d/{e,f,g,h},i}
2360# Expected: y/{b,c,i}, x/w/{e,f,g,h}
2361# NOTE: The only reason this one is interesting is because when a directory
2362# is split into multiple other directories, we determine by the weight
2363# of which one had the most paths going to it. A naive implementation
2364# of that could take the new file in commit B at z/i to x/w/i or x/i.
2365
da1e295e 2366test_setup_9a () {
792e1371
EN
2367 test_create_repo 9a &&
2368 (
2369 cd 9a &&
2370
2371 mkdir -p z/d &&
2372 echo b >z/b &&
2373 echo c >z/c &&
2374 echo e >z/d/e &&
2375 echo f >z/d/f &&
2376 echo g >z/d/g &&
2377 git add z &&
2378 test_tick &&
2379 git commit -m "O" &&
2380
2381 git branch O &&
2382 git branch A &&
2383 git branch B &&
2384
2385 git checkout A &&
2386 mkdir x &&
2387 git mv z/d x/w &&
2388 git mv z y &&
2389 test_tick &&
2390 git commit -m "A" &&
2391
2392 git checkout B &&
2393 echo h >z/d/h &&
2394 echo i >z/i &&
2395 git add z &&
2396 test_tick &&
2397 git commit -m "B"
2398 )
da1e295e 2399}
792e1371 2400
da1e295e
EN
2401test_expect_success '9a: Inner renamed directory within outer renamed directory' '
2402 test_setup_9a &&
792e1371
EN
2403 (
2404 cd 9a &&
2405
2406 git checkout A^0 &&
2407
8c8e5bd6 2408 git -c merge.directoryRenames=true merge -s recursive B^0 &&
792e1371
EN
2409
2410 git ls-files -s >out &&
2411 test_line_count = 7 out &&
2412 git ls-files -u >out &&
2413 test_line_count = 0 out &&
2414 git ls-files -o >out &&
2415 test_line_count = 1 out &&
2416
2417 git rev-parse >actual \
2418 HEAD:y/b HEAD:y/c HEAD:y/i &&
2419 git rev-parse >expect \
2420 O:z/b O:z/c B:z/i &&
2421 test_cmp expect actual &&
2422
2423 git rev-parse >actual \
2424 HEAD:x/w/e HEAD:x/w/f HEAD:x/w/g HEAD:x/w/h &&
2425 git rev-parse >expect \
2426 O:z/d/e O:z/d/f O:z/d/g B:z/d/h &&
2427 test_cmp expect actual
2428 )
2429'
2430
2431# Testcase 9b, Transitive rename with content merge
2432# (Related to testcase 1c)
2433# Commit O: z/{b,c}, x/d_1
2434# Commit A: y/{b,c}, x/d_2
2435# Commit B: z/{b,c,d_3}
2436# Expected: y/{b,c,d_merged}
2437
da1e295e 2438test_setup_9b () {
792e1371
EN
2439 test_create_repo 9b &&
2440 (
2441 cd 9b &&
2442
2443 mkdir z &&
2444 echo b >z/b &&
2445 echo c >z/c &&
2446 mkdir x &&
2447 test_seq 1 10 >x/d &&
2448 git add z x &&
2449 test_tick &&
2450 git commit -m "O" &&
2451
2452 git branch O &&
2453 git branch A &&
2454 git branch B &&
2455
2456 git checkout A &&
2457 git mv z y &&
2458 test_seq 1 11 >x/d &&
2459 git add x/d &&
2460 test_tick &&
2461 git commit -m "A" &&
2462
2463 git checkout B &&
2464 test_seq 0 10 >x/d &&
2465 git mv x/d z/d &&
2466 git add z/d &&
2467 test_tick &&
2468 git commit -m "B"
2469 )
da1e295e 2470}
792e1371 2471
da1e295e
EN
2472test_expect_success '9b: Transitive rename with content merge' '
2473 test_setup_9b &&
792e1371
EN
2474 (
2475 cd 9b &&
2476
2477 git checkout A^0 &&
2478
8c8e5bd6 2479 git -c merge.directoryRenames=true merge -s recursive B^0 &&
792e1371
EN
2480
2481 git ls-files -s >out &&
2482 test_line_count = 3 out &&
2483
2484 test_seq 0 11 >expected &&
2485 test_cmp expected y/d &&
2486 git add expected &&
2487 git rev-parse >actual \
2488 HEAD:y/b HEAD:y/c HEAD:y/d &&
2489 git rev-parse >expect \
2490 O:z/b O:z/c :0:expected &&
2491 test_cmp expect actual &&
2492 test_must_fail git rev-parse HEAD:x/d &&
2493 test_must_fail git rev-parse HEAD:z/d &&
2494 test_path_is_missing z/d &&
2495
2496 test $(git rev-parse HEAD:y/d) != $(git rev-parse O:x/d) &&
2497 test $(git rev-parse HEAD:y/d) != $(git rev-parse A:x/d) &&
2498 test $(git rev-parse HEAD:y/d) != $(git rev-parse B:z/d)
2499 )
2500'
2501
2502# Testcase 9c, Doubly transitive rename?
2503# (Related to testcase 1c, 7e, and 9d)
2504# Commit O: z/{b,c}, x/{d,e}, w/f
2505# Commit A: y/{b,c}, x/{d,e,f,g}
2506# Commit B: z/{b,c,d,e}, w/f
2507# Expected: y/{b,c,d,e}, x/{f,g}
2508#
2509# NOTE: x/f and x/g may be slightly confusing here. The rename from w/f to
2510# x/f is clear. Let's look beyond that. Here's the logic:
2511# Commit B renamed x/ -> z/
2512# Commit A renamed z/ -> y/
2513# So, we could possibly further rename x/f to z/f to y/f, a doubly
2514# transient rename. However, where does it end? We can chain these
2515# indefinitely (see testcase 9d). What if there is a D/F conflict
2516# at z/f/ or y/f/? Or just another file conflict at one of those
2517# paths? In the case of an N-long chain of transient renamings,
2518# where do we "abort" the rename at? Can the user make sense of
2519# the resulting conflict and resolve it?
2520#
2521# To avoid this confusion I use the simple rule that if the other side
2522# of history did a directory rename to a path that your side renamed
2523# away, then ignore that particular rename from the other side of
2524# history for any implicit directory renames.
2525
da1e295e 2526test_setup_9c () {
792e1371
EN
2527 test_create_repo 9c &&
2528 (
2529 cd 9c &&
2530
2531 mkdir z &&
2532 echo b >z/b &&
2533 echo c >z/c &&
2534 mkdir x &&
2535 echo d >x/d &&
2536 echo e >x/e &&
2537 mkdir w &&
2538 echo f >w/f &&
2539 git add z x w &&
2540 test_tick &&
2541 git commit -m "O" &&
2542
2543 git branch O &&
2544 git branch A &&
2545 git branch B &&
2546
2547 git checkout A &&
2548 git mv z y &&
2549 git mv w/f x/ &&
2550 echo g >x/g &&
2551 git add x/g &&
2552 test_tick &&
2553 git commit -m "A" &&
2554
2555 git checkout B &&
2556 git mv x/d z/d &&
2557 git mv x/e z/e &&
2558 test_tick &&
2559 git commit -m "B"
2560 )
da1e295e 2561}
792e1371 2562
da1e295e
EN
2563test_expect_success '9c: Doubly transitive rename?' '
2564 test_setup_9c &&
792e1371
EN
2565 (
2566 cd 9c &&
2567
2568 git checkout A^0 &&
2569
8c8e5bd6 2570 git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
792e1371
EN
2571 test_i18ngrep "WARNING: Avoiding applying x -> z rename to x/f" out &&
2572
2573 git ls-files -s >out &&
2574 test_line_count = 6 out &&
2575 git ls-files -o >out &&
2576 test_line_count = 1 out &&
2577
2578 git rev-parse >actual \
2579 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:y/e HEAD:x/f HEAD:x/g &&
2580 git rev-parse >expect \
2581 O:z/b O:z/c O:x/d O:x/e O:w/f A:x/g &&
2582 test_cmp expect actual
2583 )
2584'
2585
2586# Testcase 9d, N-fold transitive rename?
2587# (Related to testcase 9c...and 1c and 7e)
2588# Commit O: z/a, y/b, x/c, w/d, v/e, u/f
2589# Commit A: y/{a,b}, w/{c,d}, u/{e,f}
2590# Commit B: z/{a,t}, x/{b,c}, v/{d,e}, u/f
2591# Expected: <see NOTE first>
2592#
2593# NOTE: z/ -> y/ (in commit A)
2594# y/ -> x/ (in commit B)
2595# x/ -> w/ (in commit A)
2596# w/ -> v/ (in commit B)
2597# v/ -> u/ (in commit A)
2598# So, if we add a file to z, say z/t, where should it end up? In u?
2599# What if there's another file or directory named 't' in one of the
2600# intervening directories and/or in u itself? Also, shouldn't the
2601# same logic that places 't' in u/ also move ALL other files to u/?
2602# What if there are file or directory conflicts in any of them? If
2603# we attempted to do N-way (N-fold? N-ary? N-uple?) transitive renames
2604# like this, would the user have any hope of understanding any
2605# conflicts or how their working tree ended up? I think not, so I'm
2606# ruling out N-ary transitive renames for N>1.
2607#
2608# Therefore our expected result is:
2609# z/t, y/a, x/b, w/c, u/d, u/e, u/f
2610# The reason that v/d DOES get transitively renamed to u/d is that u/ isn't
2611# renamed somewhere. A slightly sub-optimal result, but it uses fairly
2612# simple rules that are consistent with what we need for all the other
2613# testcases and simplifies things for the user.
2614
da1e295e 2615test_setup_9d () {
792e1371
EN
2616 test_create_repo 9d &&
2617 (
2618 cd 9d &&
2619
2620 mkdir z y x w v u &&
2621 echo a >z/a &&
2622 echo b >y/b &&
2623 echo c >x/c &&
2624 echo d >w/d &&
2625 echo e >v/e &&
2626 echo f >u/f &&
2627 git add z y x w v u &&
2628 test_tick &&
2629 git commit -m "O" &&
2630
2631 git branch O &&
2632 git branch A &&
2633 git branch B &&
2634
2635 git checkout A &&
2636 git mv z/a y/ &&
2637 git mv x/c w/ &&
2638 git mv v/e u/ &&
2639 test_tick &&
2640 git commit -m "A" &&
2641
2642 git checkout B &&
2643 echo t >z/t &&
2644 git mv y/b x/ &&
2645 git mv w/d v/ &&
2646 git add z/t &&
2647 test_tick &&
2648 git commit -m "B"
2649 )
da1e295e 2650}
792e1371 2651
da1e295e
EN
2652test_expect_success '9d: N-way transitive rename?' '
2653 test_setup_9d &&
792e1371
EN
2654 (
2655 cd 9d &&
2656
2657 git checkout A^0 &&
2658
8c8e5bd6 2659 git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
792e1371
EN
2660 test_i18ngrep "WARNING: Avoiding applying z -> y rename to z/t" out &&
2661 test_i18ngrep "WARNING: Avoiding applying y -> x rename to y/a" out &&
2662 test_i18ngrep "WARNING: Avoiding applying x -> w rename to x/b" out &&
2663 test_i18ngrep "WARNING: Avoiding applying w -> v rename to w/c" out &&
2664
2665 git ls-files -s >out &&
2666 test_line_count = 7 out &&
2667 git ls-files -o >out &&
2668 test_line_count = 1 out &&
2669
2670 git rev-parse >actual \
2671 HEAD:z/t \
2672 HEAD:y/a HEAD:x/b HEAD:w/c \
2673 HEAD:u/d HEAD:u/e HEAD:u/f &&
2674 git rev-parse >expect \
2675 B:z/t \
2676 O:z/a O:y/b O:x/c \
2677 O:w/d O:v/e A:u/f &&
2678 test_cmp expect actual
2679 )
2680'
2681
2682# Testcase 9e, N-to-1 whammo
2683# (Related to testcase 9c...and 1c and 7e)
2684# Commit O: dir1/{a,b}, dir2/{d,e}, dir3/{g,h}, dirN/{j,k}
2685# Commit A: dir1/{a,b,c,yo}, dir2/{d,e,f,yo}, dir3/{g,h,i,yo}, dirN/{j,k,l,yo}
2686# Commit B: combined/{a,b,d,e,g,h,j,k}
2687# Expected: combined/{a,b,c,d,e,f,g,h,i,j,k,l}, CONFLICT(Nto1) warnings,
2688# dir1/yo, dir2/yo, dir3/yo, dirN/yo
2689
da1e295e 2690test_setup_9e () {
792e1371
EN
2691 test_create_repo 9e &&
2692 (
2693 cd 9e &&
2694
2695 mkdir dir1 dir2 dir3 dirN &&
2696 echo a >dir1/a &&
2697 echo b >dir1/b &&
2698 echo d >dir2/d &&
2699 echo e >dir2/e &&
2700 echo g >dir3/g &&
2701 echo h >dir3/h &&
2702 echo j >dirN/j &&
2703 echo k >dirN/k &&
2704 git add dir* &&
2705 test_tick &&
2706 git commit -m "O" &&
2707
2708 git branch O &&
2709 git branch A &&
2710 git branch B &&
2711
2712 git checkout A &&
2713 echo c >dir1/c &&
2714 echo yo >dir1/yo &&
2715 echo f >dir2/f &&
2716 echo yo >dir2/yo &&
2717 echo i >dir3/i &&
2718 echo yo >dir3/yo &&
2719 echo l >dirN/l &&
2720 echo yo >dirN/yo &&
2721 git add dir* &&
2722 test_tick &&
2723 git commit -m "A" &&
2724
2725 git checkout B &&
2726 git mv dir1 combined &&
2727 git mv dir2/* combined/ &&
2728 git mv dir3/* combined/ &&
2729 git mv dirN/* combined/ &&
2730 test_tick &&
2731 git commit -m "B"
2732 )
da1e295e 2733}
792e1371 2734
da1e295e
EN
2735test_expect_success C_LOCALE_OUTPUT '9e: N-to-1 whammo' '
2736 test_setup_9e &&
792e1371
EN
2737 (
2738 cd 9e &&
2739
2740 git checkout A^0 &&
2741
8c8e5bd6 2742 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
792e1371
EN
2743 grep "CONFLICT (implicit dir rename): Cannot map more than one path to combined/yo" out >error_line &&
2744 grep -q dir1/yo error_line &&
2745 grep -q dir2/yo error_line &&
2746 grep -q dir3/yo error_line &&
2747 grep -q dirN/yo error_line &&
2748
2749 git ls-files -s >out &&
2750 test_line_count = 16 out &&
2751 git ls-files -u >out &&
2752 test_line_count = 0 out &&
2753 git ls-files -o >out &&
2754 test_line_count = 2 out &&
2755
2756 git rev-parse >actual \
2757 :0:combined/a :0:combined/b :0:combined/c \
2758 :0:combined/d :0:combined/e :0:combined/f \
2759 :0:combined/g :0:combined/h :0:combined/i \
2760 :0:combined/j :0:combined/k :0:combined/l &&
2761 git rev-parse >expect \
2762 O:dir1/a O:dir1/b A:dir1/c \
2763 O:dir2/d O:dir2/e A:dir2/f \
2764 O:dir3/g O:dir3/h A:dir3/i \
2765 O:dirN/j O:dirN/k A:dirN/l &&
2766 test_cmp expect actual &&
2767
2768 git rev-parse >actual \
2769 :0:dir1/yo :0:dir2/yo :0:dir3/yo :0:dirN/yo &&
2770 git rev-parse >expect \
2771 A:dir1/yo A:dir2/yo A:dir3/yo A:dirN/yo &&
2772 test_cmp expect actual
2773 )
2774'
2775
2776# Testcase 9f, Renamed directory that only contained immediate subdirs
2777# (Related to testcases 1e & 9g)
2778# Commit O: goal/{a,b}/$more_files
2779# Commit A: priority/{a,b}/$more_files
2780# Commit B: goal/{a,b}/$more_files, goal/c
2781# Expected: priority/{a,b}/$more_files, priority/c
2782
da1e295e 2783test_setup_9f () {
792e1371
EN
2784 test_create_repo 9f &&
2785 (
2786 cd 9f &&
2787
2788 mkdir -p goal/a &&
2789 mkdir -p goal/b &&
2790 echo foo >goal/a/foo &&
2791 echo bar >goal/b/bar &&
2792 echo baz >goal/b/baz &&
2793 git add goal &&
2794 test_tick &&
2795 git commit -m "O" &&
2796
2797 git branch O &&
2798 git branch A &&
2799 git branch B &&
2800
2801 git checkout A &&
2802 git mv goal/ priority &&
2803 test_tick &&
2804 git commit -m "A" &&
2805
2806 git checkout B &&
2807 echo c >goal/c &&
2808 git add goal/c &&
2809 test_tick &&
2810 git commit -m "B"
2811 )
da1e295e 2812}
792e1371 2813
da1e295e
EN
2814test_expect_success '9f: Renamed directory that only contained immediate subdirs' '
2815 test_setup_9f &&
792e1371
EN
2816 (
2817 cd 9f &&
2818
2819 git checkout A^0 &&
2820
8c8e5bd6 2821 git -c merge.directoryRenames=true merge -s recursive B^0 &&
792e1371
EN
2822
2823 git ls-files -s >out &&
2824 test_line_count = 4 out &&
2825
2826 git rev-parse >actual \
2827 HEAD:priority/a/foo \
2828 HEAD:priority/b/bar \
2829 HEAD:priority/b/baz \
2830 HEAD:priority/c &&
2831 git rev-parse >expect \
2832 O:goal/a/foo \
2833 O:goal/b/bar \
2834 O:goal/b/baz \
2835 B:goal/c &&
2836 test_cmp expect actual &&
2837 test_must_fail git rev-parse HEAD:goal/c
2838 )
2839'
2840
2841# Testcase 9g, Renamed directory that only contained immediate subdirs, immediate subdirs renamed
2842# (Related to testcases 1e & 9f)
2843# Commit O: goal/{a,b}/$more_files
2844# Commit A: priority/{alpha,bravo}/$more_files
2845# Commit B: goal/{a,b}/$more_files, goal/c
2846# Expected: priority/{alpha,bravo}/$more_files, priority/c
2847
da1e295e 2848test_setup_9g () {
792e1371
EN
2849 test_create_repo 9g &&
2850 (
2851 cd 9g &&
2852
2853 mkdir -p goal/a &&
2854 mkdir -p goal/b &&
2855 echo foo >goal/a/foo &&
2856 echo bar >goal/b/bar &&
2857 echo baz >goal/b/baz &&
2858 git add goal &&
2859 test_tick &&
2860 git commit -m "O" &&
2861
2862 git branch O &&
2863 git branch A &&
2864 git branch B &&
2865
2866 git checkout A &&
2867 mkdir priority &&
2868 git mv goal/a/ priority/alpha &&
2869 git mv goal/b/ priority/beta &&
2870 rmdir goal/ &&
2871 test_tick &&
2872 git commit -m "A" &&
2873
2874 git checkout B &&
2875 echo c >goal/c &&
2876 git add goal/c &&
2877 test_tick &&
2878 git commit -m "B"
2879 )
da1e295e 2880}
792e1371 2881
da1e295e 2882test_expect_failure '9g: Renamed directory that only contained immediate subdirs, immediate subdirs renamed' '
a0601b2e 2883 test_setup_9g &&
792e1371
EN
2884 (
2885 cd 9g &&
2886
2887 git checkout A^0 &&
2888
8c8e5bd6 2889 git -c merge.directoryRenames=true merge -s recursive B^0 &&
792e1371
EN
2890
2891 git ls-files -s >out &&
2892 test_line_count = 4 out &&
2893
2894 git rev-parse >actual \
2895 HEAD:priority/alpha/foo \
2896 HEAD:priority/beta/bar \
2897 HEAD:priority/beta/baz \
2898 HEAD:priority/c &&
2899 git rev-parse >expect \
2900 O:goal/a/foo \
2901 O:goal/b/bar \
2902 O:goal/b/baz \
2903 B:goal/c &&
2904 test_cmp expect actual &&
2905 test_must_fail git rev-parse HEAD:goal/c
2906 )
2907'
2908
bc71c4ee
EN
2909# Testcase 9h, Avoid implicit rename if involved as source on other side
2910# (Extremely closely related to testcase 3a)
2911# Commit O: z/{b,c,d_1}
2912# Commit A: z/{b,c,d_2}
2913# Commit B: y/{b,c}, x/d_1
2914# Expected: y/{b,c}, x/d_2
2915# NOTE: If we applied the z/ -> y/ rename to z/d, then we'd end up with
2916# a rename/rename(1to2) conflict (z/d -> y/d vs. x/d)
da1e295e 2917test_setup_9h () {
bc71c4ee
EN
2918 test_create_repo 9h &&
2919 (
2920 cd 9h &&
2921
2922 mkdir z &&
2923 echo b >z/b &&
2924 echo c >z/c &&
2925 printf "1\n2\n3\n4\n5\n6\n7\n8\nd\n" >z/d &&
2926 git add z &&
2927 test_tick &&
2928 git commit -m "O" &&
2929
2930 git branch O &&
2931 git branch A &&
2932 git branch B &&
2933
2934 git checkout A &&
2935 test_tick &&
2936 echo more >>z/d &&
2937 git add z/d &&
2938 git commit -m "A" &&
2939
2940 git checkout B &&
2941 mkdir y &&
2942 mkdir x &&
2943 git mv z/b y/ &&
2944 git mv z/c y/ &&
2945 git mv z/d x/ &&
2946 rmdir z &&
2947 test_tick &&
2948 git commit -m "B"
2949 )
da1e295e 2950}
bc71c4ee 2951
da1e295e
EN
2952test_expect_success '9h: Avoid dir rename on merely modified path' '
2953 test_setup_9h &&
bc71c4ee
EN
2954 (
2955 cd 9h &&
2956
2957 git checkout A^0 &&
2958
8c8e5bd6 2959 git -c merge.directoryRenames=true merge -s recursive B^0 &&
bc71c4ee
EN
2960
2961 git ls-files -s >out &&
2962 test_line_count = 3 out &&
2963
2964 git rev-parse >actual \
2965 HEAD:y/b HEAD:y/c HEAD:x/d &&
2966 git rev-parse >expect \
2967 O:z/b O:z/c A:z/d &&
2968 test_cmp expect actual
2969 )
2970'
2971
792e1371
EN
2972###########################################################################
2973# Rules suggested by section 9:
2974#
2975# If the other side of history did a directory rename to a path that your
2976# side renamed away, then ignore that particular rename from the other
2977# side of history for any implicit directory renames.
2978###########################################################################
2979
a0b0a151
EN
2980###########################################################################
2981# SECTION 10: Handling untracked files
2982#
2983# unpack_trees(), upon which the recursive merge algorithm is based, aborts
2984# the operation if untracked or dirty files would be deleted or overwritten
2985# by the merge. Unfortunately, unpack_trees() does not understand renames,
2986# and if it doesn't abort, then it muddies up the working directory before
2987# we even get to the point of detecting renames, so we need some special
2988# handling, at least in the case of directory renames.
2989###########################################################################
2990
2991# Testcase 10a, Overwrite untracked: normal rename/delete
2992# Commit O: z/{b,c_1}
2993# Commit A: z/b + untracked z/c + untracked z/d
2994# Commit B: z/{b,d_1}
2995# Expected: Aborted Merge +
2996# ERROR_MSG(untracked working tree files would be overwritten by merge)
2997
da1e295e 2998test_setup_10a () {
a0b0a151
EN
2999 test_create_repo 10a &&
3000 (
3001 cd 10a &&
3002
3003 mkdir z &&
3004 echo b >z/b &&
3005 echo c >z/c &&
3006 git add z &&
3007 test_tick &&
3008 git commit -m "O" &&
3009
3010 git branch O &&
3011 git branch A &&
3012 git branch B &&
3013
3014 git checkout A &&
3015 git rm z/c &&
3016 test_tick &&
3017 git commit -m "A" &&
3018
3019 git checkout B &&
3020 git mv z/c z/d &&
3021 test_tick &&
3022 git commit -m "B"
3023 )
da1e295e 3024}
a0b0a151 3025
da1e295e
EN
3026test_expect_success '10a: Overwrite untracked with normal rename/delete' '
3027 test_setup_10a &&
a0b0a151
EN
3028 (
3029 cd 10a &&
3030
3031 git checkout A^0 &&
3032 echo very >z/c &&
3033 echo important >z/d &&
3034
8c8e5bd6 3035 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
a0b0a151
EN
3036 test_i18ngrep "The following untracked working tree files would be overwritten by merge" err &&
3037
3038 git ls-files -s >out &&
3039 test_line_count = 1 out &&
3040 git ls-files -o >out &&
3041 test_line_count = 4 out &&
3042
3043 echo very >expect &&
3044 test_cmp expect z/c &&
3045
3046 echo important >expect &&
3047 test_cmp expect z/d &&
3048
3049 git rev-parse HEAD:z/b >actual &&
3050 git rev-parse O:z/b >expect &&
3051 test_cmp expect actual
3052 )
3053'
3054
3055# Testcase 10b, Overwrite untracked: dir rename + delete
3056# Commit O: z/{b,c_1}
3057# Commit A: y/b + untracked y/{c,d,e}
3058# Commit B: z/{b,d_1,e}
3059# Expected: Failed Merge; y/b + untracked y/c + untracked y/d on disk +
3060# z/c_1 -> z/d_1 rename recorded at stage 3 for y/d +
3061# ERROR_MSG(refusing to lose untracked file at 'y/d')
3062
da1e295e 3063test_setup_10b () {
a0b0a151
EN
3064 test_create_repo 10b &&
3065 (
3066 cd 10b &&
3067
3068 mkdir z &&
3069 echo b >z/b &&
3070 echo c >z/c &&
3071 git add z &&
3072 test_tick &&
3073 git commit -m "O" &&
3074
3075 git branch O &&
3076 git branch A &&
3077 git branch B &&
3078
3079 git checkout A &&
3080 git rm z/c &&
3081 git mv z/ y/ &&
3082 test_tick &&
3083 git commit -m "A" &&
3084
3085 git checkout B &&
3086 git mv z/c z/d &&
3087 echo e >z/e &&
3088 git add z/e &&
3089 test_tick &&
3090 git commit -m "B"
3091 )
da1e295e 3092}
a0b0a151 3093
da1e295e
EN
3094test_expect_success '10b: Overwrite untracked with dir rename + delete' '
3095 test_setup_10b &&
a0b0a151
EN
3096 (
3097 cd 10b &&
3098
3099 git checkout A^0 &&
3100 echo very >y/c &&
3101 echo important >y/d &&
3102 echo contents >y/e &&
3103
8c8e5bd6 3104 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
a0b0a151
EN
3105 test_i18ngrep "CONFLICT (rename/delete).*Version B\^0 of y/d left in tree at y/d~B\^0" out &&
3106 test_i18ngrep "Error: Refusing to lose untracked file at y/e; writing to y/e~B\^0 instead" out &&
3107
3108 git ls-files -s >out &&
3109 test_line_count = 3 out &&
3110 git ls-files -u >out &&
3111 test_line_count = 2 out &&
3112 git ls-files -o >out &&
3113 test_line_count = 5 out &&
3114
3115 git rev-parse >actual \
3116 :0:y/b :3:y/d :3:y/e &&
3117 git rev-parse >expect \
3118 O:z/b O:z/c B:z/e &&
3119 test_cmp expect actual &&
3120
3121 echo very >expect &&
3122 test_cmp expect y/c &&
3123
3124 echo important >expect &&
3125 test_cmp expect y/d &&
3126
3127 echo contents >expect &&
3128 test_cmp expect y/e
3129 )
3130'
3131
3132# Testcase 10c, Overwrite untracked: dir rename/rename(1to2)
3133# Commit O: z/{a,b}, x/{c,d}
3134# Commit A: y/{a,b}, w/c, x/d + different untracked y/c
3135# Commit B: z/{a,b,c}, x/d
3136# Expected: Failed Merge; y/{a,b} + x/d + untracked y/c +
3137# CONFLICT(rename/rename) x/c -> w/c vs y/c +
3138# y/c~B^0 +
3139# ERROR_MSG(Refusing to lose untracked file at y/c)
3140
da1e295e
EN
3141test_setup_10c () {
3142 test_create_repo 10c_$1 &&
a0b0a151 3143 (
da1e295e 3144 cd 10c_$1 &&
a0b0a151
EN
3145
3146 mkdir z x &&
3147 echo a >z/a &&
3148 echo b >z/b &&
3149 echo c >x/c &&
3150 echo d >x/d &&
3151 git add z x &&
3152 test_tick &&
3153 git commit -m "O" &&
3154
3155 git branch O &&
3156 git branch A &&
3157 git branch B &&
3158
3159 git checkout A &&
3160 mkdir w &&
3161 git mv x/c w/c &&
3162 git mv z/ y/ &&
3163 test_tick &&
3164 git commit -m "A" &&
3165
3166 git checkout B &&
3167 git mv x/c z/ &&
3168 test_tick &&
3169 git commit -m "B"
3170 )
da1e295e 3171}
a0b0a151 3172
da1e295e
EN
3173test_expect_success '10c1: Overwrite untracked with dir rename/rename(1to2)' '
3174 test_setup_10c 1 &&
a0b0a151 3175 (
da1e295e 3176 cd 10c_1 &&
a0b0a151
EN
3177
3178 git checkout A^0 &&
3179 echo important >y/c &&
3180
8c8e5bd6 3181 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
a0b0a151
EN
3182 test_i18ngrep "CONFLICT (rename/rename)" out &&
3183 test_i18ngrep "Refusing to lose untracked file at y/c; adding as y/c~B\^0 instead" out &&
3184
3185 git ls-files -s >out &&
3186 test_line_count = 6 out &&
3187 git ls-files -u >out &&
3188 test_line_count = 3 out &&
3189 git ls-files -o >out &&
3190 test_line_count = 3 out &&
3191
3192 git rev-parse >actual \
3193 :0:y/a :0:y/b :0:x/d :1:x/c :2:w/c :3:y/c &&
3194 git rev-parse >expect \
3195 O:z/a O:z/b O:x/d O:x/c O:x/c O:x/c &&
3196 test_cmp expect actual &&
3197
3198 git hash-object y/c~B^0 >actual &&
3199 git rev-parse O:x/c >expect &&
3200 test_cmp expect actual &&
3201
3202 echo important >expect &&
3203 test_cmp expect y/c
3204 )
3205'
3206
da1e295e
EN
3207test_expect_success '10c2: Overwrite untracked with dir rename/rename(1to2), other direction' '
3208 test_setup_10c 2 &&
b8cd1bb7 3209 (
da1e295e 3210 cd 10c_2 &&
b8cd1bb7
EN
3211
3212 git reset --hard &&
3213 git clean -fdqx &&
3214
3215 git checkout B^0 &&
3216 mkdir y &&
3217 echo important >y/c &&
3218
8c8e5bd6 3219 test_must_fail git -c merge.directoryRenames=true merge -s recursive A^0 >out 2>err &&
b8cd1bb7
EN
3220 test_i18ngrep "CONFLICT (rename/rename)" out &&
3221 test_i18ngrep "Refusing to lose untracked file at y/c; adding as y/c~HEAD instead" out &&
3222
3223 git ls-files -s >out &&
3224 test_line_count = 6 out &&
3225 git ls-files -u >out &&
3226 test_line_count = 3 out &&
3227 git ls-files -o >out &&
3228 test_line_count = 3 out &&
3229
3230 git rev-parse >actual \
3231 :0:y/a :0:y/b :0:x/d :1:x/c :3:w/c :2:y/c &&
3232 git rev-parse >expect \
3233 O:z/a O:z/b O:x/d O:x/c O:x/c O:x/c &&
3234 test_cmp expect actual &&
3235
3236 git hash-object y/c~HEAD >actual &&
3237 git rev-parse O:x/c >expect &&
3238 test_cmp expect actual &&
3239
3240 echo important >expect &&
3241 test_cmp expect y/c
3242 )
3243'
3244
a0b0a151
EN
3245# Testcase 10d, Delete untracked w/ dir rename/rename(2to1)
3246# Commit O: z/{a,b,c_1}, x/{d,e,f_2}
3247# Commit A: y/{a,b}, x/{d,e,f_2,wham_1} + untracked y/wham
3248# Commit B: z/{a,b,c_1,wham_2}, y/{d,e}
bbafc9c4 3249# Expected: Failed Merge; y/{a,b,d,e} + untracked y/{wham,wham~merged}+
a0b0a151
EN
3250# CONFLICT(rename/rename) z/c_1 vs x/f_2 -> y/wham
3251# ERROR_MSG(Refusing to lose untracked file at y/wham)
3252
da1e295e 3253test_setup_10d () {
a0b0a151
EN
3254 test_create_repo 10d &&
3255 (
3256 cd 10d &&
3257
3258 mkdir z x &&
3259 echo a >z/a &&
3260 echo b >z/b &&
3261 echo c >z/c &&
3262 echo d >x/d &&
3263 echo e >x/e &&
3264 echo f >x/f &&
3265 git add z x &&
3266 test_tick &&
3267 git commit -m "O" &&
3268
3269 git branch O &&
3270 git branch A &&
3271 git branch B &&
3272
3273 git checkout A &&
3274 git mv z/c x/wham &&
3275 git mv z/ y/ &&
3276 test_tick &&
3277 git commit -m "A" &&
3278
3279 git checkout B &&
3280 git mv x/f z/wham &&
3281 git mv x/ y/ &&
3282 test_tick &&
3283 git commit -m "B"
3284 )
da1e295e 3285}
a0b0a151 3286
da1e295e
EN
3287test_expect_success '10d: Delete untracked with dir rename/rename(2to1)' '
3288 test_setup_10d &&
a0b0a151
EN
3289 (
3290 cd 10d &&
3291
3292 git checkout A^0 &&
3293 echo important >y/wham &&
3294
8c8e5bd6 3295 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
a0b0a151
EN
3296 test_i18ngrep "CONFLICT (rename/rename)" out &&
3297 test_i18ngrep "Refusing to lose untracked file at y/wham" out &&
3298
3299 git ls-files -s >out &&
3300 test_line_count = 6 out &&
3301 git ls-files -u >out &&
3302 test_line_count = 2 out &&
3303 git ls-files -o >out &&
bbafc9c4 3304 test_line_count = 3 out &&
a0b0a151
EN
3305
3306 git rev-parse >actual \
3307 :0:y/a :0:y/b :0:y/d :0:y/e :2:y/wham :3:y/wham &&
3308 git rev-parse >expect \
3309 O:z/a O:z/b O:x/d O:x/e O:z/c O:x/f &&
3310 test_cmp expect actual &&
3311
3312 test_must_fail git rev-parse :1:y/wham &&
3313
3314 echo important >expect &&
3315 test_cmp expect y/wham &&
3316
bbafc9c4
EN
3317 # Test that the two-way merge in y/wham~merged is as expected
3318 git cat-file -p :2:y/wham >expect &&
3319 git cat-file -p :3:y/wham >other &&
3320 >empty &&
3321 test_must_fail git merge-file \
3322 -L "HEAD" \
3323 -L "" \
3324 -L "B^0" \
3325 expect empty other &&
3326 test_cmp expect y/wham~merged
a0b0a151
EN
3327 )
3328'
3329
3330# Testcase 10e, Does git complain about untracked file that's not in the way?
3331# Commit O: z/{a,b}
3332# Commit A: y/{a,b} + untracked z/c
3333# Commit B: z/{a,b,c}
3334# Expected: y/{a,b,c} + untracked z/c
3335
da1e295e 3336test_setup_10e () {
a0b0a151
EN
3337 test_create_repo 10e &&
3338 (
3339 cd 10e &&
3340
3341 mkdir z &&
3342 echo a >z/a &&
3343 echo b >z/b &&
3344 git add z &&
3345 test_tick &&
3346 git commit -m "O" &&
3347
3348 git branch O &&
3349 git branch A &&
3350 git branch B &&
3351
3352 git checkout A &&
3353 git mv z/ y/ &&
3354 test_tick &&
3355 git commit -m "A" &&
3356
3357 git checkout B &&
3358 echo c >z/c &&
3359 git add z/c &&
3360 test_tick &&
3361 git commit -m "B"
3362 )
da1e295e 3363}
a0b0a151 3364
da1e295e 3365test_expect_failure '10e: Does git complain about untracked file that is not really in the way?' '
a0601b2e 3366 test_setup_10e &&
a0b0a151
EN
3367 (
3368 cd 10e &&
3369
3370 git checkout A^0 &&
3371 mkdir z &&
3372 echo random >z/c &&
3373
8c8e5bd6 3374 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
a0b0a151
EN
3375 test_i18ngrep ! "following untracked working tree files would be overwritten by merge" err &&
3376
3377 git ls-files -s >out &&
3378 test_line_count = 3 out &&
3379 git ls-files -u >out &&
3380 test_line_count = 0 out &&
3381 git ls-files -o >out &&
3382 test_line_count = 3 out &&
3383
3384 git rev-parse >actual \
3385 :0:y/a :0:y/b :0:y/c &&
3386 git rev-parse >expect \
3387 O:z/a O:z/b B:z/c &&
3388 test_cmp expect actual &&
3389
3390 echo random >expect &&
3391 test_cmp expect z/c
3392 )
3393'
3394
a7a43604
EN
3395###########################################################################
3396# SECTION 11: Handling dirty (not up-to-date) files
3397#
3398# unpack_trees(), upon which the recursive merge algorithm is based, aborts
3399# the operation if untracked or dirty files would be deleted or overwritten
3400# by the merge. Unfortunately, unpack_trees() does not understand renames,
3401# and if it doesn't abort, then it muddies up the working directory before
3402# we even get to the point of detecting renames, so we need some special
3403# handling. This was true even of normal renames, but there are additional
3404# codepaths that need special handling with directory renames. Add
3405# testcases for both renamed-by-directory-rename-detection and standard
3406# rename cases.
3407###########################################################################
3408
3409# Testcase 11a, Avoid losing dirty contents with simple rename
3410# Commit O: z/{a,b_v1},
3411# Commit A: z/{a,c_v1}, and z/c_v1 has uncommitted mods
3412# Commit B: z/{a,b_v2}
3413# Expected: ERROR_MSG(Refusing to lose dirty file at z/c) +
3414# z/a, staged version of z/c has sha1sum matching B:z/b_v2,
3415# z/c~HEAD with contents of B:z/b_v2,
3416# z/c with uncommitted mods on top of A:z/c_v1
3417
da1e295e 3418test_setup_11a () {
a7a43604
EN
3419 test_create_repo 11a &&
3420 (
3421 cd 11a &&
3422
3423 mkdir z &&
3424 echo a >z/a &&
3425 test_seq 1 10 >z/b &&
3426 git add z &&
3427 test_tick &&
3428 git commit -m "O" &&
3429
3430 git branch O &&
3431 git branch A &&
3432 git branch B &&
3433
3434 git checkout A &&
3435 git mv z/b z/c &&
3436 test_tick &&
3437 git commit -m "A" &&
3438
3439 git checkout B &&
3440 echo 11 >>z/b &&
3441 git add z/b &&
3442 test_tick &&
3443 git commit -m "B"
3444 )
da1e295e 3445}
a7a43604 3446
da1e295e
EN
3447test_expect_success '11a: Avoid losing dirty contents with simple rename' '
3448 test_setup_11a &&
a7a43604
EN
3449 (
3450 cd 11a &&
3451
3452 git checkout A^0 &&
3453 echo stuff >>z/c &&
3454
8c8e5bd6 3455 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
a7a43604
EN
3456 test_i18ngrep "Refusing to lose dirty file at z/c" out &&
3457
3458 test_seq 1 10 >expected &&
3459 echo stuff >>expected &&
3460 test_cmp expected z/c &&
3461
3462 git ls-files -s >out &&
3463 test_line_count = 2 out &&
3464 git ls-files -u >out &&
3465 test_line_count = 1 out &&
3466 git ls-files -o >out &&
3467 test_line_count = 4 out &&
3468
3469 git rev-parse >actual \
3470 :0:z/a :2:z/c &&
3471 git rev-parse >expect \
3472 O:z/a B:z/b &&
3473 test_cmp expect actual &&
3474
3475 git hash-object z/c~HEAD >actual &&
3476 git rev-parse B:z/b >expect &&
3477 test_cmp expect actual
3478 )
3479'
3480
3481# Testcase 11b, Avoid losing dirty file involved in directory rename
3482# Commit O: z/a, x/{b,c_v1}
3483# Commit A: z/{a,c_v1}, x/b, and z/c_v1 has uncommitted mods
3484# Commit B: y/a, x/{b,c_v2}
3485# Expected: y/{a,c_v2}, x/b, z/c_v1 with uncommitted mods untracked,
3486# ERROR_MSG(Refusing to lose dirty file at z/c)
3487
3488
da1e295e 3489test_setup_11b () {
a7a43604
EN
3490 test_create_repo 11b &&
3491 (
3492 cd 11b &&
3493
3494 mkdir z x &&
3495 echo a >z/a &&
3496 echo b >x/b &&
3497 test_seq 1 10 >x/c &&
3498 git add z x &&
3499 test_tick &&
3500 git commit -m "O" &&
3501
3502 git branch O &&
3503 git branch A &&
3504 git branch B &&
3505
3506 git checkout A &&
3507 git mv x/c z/c &&
3508 test_tick &&
3509 git commit -m "A" &&
3510
3511 git checkout B &&
3512 git mv z y &&
3513 echo 11 >>x/c &&
3514 git add x/c &&
3515 test_tick &&
3516 git commit -m "B"
3517 )
da1e295e 3518}
a7a43604 3519
da1e295e
EN
3520test_expect_success '11b: Avoid losing dirty file involved in directory rename' '
3521 test_setup_11b &&
a7a43604
EN
3522 (
3523 cd 11b &&
3524
3525 git checkout A^0 &&
3526 echo stuff >>z/c &&
3527
8c8e5bd6 3528 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
a7a43604
EN
3529 test_i18ngrep "Refusing to lose dirty file at z/c" out &&
3530
3531 grep -q stuff z/c &&
3532 test_seq 1 10 >expected &&
3533 echo stuff >>expected &&
3534 test_cmp expected z/c &&
3535
3536 git ls-files -s >out &&
3537 test_line_count = 3 out &&
3538 git ls-files -u >out &&
3539 test_line_count = 0 out &&
3540 git ls-files -m >out &&
3541 test_line_count = 0 out &&
3542 git ls-files -o >out &&
3543 test_line_count = 4 out &&
3544
3545 git rev-parse >actual \
3546 :0:x/b :0:y/a :0:y/c &&
3547 git rev-parse >expect \
3548 O:x/b O:z/a B:x/c &&
3549 test_cmp expect actual &&
3550
3551 git hash-object y/c >actual &&
3552 git rev-parse B:x/c >expect &&
3553 test_cmp expect actual
3554 )
3555'
3556
3557# Testcase 11c, Avoid losing not-up-to-date with rename + D/F conflict
3558# Commit O: y/a, x/{b,c_v1}
3559# Commit A: y/{a,c_v1}, x/b, and y/c_v1 has uncommitted mods
3560# Commit B: y/{a,c/d}, x/{b,c_v2}
3561# Expected: Abort_msg("following files would be overwritten by merge") +
3562# y/c left untouched (still has uncommitted mods)
3563
da1e295e 3564test_setup_11c () {
a7a43604
EN
3565 test_create_repo 11c &&
3566 (
3567 cd 11c &&
3568
3569 mkdir y x &&
3570 echo a >y/a &&
3571 echo b >x/b &&
3572 test_seq 1 10 >x/c &&
3573 git add y x &&
3574 test_tick &&
3575 git commit -m "O" &&
3576
3577 git branch O &&
3578 git branch A &&
3579 git branch B &&
3580
3581 git checkout A &&
3582 git mv x/c y/c &&
3583 test_tick &&
3584 git commit -m "A" &&
3585
3586 git checkout B &&
3587 mkdir y/c &&
3588 echo d >y/c/d &&
3589 echo 11 >>x/c &&
3590 git add x/c y/c/d &&
3591 test_tick &&
3592 git commit -m "B"
3593 )
da1e295e 3594}
a7a43604 3595
da1e295e
EN
3596test_expect_success '11c: Avoid losing not-uptodate with rename + D/F conflict' '
3597 test_setup_11c &&
a7a43604
EN
3598 (
3599 cd 11c &&
3600
3601 git checkout A^0 &&
3602 echo stuff >>y/c &&
3603
8c8e5bd6 3604 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
a7a43604
EN
3605 test_i18ngrep "following files would be overwritten by merge" err &&
3606
3607 grep -q stuff y/c &&
3608 test_seq 1 10 >expected &&
3609 echo stuff >>expected &&
3610 test_cmp expected y/c &&
3611
3612 git ls-files -s >out &&
3613 test_line_count = 3 out &&
3614 git ls-files -u >out &&
3615 test_line_count = 0 out &&
3616 git ls-files -m >out &&
3617 test_line_count = 1 out &&
3618 git ls-files -o >out &&
3619 test_line_count = 3 out
3620 )
3621'
3622
3623# Testcase 11d, Avoid losing not-up-to-date with rename + D/F conflict
3624# Commit O: z/a, x/{b,c_v1}
3625# Commit A: z/{a,c_v1}, x/b, and z/c_v1 has uncommitted mods
3626# Commit B: y/{a,c/d}, x/{b,c_v2}
3627# Expected: D/F: y/c_v2 vs y/c/d) +
3628# Warning_Msg("Refusing to lose dirty file at z/c) +
3629# y/{a,c~HEAD,c/d}, x/b, now-untracked z/c_v1 with uncommitted mods
3630
da1e295e 3631test_setup_11d () {
a7a43604
EN
3632 test_create_repo 11d &&
3633 (
3634 cd 11d &&
3635
3636 mkdir z x &&
3637 echo a >z/a &&
3638 echo b >x/b &&
3639 test_seq 1 10 >x/c &&
3640 git add z x &&
3641 test_tick &&
3642 git commit -m "O" &&
3643
3644 git branch O &&
3645 git branch A &&
3646 git branch B &&
3647
3648 git checkout A &&
3649 git mv x/c z/c &&
3650 test_tick &&
3651 git commit -m "A" &&
3652
3653 git checkout B &&
3654 git mv z y &&
3655 mkdir y/c &&
3656 echo d >y/c/d &&
3657 echo 11 >>x/c &&
3658 git add x/c y/c/d &&
3659 test_tick &&
3660 git commit -m "B"
3661 )
da1e295e 3662}
a7a43604 3663
da1e295e
EN
3664test_expect_success '11d: Avoid losing not-uptodate with rename + D/F conflict' '
3665 test_setup_11d &&
a7a43604
EN
3666 (
3667 cd 11d &&
3668
3669 git checkout A^0 &&
3670 echo stuff >>z/c &&
3671
8c8e5bd6 3672 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
a7a43604
EN
3673 test_i18ngrep "Refusing to lose dirty file at z/c" out &&
3674
3675 grep -q stuff z/c &&
3676 test_seq 1 10 >expected &&
3677 echo stuff >>expected &&
c8ce3763 3678 test_cmp expected z/c &&
a7a43604
EN
3679
3680 git ls-files -s >out &&
3681 test_line_count = 4 out &&
3682 git ls-files -u >out &&
3683 test_line_count = 1 out &&
3684 git ls-files -o >out &&
3685 test_line_count = 5 out &&
3686
3687 git rev-parse >actual \
3688 :0:x/b :0:y/a :0:y/c/d :3:y/c &&
3689 git rev-parse >expect \
3690 O:x/b O:z/a B:y/c/d B:x/c &&
3691 test_cmp expect actual &&
3692
3693 git hash-object y/c~HEAD >actual &&
3694 git rev-parse B:x/c >expect &&
3695 test_cmp expect actual
3696 )
3697'
3698
3699# Testcase 11e, Avoid deleting not-up-to-date with dir rename/rename(1to2)/add
3700# Commit O: z/{a,b}, x/{c_1,d}
3701# Commit A: y/{a,b,c_2}, x/d, w/c_1, and y/c_2 has uncommitted mods
3702# Commit B: z/{a,b,c_1}, x/d
3703# Expected: Failed Merge; y/{a,b} + x/d +
3704# CONFLICT(rename/rename) x/c_1 -> w/c_1 vs y/c_1 +
3705# ERROR_MSG(Refusing to lose dirty file at y/c)
3706# y/c~B^0 has O:x/c_1 contents
3707# y/c~HEAD has A:y/c_2 contents
3708# y/c has dirty file from before merge
3709
da1e295e 3710test_setup_11e () {
a7a43604
EN
3711 test_create_repo 11e &&
3712 (
3713 cd 11e &&
3714
3715 mkdir z x &&
3716 echo a >z/a &&
3717 echo b >z/b &&
3718 echo c >x/c &&
3719 echo d >x/d &&
3720 git add z x &&
3721 test_tick &&
3722 git commit -m "O" &&
3723
3724 git branch O &&
3725 git branch A &&
3726 git branch B &&
3727
3728 git checkout A &&
3729 git mv z/ y/ &&
3730 echo different >y/c &&
3731 mkdir w &&
3732 git mv x/c w/ &&
3733 git add y/c &&
3734 test_tick &&
3735 git commit -m "A" &&
3736
3737 git checkout B &&
3738 git mv x/c z/ &&
3739 test_tick &&
3740 git commit -m "B"
3741 )
da1e295e 3742}
a7a43604 3743
da1e295e
EN
3744test_expect_success '11e: Avoid deleting not-uptodate with dir rename/rename(1to2)/add' '
3745 test_setup_11e &&
a7a43604
EN
3746 (
3747 cd 11e &&
3748
3749 git checkout A^0 &&
3750 echo mods >>y/c &&
3751
8c8e5bd6 3752 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
a7a43604
EN
3753 test_i18ngrep "CONFLICT (rename/rename)" out &&
3754 test_i18ngrep "Refusing to lose dirty file at y/c" out &&
3755
3756 git ls-files -s >out &&
3757 test_line_count = 7 out &&
3758 git ls-files -u >out &&
3759 test_line_count = 4 out &&
3760 git ls-files -o >out &&
48c9cb9d 3761 test_line_count = 3 out &&
a7a43604
EN
3762
3763 echo different >expected &&
3764 echo mods >>expected &&
3765 test_cmp expected y/c &&
3766
3767 git rev-parse >actual \
3768 :0:y/a :0:y/b :0:x/d :1:x/c :2:w/c :2:y/c :3:y/c &&
3769 git rev-parse >expect \
3770 O:z/a O:z/b O:x/d O:x/c O:x/c A:y/c O:x/c &&
3771 test_cmp expect actual &&
3772
48c9cb9d
EN
3773 # See if y/c~merged has expected contents; requires manually
3774 # doing the expected file merge
3775 git cat-file -p A:y/c >c1 &&
3776 git cat-file -p B:z/c >c2 &&
3777 >empty &&
3778 test_must_fail git merge-file \
3779 -L "HEAD" \
3780 -L "" \
3781 -L "B^0" \
3782 c1 empty c2 &&
3783 test_cmp c1 y/c~merged
a7a43604
EN
3784 )
3785'
3786
3787# Testcase 11f, Avoid deleting not-up-to-date w/ dir rename/rename(2to1)
3788# Commit O: z/{a,b}, x/{c_1,d_2}
3789# Commit A: y/{a,b,wham_1}, x/d_2, except y/wham has uncommitted mods
3790# Commit B: z/{a,b,wham_2}, x/c_1
bbafc9c4 3791# Expected: Failed Merge; y/{a,b} + untracked y/{wham~merged} +
a7a43604
EN
3792# y/wham with dirty changes from before merge +
3793# CONFLICT(rename/rename) x/c vs x/d -> y/wham
3794# ERROR_MSG(Refusing to lose dirty file at y/wham)
3795
da1e295e 3796test_setup_11f () {
a7a43604
EN
3797 test_create_repo 11f &&
3798 (
3799 cd 11f &&
3800
3801 mkdir z x &&
3802 echo a >z/a &&
3803 echo b >z/b &&
3804 test_seq 1 10 >x/c &&
3805 echo d >x/d &&
3806 git add z x &&
3807 test_tick &&
3808 git commit -m "O" &&
3809
3810 git branch O &&
3811 git branch A &&
3812 git branch B &&
3813
3814 git checkout A &&
3815 git mv z/ y/ &&
3816 git mv x/c y/wham &&
3817 test_tick &&
3818 git commit -m "A" &&
3819
3820 git checkout B &&
3821 git mv x/d z/wham &&
3822 test_tick &&
3823 git commit -m "B"
3824 )
da1e295e 3825}
a7a43604 3826
da1e295e
EN
3827test_expect_success '11f: Avoid deleting not-uptodate with dir rename/rename(2to1)' '
3828 test_setup_11f &&
a7a43604
EN
3829 (
3830 cd 11f &&
3831
3832 git checkout A^0 &&
3833 echo important >>y/wham &&
3834
8c8e5bd6 3835 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
a7a43604
EN
3836 test_i18ngrep "CONFLICT (rename/rename)" out &&
3837 test_i18ngrep "Refusing to lose dirty file at y/wham" out &&
3838
3839 git ls-files -s >out &&
3840 test_line_count = 4 out &&
3841 git ls-files -u >out &&
3842 test_line_count = 2 out &&
3843 git ls-files -o >out &&
bbafc9c4 3844 test_line_count = 3 out &&
a7a43604
EN
3845
3846 test_seq 1 10 >expected &&
3847 echo important >>expected &&
3848 test_cmp expected y/wham &&
3849
3850 test_must_fail git rev-parse :1:y/wham &&
a7a43604
EN
3851
3852 git rev-parse >actual \
3853 :0:y/a :0:y/b :2:y/wham :3:y/wham &&
3854 git rev-parse >expect \
3855 O:z/a O:z/b O:x/c O:x/d &&
bbafc9c4
EN
3856 test_cmp expect actual &&
3857
3858 # Test that the two-way merge in y/wham~merged is as expected
3859 git cat-file -p :2:y/wham >expect &&
3860 git cat-file -p :3:y/wham >other &&
3861 >empty &&
3862 test_must_fail git merge-file \
3863 -L "HEAD" \
3864 -L "" \
3865 -L "B^0" \
3866 expect empty other &&
3867 test_cmp expect y/wham~merged
a7a43604
EN
3868 )
3869'
3870
bc71c4ee
EN
3871###########################################################################
3872# SECTION 12: Everything else
3873#
3874# Tests suggested by others. Tests added after implementation completed
3875# and submitted. Grab bag.
3876###########################################################################
3877
3878# Testcase 12a, Moving one directory hierarchy into another
3879# (Related to testcase 9a)
3880# Commit O: node1/{leaf1,leaf2}, node2/{leaf3,leaf4}
3881# Commit A: node1/{leaf1,leaf2,node2/{leaf3,leaf4}}
3882# Commit B: node1/{leaf1,leaf2,leaf5}, node2/{leaf3,leaf4,leaf6}
3883# Expected: node1/{leaf1,leaf2,leaf5,node2/{leaf3,leaf4,leaf6}}
3884
da1e295e 3885test_setup_12a () {
bc71c4ee
EN
3886 test_create_repo 12a &&
3887 (
3888 cd 12a &&
3889
3890 mkdir -p node1 node2 &&
3891 echo leaf1 >node1/leaf1 &&
3892 echo leaf2 >node1/leaf2 &&
3893 echo leaf3 >node2/leaf3 &&
3894 echo leaf4 >node2/leaf4 &&
3895 git add node1 node2 &&
3896 test_tick &&
3897 git commit -m "O" &&
3898
3899 git branch O &&
3900 git branch A &&
3901 git branch B &&
3902
3903 git checkout A &&
3904 git mv node2/ node1/ &&
3905 test_tick &&
3906 git commit -m "A" &&
3907
3908 git checkout B &&
3909 echo leaf5 >node1/leaf5 &&
3910 echo leaf6 >node2/leaf6 &&
3911 git add node1 node2 &&
3912 test_tick &&
3913 git commit -m "B"
3914 )
da1e295e 3915}
bc71c4ee 3916
da1e295e
EN
3917test_expect_success '12a: Moving one directory hierarchy into another' '
3918 test_setup_12a &&
bc71c4ee
EN
3919 (
3920 cd 12a &&
3921
3922 git checkout A^0 &&
3923
8c8e5bd6 3924 git -c merge.directoryRenames=true merge -s recursive B^0 &&
bc71c4ee
EN
3925
3926 git ls-files -s >out &&
3927 test_line_count = 6 out &&
3928
3929 git rev-parse >actual \
3930 HEAD:node1/leaf1 HEAD:node1/leaf2 HEAD:node1/leaf5 \
3931 HEAD:node1/node2/leaf3 \
3932 HEAD:node1/node2/leaf4 \
3933 HEAD:node1/node2/leaf6 &&
3934 git rev-parse >expect \
3935 O:node1/leaf1 O:node1/leaf2 B:node1/leaf5 \
3936 O:node2/leaf3 \
3937 O:node2/leaf4 \
3938 B:node2/leaf6 &&
3939 test_cmp expect actual
3940 )
3941'
3942
3943# Testcase 12b, Moving two directory hierarchies into each other
3944# (Related to testcases 1c and 12c)
3945# Commit O: node1/{leaf1, leaf2}, node2/{leaf3, leaf4}
3946# Commit A: node1/{leaf1, leaf2, node2/{leaf3, leaf4}}
3947# Commit B: node2/{leaf3, leaf4, node1/{leaf1, leaf2}}
3948# Expected: node1/node2/node1/{leaf1, leaf2},
3949# node2/node1/node2/{leaf3, leaf4}
3950# NOTE: Without directory renames, we would expect
3951# node2/node1/{leaf1, leaf2},
3952# node1/node2/{leaf3, leaf4}
3953# with directory rename detection, we note that
3954# commit A renames node2/ -> node1/node2/
3955# commit B renames node1/ -> node2/node1/
3956# therefore, applying those directory renames to the initial result
3957# (making all four paths experience a transitive renaming), yields
3958# the expected result.
3959#
3960# You may ask, is it weird to have two directories rename each other?
3961# To which, I can do no more than shrug my shoulders and say that
3962# even simple rules give weird results when given weird inputs.
3963
da1e295e 3964test_setup_12b () {
bc71c4ee
EN
3965 test_create_repo 12b &&
3966 (
3967 cd 12b &&
3968
3969 mkdir -p node1 node2 &&
3970 echo leaf1 >node1/leaf1 &&
3971 echo leaf2 >node1/leaf2 &&
3972 echo leaf3 >node2/leaf3 &&
3973 echo leaf4 >node2/leaf4 &&
3974 git add node1 node2 &&
3975 test_tick &&
3976 git commit -m "O" &&
3977
3978 git branch O &&
3979 git branch A &&
3980 git branch B &&
3981
3982 git checkout A &&
3983 git mv node2/ node1/ &&
3984 test_tick &&
3985 git commit -m "A" &&
3986
3987 git checkout B &&
3988 git mv node1/ node2/ &&
3989 test_tick &&
3990 git commit -m "B"
3991 )
da1e295e 3992}
bc71c4ee 3993
da1e295e
EN
3994test_expect_success '12b: Moving two directory hierarchies into each other' '
3995 test_setup_12b &&
bc71c4ee
EN
3996 (
3997 cd 12b &&
3998
3999 git checkout A^0 &&
4000
8c8e5bd6 4001 git -c merge.directoryRenames=true merge -s recursive B^0 &&
bc71c4ee
EN
4002
4003 git ls-files -s >out &&
4004 test_line_count = 4 out &&
4005
4006 git rev-parse >actual \
4007 HEAD:node1/node2/node1/leaf1 \
4008 HEAD:node1/node2/node1/leaf2 \
4009 HEAD:node2/node1/node2/leaf3 \
4010 HEAD:node2/node1/node2/leaf4 &&
4011 git rev-parse >expect \
4012 O:node1/leaf1 \
4013 O:node1/leaf2 \
4014 O:node2/leaf3 \
4015 O:node2/leaf4 &&
4016 test_cmp expect actual
4017 )
4018'
4019
4020# Testcase 12c, Moving two directory hierarchies into each other w/ content merge
4021# (Related to testcase 12b)
4022# Commit O: node1/{ leaf1_1, leaf2_1}, node2/{leaf3_1, leaf4_1}
4023# Commit A: node1/{ leaf1_2, leaf2_2, node2/{leaf3_2, leaf4_2}}
4024# Commit B: node2/{node1/{leaf1_3, leaf2_3}, leaf3_3, leaf4_3}
4025# Expected: Content merge conflicts for each of:
4026# node1/node2/node1/{leaf1, leaf2},
4027# node2/node1/node2/{leaf3, leaf4}
4028# NOTE: This is *exactly* like 12c, except that every path is modified on
4029# each side of the merge.
4030
da1e295e 4031test_setup_12c () {
bc71c4ee
EN
4032 test_create_repo 12c &&
4033 (
4034 cd 12c &&
4035
4036 mkdir -p node1 node2 &&
4037 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf1\n" >node1/leaf1 &&
4038 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf2\n" >node1/leaf2 &&
4039 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf3\n" >node2/leaf3 &&
4040 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf4\n" >node2/leaf4 &&
4041 git add node1 node2 &&
4042 test_tick &&
4043 git commit -m "O" &&
4044
4045 git branch O &&
4046 git branch A &&
4047 git branch B &&
4048
4049 git checkout A &&
4050 git mv node2/ node1/ &&
4051 for i in `git ls-files`; do echo side A >>$i; done &&
4052 git add -u &&
4053 test_tick &&
4054 git commit -m "A" &&
4055
4056 git checkout B &&
4057 git mv node1/ node2/ &&
4058 for i in `git ls-files`; do echo side B >>$i; done &&
4059 git add -u &&
4060 test_tick &&
4061 git commit -m "B"
4062 )
da1e295e 4063}
bc71c4ee 4064
da1e295e
EN
4065test_expect_success '12c: Moving one directory hierarchy into another w/ content merge' '
4066 test_setup_12c &&
bc71c4ee
EN
4067 (
4068 cd 12c &&
4069
4070 git checkout A^0 &&
4071
8c8e5bd6 4072 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 &&
bc71c4ee
EN
4073
4074 git ls-files -u >out &&
4075 test_line_count = 12 out &&
4076
4077 git rev-parse >actual \
4078 :1:node1/node2/node1/leaf1 \
4079 :1:node1/node2/node1/leaf2 \
4080 :1:node2/node1/node2/leaf3 \
4081 :1:node2/node1/node2/leaf4 \
4082 :2:node1/node2/node1/leaf1 \
4083 :2:node1/node2/node1/leaf2 \
4084 :2:node2/node1/node2/leaf3 \
4085 :2:node2/node1/node2/leaf4 \
4086 :3:node1/node2/node1/leaf1 \
4087 :3:node1/node2/node1/leaf2 \
4088 :3:node2/node1/node2/leaf3 \
4089 :3:node2/node1/node2/leaf4 &&
4090 git rev-parse >expect \
4091 O:node1/leaf1 \
4092 O:node1/leaf2 \
4093 O:node2/leaf3 \
4094 O:node2/leaf4 \
4095 A:node1/leaf1 \
4096 A:node1/leaf2 \
4097 A:node1/node2/leaf3 \
4098 A:node1/node2/leaf4 \
4099 B:node2/node1/leaf1 \
4100 B:node2/node1/leaf2 \
4101 B:node2/leaf3 \
4102 B:node2/leaf4 &&
4103 test_cmp expect actual
4104 )
4105'
4106
49b8133a
EN
4107# Testcase 12d, Rename/merge of subdirectory into the root
4108# Commit O: a/b/subdir/foo
4109# Commit A: subdir/foo
4110# Commit B: a/b/subdir/foo, a/b/bar
4111# Expected: subdir/foo, bar
4112
da1e295e 4113test_setup_12d () {
49b8133a
EN
4114 test_create_repo 12d &&
4115 (
4116 cd 12d &&
4117
4118 mkdir -p a/b/subdir &&
4119 test_commit a/b/subdir/foo &&
4120
4121 git branch O &&
4122 git branch A &&
4123 git branch B &&
4124
4125 git checkout A &&
4126 mkdir subdir &&
4127 git mv a/b/subdir/foo.t subdir/foo.t &&
4128 test_tick &&
4129 git commit -m "A" &&
4130
4131 git checkout B &&
4132 test_commit a/b/bar
4133 )
da1e295e 4134}
49b8133a 4135
da1e295e
EN
4136test_expect_success '12d: Rename/merge subdir into the root, variant 1' '
4137 test_setup_12d &&
49b8133a
EN
4138 (
4139 cd 12d &&
4140
4141 git checkout A^0 &&
4142
4143 git -c merge.directoryRenames=true merge -s recursive B^0 &&
4144
4145 git ls-files -s >out &&
4146 test_line_count = 2 out &&
4147
4148 git rev-parse >actual \
4149 HEAD:subdir/foo.t HEAD:bar.t &&
4150 git rev-parse >expect \
4151 O:a/b/subdir/foo.t B:a/b/bar.t &&
4152 test_cmp expect actual &&
4153
4154 git hash-object bar.t >actual &&
4155 git rev-parse B:a/b/bar.t >expect &&
4156 test_cmp expect actual &&
4157
4158 test_must_fail git rev-parse HEAD:a/b/subdir/foo.t &&
4159 test_must_fail git rev-parse HEAD:a/b/bar.t &&
4160 test_path_is_missing a/ &&
4161 test_path_is_file bar.t
4162 )
4163'
4164
4165# Testcase 12e, Rename/merge of subdirectory into the root
4166# Commit O: a/b/foo
4167# Commit A: foo
4168# Commit B: a/b/foo, a/b/bar
4169# Expected: foo, bar
4170
da1e295e 4171test_setup_12e () {
49b8133a
EN
4172 test_create_repo 12e &&
4173 (
4174 cd 12e &&
4175
4176 mkdir -p a/b &&
4177 test_commit a/b/foo &&
4178
4179 git branch O &&
4180 git branch A &&
4181 git branch B &&
4182
4183 git checkout A &&
4184 mkdir subdir &&
4185 git mv a/b/foo.t foo.t &&
4186 test_tick &&
4187 git commit -m "A" &&
4188
4189 git checkout B &&
4190 test_commit a/b/bar
4191 )
da1e295e 4192}
49b8133a 4193
da1e295e
EN
4194test_expect_success '12e: Rename/merge subdir into the root, variant 2' '
4195 test_setup_12e &&
49b8133a
EN
4196 (
4197 cd 12e &&
4198
4199 git checkout A^0 &&
4200
4201 git -c merge.directoryRenames=true merge -s recursive B^0 &&
4202
4203 git ls-files -s >out &&
4204 test_line_count = 2 out &&
4205
4206 git rev-parse >actual \
4207 HEAD:foo.t HEAD:bar.t &&
4208 git rev-parse >expect \
4209 O:a/b/foo.t B:a/b/bar.t &&
4210 test_cmp expect actual &&
4211
4212 git hash-object bar.t >actual &&
4213 git rev-parse B:a/b/bar.t >expect &&
4214 test_cmp expect actual &&
4215
4216 test_must_fail git rev-parse HEAD:a/b/foo.t &&
4217 test_must_fail git rev-parse HEAD:a/b/bar.t &&
4218 test_path_is_missing a/ &&
4219 test_path_is_file bar.t
4220 )
4221'
4222
8c8e5bd6
EN
4223###########################################################################
4224# SECTION 13: Checking informational and conflict messages
4225#
4226# A year after directory rename detection became the default, it was
4227# instead decided to report conflicts on the pathname on the basis that
4228# some users may expect the new files added or moved into a directory to
4229# be unrelated to all the other files in that directory, and thus that
4230# directory rename detection is unexpected. Test that the messages printed
4231# match our expectation.
4232###########################################################################
4233
4234# Testcase 13a, Basic directory rename with newly added files
4235# Commit O: z/{b,c}
4236# Commit A: y/{b,c}
4237# Commit B: z/{b,c,d,e/f}
4238# Expected: y/{b,c,d,e/f}, with notices/conflicts for both y/d and y/e/f
4239
da1e295e
EN
4240test_setup_13a () {
4241 test_create_repo 13a_$1 &&
8c8e5bd6 4242 (
da1e295e 4243 cd 13a_$1 &&
8c8e5bd6
EN
4244
4245 mkdir z &&
4246 echo b >z/b &&
4247 echo c >z/c &&
4248 git add z &&
4249 test_tick &&
4250 git commit -m "O" &&
4251
4252 git branch O &&
4253 git branch A &&
4254 git branch B &&
4255
4256 git checkout A &&
4257 git mv z y &&
4258 test_tick &&
4259 git commit -m "A" &&
4260
4261 git checkout B &&
4262 echo d >z/d &&
4263 mkdir z/e &&
4264 echo f >z/e/f &&
4265 git add z/d z/e/f &&
4266 test_tick &&
4267 git commit -m "B"
4268 )
da1e295e 4269}
8c8e5bd6 4270
da1e295e
EN
4271test_expect_success '13a(conflict): messages for newly added files' '
4272 test_setup_13a conflict &&
8c8e5bd6 4273 (
da1e295e 4274 cd 13a_conflict &&
8c8e5bd6
EN
4275
4276 git checkout A^0 &&
4277
4278 test_must_fail git merge -s recursive B^0 >out 2>err &&
4279
4280 test_i18ngrep CONFLICT..file.location.*z/e/f.added.in.B^0.*y/e/f out &&
4281 test_i18ngrep CONFLICT..file.location.*z/d.added.in.B^0.*y/d out &&
4282
4283 git ls-files >paths &&
4284 ! grep z/ paths &&
4285 grep "y/[de]" paths &&
4286
4287 test_path_is_missing z/d &&
4288 test_path_is_file y/d &&
4289 test_path_is_missing z/e/f &&
4290 test_path_is_file y/e/f
4291 )
4292'
4293
da1e295e
EN
4294test_expect_success '13a(info): messages for newly added files' '
4295 test_setup_13a info &&
8c8e5bd6 4296 (
da1e295e 4297 cd 13a_info &&
8c8e5bd6
EN
4298
4299 git reset --hard &&
4300 git checkout A^0 &&
4301
4302 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
4303
4304 test_i18ngrep Path.updated:.*z/e/f.added.in.B^0.*y/e/f out &&
4305 test_i18ngrep Path.updated:.*z/d.added.in.B^0.*y/d out &&
4306
4307 git ls-files >paths &&
4308 ! grep z/ paths &&
4309 grep "y/[de]" paths &&
4310
4311 test_path_is_missing z/d &&
4312 test_path_is_file y/d &&
4313 test_path_is_missing z/e/f &&
4314 test_path_is_file y/e/f
4315 )
4316'
4317
4318# Testcase 13b, Transitive rename with conflicted content merge and default
4319# "conflict" setting
4320# (Related to testcase 1c, 9b)
4321# Commit O: z/{b,c}, x/d_1
4322# Commit A: y/{b,c}, x/d_2
4323# Commit B: z/{b,c,d_3}
4324# Expected: y/{b,c,d_merged}, with two conflict messages for y/d,
4325# one about content, and one about file location
4326
da1e295e
EN
4327test_setup_13b () {
4328 test_create_repo 13b_$1 &&
8c8e5bd6 4329 (
da1e295e 4330 cd 13b_$1 &&
8c8e5bd6
EN
4331
4332 mkdir x &&
4333 mkdir z &&
4334 test_seq 1 10 >x/d &&
4335 echo b >z/b &&
4336 echo c >z/c &&
4337 git add x z &&
4338 test_tick &&
4339 git commit -m "O" &&
4340
4341 git branch O &&
4342 git branch A &&
4343 git branch B &&
4344
4345 git checkout A &&
4346 git mv z y &&
4347 echo 11 >>x/d &&
4348 git add x/d &&
4349 test_tick &&
4350 git commit -m "A" &&
4351
4352 git checkout B &&
4353 echo eleven >>x/d &&
4354 git mv x/d z/d &&
4355 git add z/d &&
4356 test_tick &&
4357 git commit -m "B"
4358 )
da1e295e 4359}
8c8e5bd6 4360
da1e295e
EN
4361test_expect_success '13b(conflict): messages for transitive rename with conflicted content' '
4362 test_setup_13b conflict &&
8c8e5bd6 4363 (
da1e295e 4364 cd 13b_conflict &&
8c8e5bd6
EN
4365
4366 git checkout A^0 &&
4367
4368 test_must_fail git merge -s recursive B^0 >out 2>err &&
4369
4370 test_i18ngrep CONFLICT.*content.*Merge.conflict.in.y/d out &&
4371 test_i18ngrep CONFLICT..file.location.*x/d.renamed.to.z/d.*moved.to.y/d out &&
4372
4373 git ls-files >paths &&
4374 ! grep z/ paths &&
4375 grep "y/d" paths &&
4376
4377 test_path_is_missing z/d &&
4378 test_path_is_file y/d
4379 )
4380'
4381
da1e295e
EN
4382test_expect_success '13b(info): messages for transitive rename with conflicted content' '
4383 test_setup_13b info &&
8c8e5bd6 4384 (
da1e295e 4385 cd 13b_info &&
8c8e5bd6
EN
4386
4387 git reset --hard &&
4388 git checkout A^0 &&
4389
4390 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
4391
4392 test_i18ngrep CONFLICT.*content.*Merge.conflict.in.y/d out &&
4393 test_i18ngrep Path.updated:.*x/d.renamed.to.z/d.in.B^0.*moving.it.to.y/d out &&
4394
4395 git ls-files >paths &&
4396 ! grep z/ paths &&
4397 grep "y/d" paths &&
4398
4399 test_path_is_missing z/d &&
4400 test_path_is_file y/d
4401 )
4402'
4403
4404# Testcase 13c, Rename/rename(1to1) due to directory rename
4405# Commit O: z/{b,c}, x/{d,e}
4406# Commit A: y/{b,c,d}, x/e
4407# Commit B: z/{b,c,d}, x/e
4408# Expected: y/{b,c,d}, with info or conflict messages for d (
4409# A: renamed x/d -> z/d; B: renamed z/ -> y/ AND renamed x/d to y/d
4410# One could argue A had partial knowledge of what was done with
4411# d and B had full knowledge, but that's a slippery slope as
4412# shown in testcase 13d.
4413
da1e295e
EN
4414test_setup_13c () {
4415 test_create_repo 13c_$1 &&
8c8e5bd6 4416 (
da1e295e 4417 cd 13c_$1 &&
8c8e5bd6
EN
4418
4419 mkdir x &&
4420 mkdir z &&
4421 test_seq 1 10 >x/d &&
4422 echo e >x/e &&
4423 echo b >z/b &&
4424 echo c >z/c &&
4425 git add x z &&
4426 test_tick &&
4427 git commit -m "O" &&
4428
4429 git branch O &&
4430 git branch A &&
4431 git branch B &&
4432
4433 git checkout A &&
4434 git mv z y &&
4435 git mv x/d y/ &&
4436 test_tick &&
4437 git commit -m "A" &&
4438
4439 git checkout B &&
4440 git mv x/d z/d &&
4441 git add z/d &&
4442 test_tick &&
4443 git commit -m "B"
4444 )
da1e295e 4445}
8c8e5bd6 4446
da1e295e
EN
4447test_expect_success '13c(conflict): messages for rename/rename(1to1) via transitive rename' '
4448 test_setup_13c conflict &&
8c8e5bd6 4449 (
da1e295e 4450 cd 13c_conflict &&
8c8e5bd6
EN
4451
4452 git checkout A^0 &&
4453
4454 test_must_fail git merge -s recursive B^0 >out 2>err &&
4455
4456 test_i18ngrep CONFLICT..file.location.*x/d.renamed.to.z/d.*moved.to.y/d out &&
4457
4458 git ls-files >paths &&
4459 ! grep z/ paths &&
4460 grep "y/d" paths &&
4461
4462 test_path_is_missing z/d &&
4463 test_path_is_file y/d
4464 )
4465'
4466
da1e295e
EN
4467test_expect_success '13c(info): messages for rename/rename(1to1) via transitive rename' '
4468 test_setup_13c info &&
8c8e5bd6 4469 (
da1e295e 4470 cd 13c_info &&
8c8e5bd6
EN
4471
4472 git reset --hard &&
4473 git checkout A^0 &&
4474
4475 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
4476
4477 test_i18ngrep Path.updated:.*x/d.renamed.to.z/d.in.B^0.*moving.it.to.y/d out &&
4478
4479 git ls-files >paths &&
4480 ! grep z/ paths &&
4481 grep "y/d" paths &&
4482
4483 test_path_is_missing z/d &&
4484 test_path_is_file y/d
4485 )
4486'
4487
4488# Testcase 13d, Rename/rename(1to1) due to directory rename on both sides
4489# Commit O: a/{z,y}, b/x, c/w
4490# Commit A: a/z, b/{y,x}, d/w
4491# Commit B: a/z, d/x, c/{y,w}
4492# Expected: a/z, d/{y,x,w} with no file location conflict for x
4493# Easy cases:
4494# * z is always in a; so it stays in a.
4495# * x starts in b, only modified on one side to move into d/
4496# * w starts in c, only modified on one side to move into d/
4497# Hard case:
4498# * A renames a/y to b/y, and B renames b/->d/ => a/y -> d/y
4499# * B renames a/y to c/y, and A renames c/->d/ => a/y -> d/y
4500# No conflict in where a/y ends up, so put it in d/y.
4501
da1e295e
EN
4502test_setup_13d () {
4503 test_create_repo 13d_$1 &&
8c8e5bd6 4504 (
da1e295e 4505 cd 13d_$1 &&
8c8e5bd6
EN
4506
4507 mkdir a &&
4508 mkdir b &&
4509 mkdir c &&
4510 echo z >a/z &&
4511 echo y >a/y &&
4512 echo x >b/x &&
4513 echo w >c/w &&
4514 git add a b c &&
4515 test_tick &&
4516 git commit -m "O" &&
4517
4518 git branch O &&
4519 git branch A &&
4520 git branch B &&
4521
4522 git checkout A &&
4523 git mv a/y b/ &&
4524 git mv c/ d/ &&
4525 test_tick &&
4526 git commit -m "A" &&
4527
4528 git checkout B &&
4529 git mv a/y c/ &&
4530 git mv b/ d/ &&
4531 test_tick &&
4532 git commit -m "B"
4533 )
da1e295e 4534}
8c8e5bd6 4535
da1e295e
EN
4536test_expect_success '13d(conflict): messages for rename/rename(1to1) via dual transitive rename' '
4537 test_setup_13d conflict &&
8c8e5bd6 4538 (
da1e295e 4539 cd 13d_conflict &&
8c8e5bd6
EN
4540
4541 git checkout A^0 &&
4542
4543 test_must_fail git merge -s recursive B^0 >out 2>err &&
4544
4545 test_i18ngrep CONFLICT..file.location.*a/y.renamed.to.b/y.*moved.to.d/y out &&
4546 test_i18ngrep CONFLICT..file.location.*a/y.renamed.to.c/y.*moved.to.d/y out &&
4547
4548 git ls-files >paths &&
4549 ! grep b/ paths &&
4550 ! grep c/ paths &&
4551 grep "d/y" paths &&
4552
4553 test_path_is_missing b/y &&
4554 test_path_is_missing c/y &&
4555 test_path_is_file d/y
4556 )
4557'
4558
da1e295e
EN
4559test_expect_success '13d(info): messages for rename/rename(1to1) via dual transitive rename' '
4560 test_setup_13d info &&
8c8e5bd6 4561 (
da1e295e 4562 cd 13d_info &&
8c8e5bd6
EN
4563
4564 git reset --hard &&
4565 git checkout A^0 &&
4566
4567 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
4568
4569 test_i18ngrep Path.updated.*a/y.renamed.to.b/y.*moving.it.to.d/y out &&
4570 test_i18ngrep Path.updated.*a/y.renamed.to.c/y.*moving.it.to.d/y out &&
4571
4572 git ls-files >paths &&
4573 ! grep b/ paths &&
4574 ! grep c/ paths &&
4575 grep "d/y" paths &&
4576
4577 test_path_is_missing b/y &&
4578 test_path_is_missing c/y &&
4579 test_path_is_file d/y
4580 )
4581'
4582
ff6d5477
EN
4583# Testcase 13e, directory rename in virtual merge base
4584#
4585# This testcase has a slightly different setup than all the above cases, in
4586# order to include a recursive case:
4587#
4588# A C
4589# o - o
4590# / \ / \
4591# O o X ?
4592# \ / \ /
4593# o o
4594# B D
4595#
4596# Commit O: a/{z,y}
4597# Commit A: b/{z,y}
4598# Commit B: a/{z,y,x}
4599# Commit C: b/{z,y,x}
4600# Commit D: b/{z,y}, a/x
4601# Expected: b/{z,y,x} (sort of; see below for why this might not be expected)
4602#
4603# NOTES: 'X' represents a virtual merge base. With the default of
4604# directory rename detection yielding conflicts, merging A and B
4605# results in a conflict complaining about whether 'x' should be
4606# under 'a/' or 'b/'. However, when creating the virtual merge
4607# base 'X', since virtual merge bases need to be written out as a
4608# tree, we cannot have a conflict, so some resolution has to be
4609# picked.
4610#
4611# In choosing the right resolution, it's worth noting here that
4612# commits C & D are merges of A & B that choose different
4613# locations for 'x' (i.e. they resolve the conflict differently),
4614# and so it would be nice when merging C & D if git could detect
4615# this difference of opinion and report a conflict. But the only
4616# way to do so that I can think of would be to have the virtual
4617# merge base place 'x' in some directory other than either 'a/' or
4618# 'b/', which seems a little weird -- especially since it'd result
4619# in a rename/rename(1to2) conflict with a source path that never
4620# existed in any version.
4621#
4622# So, for now, when directory rename detection is set to
4623# 'conflict' just avoid doing directory rename detection at all in
4624# the recursive case. This will not allow us to detect a conflict
4625# in the outer merge for this special kind of setup, but it at
4626# least avoids hitting a BUG().
4627#
da1e295e 4628test_setup_13e () {
ff6d5477
EN
4629 test_create_repo 13e &&
4630 (
4631 cd 13e &&
4632
4633 mkdir a &&
4634 echo z >a/z &&
4635 echo y >a/y &&
4636 git add a &&
4637 test_tick &&
4638 git commit -m "O" &&
4639
4640 git branch O &&
4641 git branch A &&
4642 git branch B &&
4643
4644 git checkout A &&
4645 git mv a/ b/ &&
4646 test_tick &&
4647 git commit -m "A" &&
4648
4649 git checkout B &&
4650 echo x >a/x &&
4651 git add a &&
4652 test_tick &&
4653 git commit -m "B" &&
4654
4655 git branch C A &&
4656 git branch D B &&
4657
4658 git checkout C &&
4659 test_must_fail git -c merge.directoryRenames=conflict merge B &&
4660 git add b/x &&
4661 test_tick &&
4662 git commit -m "C" &&
4663
4664
4665 git checkout D &&
4666 test_must_fail git -c merge.directoryRenames=conflict merge A &&
4667 git add b/x &&
4668 mkdir a &&
4669 git mv b/x a/x &&
4670 test_tick &&
4671 git commit -m "D"
4672 )
da1e295e 4673}
ff6d5477 4674
da1e295e
EN
4675test_expect_success '13e: directory rename detection in recursive case' '
4676 test_setup_13e &&
ff6d5477
EN
4677 (
4678 cd 13e &&
4679
4680 git checkout --quiet D^0 &&
4681
4682 git -c merge.directoryRenames=conflict merge -s recursive C^0 >out 2>err &&
4683
4684 test_i18ngrep ! CONFLICT out &&
4685 test_i18ngrep ! BUG: err &&
4686 test_i18ngrep ! core.dumped err &&
4687 test_must_be_empty err &&
4688
4689 git ls-files >paths &&
4690 ! grep a/x paths &&
4691 grep b/x paths
4692 )
4693'
4694
04550ab5 4695test_done