File: merge_reintegrate_tests.py

package info (click to toggle)
subversion 1.8.10-6%2Bdeb8u6
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 62,080 kB
  • sloc: ansic: 795,684; python: 115,859; java: 17,742; sh: 13,590; ruby: 12,397; cpp: 11,206; lisp: 7,540; perl: 5,649; sql: 1,466; makefile: 1,110; xml: 577
file content (2819 lines) | stat: -rwxr-xr-x 122,708 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
#!/usr/bin/env python
#
#  merge_reintegrate_tests.py:  testing merge --reintegrate
#
#  Subversion is a tool for revision control.
#  See http://subversion.apache.org for more information.
#
# ====================================================================
#    Licensed to the Apache Software Foundation (ASF) under one
#    or more contributor license agreements.  See the NOTICE file
#    distributed with this work for additional information
#    regarding copyright ownership.  The ASF licenses this file
#    to you under the Apache License, Version 2.0 (the
#    "License"); you may not use this file except in compliance
#    with the License.  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing,
#    software distributed under the License is distributed on an
#    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
#    KIND, either express or implied.  See the License for the
#    specific language governing permissions and limitations
#    under the License.
######################################################################

# General modules
import shutil, sys, re, os
import time

# Our testing module
import svntest
from svntest import main, wc, verify, actions

# (abbreviation)
Item = wc.StateItem
Skip = svntest.testcase.Skip_deco
SkipUnless = svntest.testcase.SkipUnless_deco
XFail = svntest.testcase.XFail_deco
Issues = svntest.testcase.Issues_deco
Issue = svntest.testcase.Issue_deco
Wimp = svntest.testcase.Wimp_deco
exp_noop_up_out = svntest.actions.expected_noop_update_output

from svntest.main import SVN_PROP_MERGEINFO
from svntest.main import server_has_mergeinfo
from merge_tests import set_up_branch
from merge_tests import expected_merge_output

#----------------------------------------------------------------------
def run_reintegrate(src_url, tgt_path):
  """Run 'svn merge --reintegrate SRC_URL TGT_PATH'. Raise an error if
     there is nothing on stdout, anything on stderr, or a non-zero exit
     code.
  """
  svntest.actions.run_and_verify_svn(None, svntest.verify.AnyOutput, [],
                                     'merge', '--reintegrate',
                                     src_url, tgt_path)

def run_reintegrate_expect_error(src_url, tgt_path,
                                 expected_stdout, expected_stderr):
  """Run 'svn merge --reintegrate SRC_URL TGT_PATH'. Raise an error
     unless stdout and stderr both match and the exit code is non-zero.
     Every line of stderr must match the regex EXPECTED_STDERR.
  """
  expected_stderr += "|" + svntest.main.stack_trace_regexp

  # The actions.run_and_verify_* methods are happy if one line of the error
  # matches the regex, but we want to check that every line matches.
  # So we will pass the stderr to svntest.verify.verify_outputs()
  # ourselves, but as the 'actual_stdout' argument, that way each line of
  # error must match the regex.
  exit_code, out, err = svntest.actions.run_and_verify_svn(
                          None, expected_stdout, svntest.verify.AnyOutput,
                          'merge', '--reintegrate',
                          src_url, tgt_path)
  assert exit_code
  svntest.verify.verify_outputs(
                   "Reintegrate failed but not in the way expected",
                   err, None,
                   expected_stderr, None,
                   True) # Match *all* lines

def run_and_verify_reintegrate(tgt_dir, src_url,
                               output_tree,
                               mergeinfo_output_tree,
                               elision_output_tree,
                               disk_tree, status_tree, skip_tree,
                               error_re_string = None,
                               check_props = True,
                               dry_run = True):
  """Run 'svn merge --reintegrate SRC_URL TGT_DIR'. Raise an error if
     there is nothing on stdout, anything on stderr, or a non-zero exit
     code, or if the expected ERROR_RE_STRING or any of the given expected
     trees don't match.
  """
  svntest.actions.run_and_verify_merge(
                    tgt_dir, None, None, src_url, None,
                    output_tree, mergeinfo_output_tree, elision_output_tree,
                    disk_tree, status_tree, skip_tree,
                    error_re_string,
                    None, None, None, None, check_props, dry_run,
                    '--reintegrate', tgt_dir)


#----------------------------------------------------------------------
@SkipUnless(server_has_mergeinfo)
@Issue(3640)
def basic_reintegrate(sbox):
  "basic merge --reintegrate support"

  # Also includes test for issue #3640 'moved target breaks reintegrate merge'

  # Make A_COPY branch in r2, and do a few more commits to A in r3-6.
  sbox.build()
  wc_dir = sbox.wc_dir
  expected_disk, expected_status = set_up_branch(sbox)

  # Make a change on the branch, to A/mu.  Commit in r7.
  svntest.main.file_write(sbox.ospath('A_COPY/mu'),
                          "Changed on the branch.")
  expected_output = wc.State(wc_dir, {'A_COPY/mu' : Item(verb='Sending')})
  expected_status.tweak('A_COPY/mu', wc_rev=7)
  svntest.actions.run_and_verify_commit(wc_dir, expected_output,
                                        expected_status, None, wc_dir)
  expected_disk.tweak('A_COPY/mu', contents='Changed on the branch.')

  # Update the wcs.
  expected_output = wc.State(wc_dir, {})
  expected_status.tweak(wc_rev='7')
  svntest.actions.run_and_verify_update(wc_dir, expected_output,
                                        expected_disk, expected_status,
                                        None, None, None, None, None, True)

  # Merge from trunk to branch (ie, r3-6), using normal cherry-harvest.
  A_COPY_path = sbox.ospath('A_COPY')
  expected_output = wc.State(A_COPY_path, {
    'D/H/psi'   : Item(status='U '),
    'D/G/rho'   : Item(status='U '),
    'B/E/beta'  : Item(status='U '),
    'D/H/omega' : Item(status='U '),
    })
  expected_mergeinfo_output = wc.State(A_COPY_path, {
    '' : Item(status=' U'),
    })
  expected_elision_output = wc.State(A_COPY_path, {
    })
  k_expected_status = wc.State(A_COPY_path, {
    "B"         : Item(status='  ', wc_rev=7),
    "B/lambda"  : Item(status='  ', wc_rev=7),
    "B/E"       : Item(status='  ', wc_rev=7),
    "B/E/alpha" : Item(status='  ', wc_rev=7),
    "B/E/beta"  : Item(status='M ', wc_rev=7),
    "B/F"       : Item(status='  ', wc_rev=7),
    "mu"        : Item(status='  ', wc_rev=7),
    "C"         : Item(status='  ', wc_rev=7),
    "D"         : Item(status='  ', wc_rev=7),
    "D/gamma"   : Item(status='  ', wc_rev=7),
    "D/G"       : Item(status='  ', wc_rev=7),
    "D/G/pi"    : Item(status='  ', wc_rev=7),
    "D/G/rho"   : Item(status='M ', wc_rev=7),
    "D/G/tau"   : Item(status='  ', wc_rev=7),
    "D/H"       : Item(status='  ', wc_rev=7),
    "D/H/chi"   : Item(status='  ', wc_rev=7),
    "D/H/omega" : Item(status='M ', wc_rev=7),
    "D/H/psi"   : Item(status='M ', wc_rev=7),
    ""          : Item(status=' M', wc_rev=7),
  })
  k_expected_disk = wc.State('', {
    ''          : Item(props={SVN_PROP_MERGEINFO : '/A:2-7'}),
    'B'         : Item(),
    'B/lambda'  : Item("This is the file 'lambda'.\n"),
    'B/E'       : Item(),
    'B/E/alpha' : Item("This is the file 'alpha'.\n"),
    'B/E/beta'  : Item("New content"),
    'B/F'       : Item(),
    'mu'        : Item("Changed on the branch."),
    'C'         : Item(),
    'D'         : Item(),
    'D/gamma'   : Item("This is the file 'gamma'.\n"),
    'D/G'       : Item(),
    'D/G/pi'    : Item("This is the file 'pi'.\n"),
    'D/G/rho'   : Item("New content"),
    'D/G/tau'   : Item("This is the file 'tau'.\n"),
    'D/H'       : Item(),
    'D/H/chi'   : Item("This is the file 'chi'.\n"),
    'D/H/omega' : Item("New content"),
    'D/H/psi'   : Item("New content"),
  })
  expected_skip = wc.State(A_COPY_path, {})
  svntest.actions.run_and_verify_merge(A_COPY_path, None, None,
                                       sbox.repo_url + '/A', None,
                                       expected_output,
                                       expected_mergeinfo_output,
                                       expected_elision_output,
                                       k_expected_disk,
                                       k_expected_status,
                                       expected_skip,
                                       None, None, None, None,
                                       None, True)
  expected_disk.tweak('A_COPY', props={SVN_PROP_MERGEINFO: '/A:2-7'})
  expected_disk.tweak('A_COPY/B/E/beta', contents="New content")
  expected_disk.tweak('A_COPY/D/G/rho', contents="New content")
  expected_disk.tweak('A_COPY/D/H/omega', contents="New content")
  expected_disk.tweak('A_COPY/D/H/psi', contents="New content")

  # Commit the merge to branch (r8).
  expected_output = wc.State(wc_dir, {
    'A_COPY/D/H/psi'   : Item(verb='Sending'),
    'A_COPY/D/G/rho'   : Item(verb='Sending'),
    'A_COPY/B/E/beta'  : Item(verb='Sending'),
    'A_COPY/D/H/omega' : Item(verb='Sending'),
    'A_COPY'           : Item(verb='Sending'),
    })
  expected_status.tweak('A_COPY', 'A_COPY/D/H/psi', 'A_COPY/D/G/rho',
                        'A_COPY/B/E/beta', 'A_COPY/D/H/omega', wc_rev=8)
  svntest.actions.run_and_verify_commit(wc_dir, expected_output,
                                        expected_status, None, wc_dir)

  # Update the wcs again.
  expected_output = wc.State(wc_dir, {})
  expected_status.tweak(wc_rev='8')
  svntest.actions.run_and_verify_update(wc_dir, expected_output,
                                        expected_disk, expected_status,
                                        None, None, None, None, None, True)


  # *finally*, actually run merge --reintegrate in trunk with the
  # branch URL.  This should bring in the mu change and the tauprime
  # change.
  A_path = sbox.ospath('A')
  expected_output = wc.State(A_path, {
    'mu'           : Item(status='U '),
    })
  expected_mergeinfo_output = wc.State(A_path, {
    '' : Item(status=' U'),
    })
  expected_elision_output = wc.State(A_path, {
    })
  k_expected_status = wc.State(A_path, {
    "B"            : Item(status='  ', wc_rev=8),
    "B/lambda"     : Item(status='  ', wc_rev=8),
    "B/E"          : Item(status='  ', wc_rev=8),
    "B/E/alpha"    : Item(status='  ', wc_rev=8),
    "B/E/beta"     : Item(status='  ', wc_rev=8),
    "B/F"          : Item(status='  ', wc_rev=8),
    "mu"           : Item(status='M ', wc_rev=8),
    "C"            : Item(status='  ', wc_rev=8),
    "D"            : Item(status='  ', wc_rev=8),
    "D/gamma"      : Item(status='  ', wc_rev=8),
    "D/G"          : Item(status='  ', wc_rev=8),
    "D/G/pi"       : Item(status='  ', wc_rev=8),
    "D/G/rho"      : Item(status='  ', wc_rev=8),
    "D/G/tau"      : Item(status='  ', wc_rev=8),
    "D/H"          : Item(status='  ', wc_rev=8),
    "D/H/chi"      : Item(status='  ', wc_rev=8),
    "D/H/omega"    : Item(status='  ', wc_rev=8),
    "D/H/psi"      : Item(status='  ', wc_rev=8),
    ""             : Item(status=' M', wc_rev=8),
  })
  k_expected_disk.tweak('', props={SVN_PROP_MERGEINFO : '/A_COPY:2-8'})
  expected_skip = wc.State(A_path, {})
  run_and_verify_reintegrate(A_path,
                                       sbox.repo_url + '/A_COPY',
                                       expected_output,
                                       expected_mergeinfo_output,
                                       expected_elision_output,
                                       k_expected_disk,
                                       k_expected_status,
                                       expected_skip,
                                       None, True, True)

  # Test issue #3640:
  #
  # Revert the merge then move A to A_MOVED in r9.  Repeat the merge, but
  # targeting A_MOVED this time.  This should work with almost the same
  # results.  The only differences being the inclusion of r9 in the
  # mergeinfo and the A-->A_MOVED path difference.
  svntest.actions.run_and_verify_svn(None, None, [], 'revert', '-R', wc_dir)
  svntest.actions.run_and_verify_svn(None,
                                     ['\n', 'Committed revision 9.\n'],
                                     [], 'move',
                                     sbox.repo_url + '/A',
                                     sbox.repo_url + '/A_MOVED',
                                     '-m', 'Copy A to A_MOVED')
  svntest.actions.run_and_verify_svn(None, None, [], 'up', wc_dir)
  A_MOVED_path = sbox.ospath('A_MOVED')
  expected_output = wc.State(A_MOVED_path, {
    'mu'           : Item(status='U '),
    })
  expected_mergeinfo_output = wc.State(A_MOVED_path, {
    '' : Item(status=' U'),
    })
  expected_elision_output = wc.State(A_MOVED_path, {
    })
  expected_status = wc.State(A_MOVED_path, {
    "B"            : Item(status='  '),
    "B/lambda"     : Item(status='  '),
    "B/E"          : Item(status='  '),
    "B/E/alpha"    : Item(status='  '),
    "B/E/beta"     : Item(status='  '),
    "B/F"          : Item(status='  '),
    "mu"           : Item(status='M '),
    "C"            : Item(status='  '),
    "D"            : Item(status='  '),
    "D/gamma"      : Item(status='  '),
    "D/G"          : Item(status='  '),
    "D/G/pi"       : Item(status='  '),
    "D/G/rho"      : Item(status='  '),
    "D/G/tau"      : Item(status='  '),
    "D/H"          : Item(status='  '),
    "D/H/chi"      : Item(status='  '),
    "D/H/omega"    : Item(status='  '),
    "D/H/psi"      : Item(status='  '),
    ""             : Item(status=' M'),
  })
  expected_status.tweak(wc_rev=9)
  k_expected_disk.tweak('', props={SVN_PROP_MERGEINFO : '/A_COPY:2-9'})
  expected_skip = wc.State(A_MOVED_path, {})
  run_and_verify_reintegrate(A_MOVED_path,
                                       sbox.repo_url + '/A_COPY',
                                       expected_output,
                                       expected_mergeinfo_output,
                                       expected_elision_output,
                                       k_expected_disk,
                                       expected_status,
                                       expected_skip,
                                       None, True, True)

#----------------------------------------------------------------------
def reintegrate_with_rename(sbox):
  "merge --reintegrate with renamed file on branch"

  # Make A_COPY branch in r2, and do a few more commits to A in r3-6.
  sbox.build()
  wc_dir = sbox.wc_dir
  expected_disk, expected_status = set_up_branch(sbox)

  # Make a change on the branch, to A/mu.  Commit in r7.
  svntest.main.file_write(sbox.ospath('A_COPY/mu'),
                          "Changed on the branch.")
  expected_output = wc.State(wc_dir, {'A_COPY/mu' : Item(verb='Sending')})
  expected_status.tweak('A_COPY/mu', wc_rev=7)
  svntest.actions.run_and_verify_commit(wc_dir, expected_output,
                                        expected_status, None, wc_dir)
  expected_disk.tweak('A_COPY/mu', contents='Changed on the branch.')

  # Update the wcs.
  expected_output = wc.State(wc_dir, {})
  expected_status.tweak(wc_rev='7')
  svntest.actions.run_and_verify_update(wc_dir, expected_output,
                                        expected_disk, expected_status,
                                        None, None, None, None, None, True)

  # Merge from trunk to branch (ie, r3-6), using normal cherry-harvest.
  A_COPY_path = sbox.ospath('A_COPY')
  expected_output = wc.State(A_COPY_path, {
    'D/H/psi'   : Item(status='U '),
    'D/G/rho'   : Item(status='U '),
    'B/E/beta'  : Item(status='U '),
    'D/H/omega' : Item(status='U '),
    })
  expected_mergeinfo_output = wc.State(A_COPY_path, {
    '' : Item(status=' U'),
    })
  expected_elision_output = wc.State(A_COPY_path, {
    })
  k_expected_status = wc.State(A_COPY_path, {
    "B"         : Item(status='  ', wc_rev=7),
    "B/lambda"  : Item(status='  ', wc_rev=7),
    "B/E"       : Item(status='  ', wc_rev=7),
    "B/E/alpha" : Item(status='  ', wc_rev=7),
    "B/E/beta"  : Item(status='M ', wc_rev=7),
    "B/F"       : Item(status='  ', wc_rev=7),
    "mu"        : Item(status='  ', wc_rev=7),
    "C"         : Item(status='  ', wc_rev=7),
    "D"         : Item(status='  ', wc_rev=7),
    "D/gamma"   : Item(status='  ', wc_rev=7),
    "D/G"       : Item(status='  ', wc_rev=7),
    "D/G/pi"    : Item(status='  ', wc_rev=7),
    "D/G/rho"   : Item(status='M ', wc_rev=7),
    "D/G/tau"   : Item(status='  ', wc_rev=7),
    "D/H"       : Item(status='  ', wc_rev=7),
    "D/H/chi"   : Item(status='  ', wc_rev=7),
    "D/H/omega" : Item(status='M ', wc_rev=7),
    "D/H/psi"   : Item(status='M ', wc_rev=7),
    ""          : Item(status=' M', wc_rev=7),
  })
  k_expected_disk = wc.State('', {
    ''          : Item(props={SVN_PROP_MERGEINFO : '/A:2-7'}),
    'B'         : Item(),
    'B/lambda'  : Item("This is the file 'lambda'.\n"),
    'B/E'       : Item(),
    'B/E/alpha' : Item("This is the file 'alpha'.\n"),
    'B/E/beta'  : Item("New content"),
    'B/F'       : Item(),
    'mu'        : Item("Changed on the branch."),
    'C'         : Item(),
    'D'         : Item(),
    'D/gamma'   : Item("This is the file 'gamma'.\n"),
    'D/G'       : Item(),
    'D/G/pi'    : Item("This is the file 'pi'.\n"),
    'D/G/rho'   : Item("New content"),
    'D/G/tau'   : Item("This is the file 'tau'.\n"),
    'D/H'       : Item(),
    'D/H/chi'   : Item("This is the file 'chi'.\n"),
    'D/H/omega' : Item("New content"),
    'D/H/psi'   : Item("New content"),
  })
  expected_skip = wc.State(A_COPY_path, {})
  svntest.actions.run_and_verify_merge(A_COPY_path, None, None,
                                       sbox.repo_url + '/A', None,
                                       expected_output,
                                       expected_mergeinfo_output,
                                       expected_elision_output,
                                       k_expected_disk,
                                       k_expected_status,
                                       expected_skip,
                                       None, None, None, None,
                                       None, True)
  expected_disk.tweak('A_COPY', props={SVN_PROP_MERGEINFO: '/A:2-7'})
  expected_disk.tweak('A_COPY/B/E/beta', contents="New content")
  expected_disk.tweak('A_COPY/D/G/rho', contents="New content")
  expected_disk.tweak('A_COPY/D/H/omega', contents="New content")
  expected_disk.tweak('A_COPY/D/H/psi', contents="New content")

  # Commit the merge to branch (r8).
  expected_output = wc.State(wc_dir, {
    'A_COPY/D/H/psi'   : Item(verb='Sending'),
    'A_COPY/D/G/rho'   : Item(verb='Sending'),
    'A_COPY/B/E/beta'  : Item(verb='Sending'),
    'A_COPY/D/H/omega' : Item(verb='Sending'),
    'A_COPY'           : Item(verb='Sending'),
    })
  expected_status.tweak('A_COPY', 'A_COPY/D/H/psi', 'A_COPY/D/G/rho',
                        'A_COPY/B/E/beta', 'A_COPY/D/H/omega', wc_rev=8)
  svntest.actions.run_and_verify_commit(wc_dir, expected_output,
                                        expected_status, None, wc_dir)


  # Update the wcs again.
  #
  # Note: this update had to be added because of r869016 (which was
  # merged into the reintegrate branch in r869021).  Without this
  # update, the mergeinfo will not be inherited properly as part of
  # the 'svn cp tau tauprime' step, and later (during the post-commit
  # update, with the new expected_disk) we'll get an error like this:
  #
  #   =============================================================
  #   Expected 'tauprime' and actual 'tauprime' in disk tree are different!
  #   =============================================================
  #   EXPECTED NODE TO BE:
  #   =============================================================
  #    * Node name:   tauprime
  #       Path:       A_COPY/D/G/tauprime
  #       Contents:   This is the file 'tau'.
  #
  #       Properties: {'svn:mergeinfo': '/A/D/G/tau:2-7'}
  #       Attributes: {}
  #       Children:   N/A (node is a file)
  #   =============================================================
  #   ACTUAL NODE FOUND:
  #   =============================================================
  #    * Node name:   tauprime
  #       Path:       G/tauprime
  #       Contents:   This is the file 'tau'.
  #
  #       Properties: {'svn:mergeinfo': ''}
  #       Attributes: {}
  #       Children:   N/A (node is a file)
  #
  expected_output = wc.State(wc_dir, {})
  expected_status.tweak(wc_rev='8')
  svntest.actions.run_and_verify_update(wc_dir, expected_output,
                                        expected_disk, expected_status,
                                        None, None, None, None, None, True)

  # Make another change on the branch: copy tau to tauprime.  Commit
  # in r9.
  svntest.actions.run_and_verify_svn(None, None, [], 'cp',
                                     sbox.repo_url + '/A_COPY/D/G/tau',
                                     sbox.repo_url + '/A_COPY/D/G/tauprime',
                                     '-m',
                                     'Repos to repos copy of tau to tauprime')

  # Update the trunk (well, the whole wc) to get the copy above and since
  # reintegrate really wants a clean wc.
  expected_output = wc.State(wc_dir, {
    'A_COPY/D/G/tauprime' : Item(verb='Adding')
    })
  expected_output = wc.State(A_COPY_path, {
    'D/G/tauprime' : Item(status='A '),
    })
  expected_status.add({'A_COPY/D/G/tauprime': Item(status='  ', wc_rev=9)})
  expected_disk.add({
    'A_COPY/D/G/tauprime' : Item(props={SVN_PROP_MERGEINFO: '/A/D/G/tau:2-7'},
                                 contents="This is the file 'tau'.\n")
    })
  expected_status.tweak(wc_rev='9')
  svntest.actions.run_and_verify_update(wc_dir, expected_output,
                                        expected_disk, expected_status,
                                        None, None, None, None, None, True)

  # *finally*, actually run merge --reintegrate in trunk with the
  # branch URL.  This should bring in the mu change and the tauprime
  # change.
  A_path = sbox.ospath('A')
  expected_output = wc.State(A_path, {
    'mu'           : Item(status='U '),
    'D/G/tauprime' : Item(status='A '),
    })
  expected_mergeinfo_output = wc.State(A_path, {
    ''             : Item(status=' U'),
    'D/G/tauprime' : Item(status=' U'),
    })
  expected_elision_output = wc.State(A_path, {
    })
  k_expected_status = wc.State(A_path, {
    "B"            : Item(status='  ', wc_rev=9),
    "B/lambda"     : Item(status='  ', wc_rev=9),
    "B/E"          : Item(status='  ', wc_rev=9),
    "B/E/alpha"    : Item(status='  ', wc_rev=9),
    "B/E/beta"     : Item(status='  ', wc_rev=9),
    "B/F"          : Item(status='  ', wc_rev=9),
    "mu"           : Item(status='M ', wc_rev=9),
    "C"            : Item(status='  ', wc_rev=9),
    "D"            : Item(status='  ', wc_rev=9),
    "D/gamma"      : Item(status='  ', wc_rev=9),
    "D/G"          : Item(status='  ', wc_rev=9),
    "D/G/pi"       : Item(status='  ', wc_rev=9),
    "D/G/rho"      : Item(status='  ', wc_rev=9),
    "D/G/tau"      : Item(status='  ', wc_rev=9),
    "D/G/tauprime" : Item(status='A ', wc_rev='-', copied='+'),
    "D/H"          : Item(status='  ', wc_rev=9),
    "D/H/chi"      : Item(status='  ', wc_rev=9),
    "D/H/omega"    : Item(status='  ', wc_rev=9),
    "D/H/psi"      : Item(status='  ', wc_rev=9),
    ""             : Item(status=' M', wc_rev=9),
  })
  k_expected_disk.tweak('', props={SVN_PROP_MERGEINFO : '/A_COPY:2-9'})
  k_expected_disk.add({
    'D/G/tauprime' : Item(props={SVN_PROP_MERGEINFO :
                                 '/A/D/G/tau:2-7\n/A_COPY/D/G/tauprime:9'},
                          contents="This is the file 'tau'.\n")
    })
  expected_skip = wc.State(A_path, {})
  run_and_verify_reintegrate(A_path,
                                       sbox.repo_url + '/A_COPY',
                                       expected_output,
                                       expected_mergeinfo_output,
                                       expected_elision_output,
                                       k_expected_disk,
                                       k_expected_status,
                                       expected_skip,
                                       None, True, True)

  # Finally, commit the result of the merge (r10).
  expected_output = wc.State(wc_dir, {
    'A/D/G/tauprime' : Item(verb='Adding'),
    'A/mu'           : Item(verb='Sending'),
    'A'              : Item(verb='Sending'),
    })
  expected_status.add({
    'A/D/G/tauprime' : Item(status='  ', wc_rev=10),
    })
  expected_status.tweak('A', 'A/mu', wc_rev=10)
  svntest.actions.run_and_verify_commit(wc_dir, expected_output,
                                        expected_status, None, wc_dir)

#----------------------------------------------------------------------
def reintegrate_branch_never_merged_to(sbox):
  "merge --reintegrate on a never-updated branch"

  # Make A_COPY branch in r2, and do a few more commits to A in r3-6.
  sbox.build()
  wc_dir = sbox.wc_dir
  expected_disk, expected_status = set_up_branch(sbox)

  # Make a change on the branch, to A_COPY/mu.  Commit in r7.
  svntest.main.file_write(sbox.ospath('A_COPY/mu'),
                          "Changed on the branch.")
  expected_output = wc.State(wc_dir, {'A_COPY/mu' : Item(verb='Sending')})
  expected_status.tweak('A_COPY/mu', wc_rev=7)
  svntest.actions.run_and_verify_commit(wc_dir, expected_output,
                                        expected_status, None, wc_dir)
  expected_disk.tweak('A_COPY/mu', contents='Changed on the branch.')

  # Update the wcs.
  expected_output = wc.State(wc_dir, {})
  expected_status.tweak(wc_rev='7')
  svntest.actions.run_and_verify_update(wc_dir, expected_output,
                                        expected_disk, expected_status,
                                        None, None, None, None, None, True)

  # Make another change on the branch: copy tau to tauprime.  Commit
  # in r8.
  svntest.actions.run_and_verify_svn(None, None, [], 'cp',
                                     os.path.join(wc_dir, 'A_COPY', 'D', 'G',
                                                  'tau'),
                                     os.path.join(wc_dir, 'A_COPY', 'D', 'G',
                                                  'tauprime'))
  expected_output = wc.State(wc_dir, {
    'A_COPY/D/G/tauprime' : Item(verb='Adding')
    })
  expected_status.add({'A_COPY/D/G/tauprime': Item(status='  ', wc_rev=8)})
  svntest.actions.run_and_verify_commit(wc_dir, expected_output,
                                        expected_status, None, wc_dir)
  expected_disk.add({
    'A_COPY/D/G/tauprime' : Item(contents="This is the file 'tau'.\n")
    })

  # Update the trunk (well, the whole wc) (since reintegrate really
  # wants a clean wc).
  expected_output = wc.State(wc_dir, {})
  expected_status.tweak(wc_rev='8')
  svntest.actions.run_and_verify_update(wc_dir, expected_output,
                                        expected_disk, expected_status,
                                        None, None, None, None, None, True)

  # *finally*, actually run merge --reintegrate in trunk with the
  # branch URL.  This should bring in the mu change and the tauprime
  # change.
  A_path = sbox.ospath('A')
  expected_output = wc.State(A_path, {
    'mu'           : Item(status='U '),
    'D/G/tauprime' : Item(status='A '),
    })
  expected_mergeinfo_output = wc.State(A_path, {
    '' : Item(status=' U'),
    })
  expected_elision_output = wc.State(A_path, {
    })
  k_expected_status = wc.State(A_path, {
    "B"            : Item(status='  ', wc_rev=8),
    "B/lambda"     : Item(status='  ', wc_rev=8),
    "B/E"          : Item(status='  ', wc_rev=8),
    "B/E/alpha"    : Item(status='  ', wc_rev=8),
    "B/E/beta"     : Item(status='  ', wc_rev=8),
    "B/F"          : Item(status='  ', wc_rev=8),
    "mu"           : Item(status='M ', wc_rev=8),
    "C"            : Item(status='  ', wc_rev=8),
    "D"            : Item(status='  ', wc_rev=8),
    "D/gamma"      : Item(status='  ', wc_rev=8),
    "D/G"          : Item(status='  ', wc_rev=8),
    "D/G/pi"       : Item(status='  ', wc_rev=8),
    "D/G/rho"      : Item(status='  ', wc_rev=8),
    "D/G/tau"      : Item(status='  ', wc_rev=8),
    "D/G/tauprime" : Item(status='A ', wc_rev='-', copied='+'),
    "D/H"          : Item(status='  ', wc_rev=8),
    "D/H/chi"      : Item(status='  ', wc_rev=8),
    "D/H/omega"    : Item(status='  ', wc_rev=8),
    "D/H/psi"      : Item(status='  ', wc_rev=8),
    ""             : Item(status=' M', wc_rev=8),
  })
  k_expected_disk = wc.State('', {
    ''             : Item(props={SVN_PROP_MERGEINFO : '/A_COPY:2-8'}),
    'B'            : Item(),
    'B/lambda'     : Item("This is the file 'lambda'.\n"),
    'B/E'          : Item(),
    'B/E/alpha'    : Item("This is the file 'alpha'.\n"),
    'B/E/beta'     : Item("New content"),
    'B/F'          : Item(),
    'mu'           : Item("Changed on the branch."),
    'C'            : Item(),
    'D'            : Item(),
    'D/gamma'      : Item("This is the file 'gamma'.\n"),
    'D/G'          : Item(),
    'D/G/pi'       : Item("This is the file 'pi'.\n"),
    'D/G/rho'      : Item("New content"),
    'D/G/tau'      : Item("This is the file 'tau'.\n"),
    'D/G/tauprime' : Item("This is the file 'tau'.\n"),
    'D/H'          : Item(),
    'D/H/chi'      : Item("This is the file 'chi'.\n"),
    'D/H/omega'    : Item("New content"),
    'D/H/psi'      : Item("New content"),
  })
  expected_skip = wc.State(A_path, {})
  run_and_verify_reintegrate(A_path,
                                       sbox.repo_url + '/A_COPY',
                                       expected_output,
                                       expected_mergeinfo_output,
                                       expected_elision_output,
                                       k_expected_disk,
                                       k_expected_status,
                                       expected_skip,
                                       None, True, True)

  # Finally, commit the result of the merge (r9).
  expected_output = wc.State(wc_dir, {
    'A/D/G/tauprime' : Item(verb='Adding'),
    'A/mu'           : Item(verb='Sending'),
    'A'              : Item(verb='Sending'),
    })
  expected_status.add({
    'A/D/G/tauprime' : Item(status='  ', wc_rev=9),
    })
  expected_status.tweak('A', 'A/mu', wc_rev=9)
  svntest.actions.run_and_verify_commit(wc_dir, expected_output,
                                        expected_status, None, wc_dir)

#----------------------------------------------------------------------
def reintegrate_fail_on_modified_wc(sbox):
  "merge --reintegrate should fail in modified wc"
  sbox.build()
  wc_dir = sbox.wc_dir
  A_path = sbox.ospath('A')
  A_COPY_path = sbox.ospath('A_COPY')
  mu_path = os.path.join(A_path, "mu")
  ignored_expected_disk, ignored_expected_status = set_up_branch(sbox)

  # Do a 'sync' merge first so that the following merge really needs to be a
  # reintegrate, so that an equivalent automatic merge would behave the same.
  svntest.main.run_svn(None, 'merge', sbox.repo_url + '/A', A_COPY_path)
  sbox.simple_commit()

  svntest.main.file_write(mu_path, "Changed on 'trunk' (the merge target).")
  sbox.simple_update() # avoid mixed-revision error
  run_and_verify_reintegrate(
    A_path, sbox.repo_url + '/A_COPY', None, None, None,
    None, None, None,
    ".*Cannot merge into a working copy that has local modifications.*",
    True, False)

#----------------------------------------------------------------------
def reintegrate_fail_on_mixed_rev_wc(sbox):
  "merge --reintegrate should fail in mixed-rev wc"
  sbox.build()
  wc_dir = sbox.wc_dir
  A_path = sbox.ospath('A')
  mu_path = os.path.join(A_path, "mu")
  ignored_expected_disk, expected_status = set_up_branch(sbox)
  # Make and commit a change, in order to get a mixed-rev wc.
  svntest.main.file_write(mu_path, "Changed on 'trunk' (the merge target).")
  expected_output = wc.State(wc_dir, {
    'A/mu'           : Item(verb='Sending'),
    })
  expected_status.tweak('A/mu', wc_rev=7)
  svntest.actions.run_and_verify_commit(wc_dir, expected_output,
                                        expected_status, None, wc_dir)
  # Try merging into that same wc, expecting failure.
  run_and_verify_reintegrate(
    A_path, sbox.repo_url + '/A_COPY', None, None, None,
    None, None, None,
    ".*Cannot merge into mixed-revision working copy.*",
    True, False)

#----------------------------------------------------------------------
def reintegrate_fail_on_switched_wc(sbox):
  "merge --reintegrate should fail in switched wc"
  sbox.build()
  wc_dir = sbox.wc_dir
  A_path = sbox.ospath('A')
  A_COPY_path = sbox.ospath('A_COPY')
  G_path = os.path.join(A_path, "D", "G")
  switch_url = sbox.repo_url + "/A/D/H"
  expected_disk, expected_status = set_up_branch(sbox)

  # Do a 'sync' merge first so that the following merge really needs to be a
  # reintegrate, so that an equivalent automatic merge would behave the same.
  expected_disk.tweak(
    'A_COPY/D/H/psi',
    'A_COPY/D/G/rho',
    'A_COPY/B/E/beta',
    'A_COPY/D/H/omega',
    contents="New content")
  expected_status.tweak(
    'A_COPY/D/H/psi',
    'A_COPY/D/G/rho',
    'A_COPY/B/E/beta',
    'A_COPY/D/H/omega',
    'A_COPY',
    wc_rev=7)
  svntest.main.run_svn(None, 'merge', sbox.repo_url + '/A', A_COPY_path)
  sbox.simple_commit()

  # Switch a subdir of the target.
  expected_output = svntest.wc.State(wc_dir, {
    'A/D/G/pi'          : Item(status='D '),
    'A/D/G/rho'         : Item(status='D '),
    'A/D/G/tau'         : Item(status='D '),
    'A/D/G/chi'         : Item(status='A '),
    'A/D/G/psi'         : Item(status='A '),
    'A/D/G/omega'       : Item(status='A '),
    })
  expected_disk.remove('A/D/G/pi', 'A/D/G/rho', 'A/D/G/tau')
  expected_disk.add({
    'A/D/G/chi'   : Item(contents="This is the file 'chi'.\n"),
    'A/D/G/psi'   : Item(contents="New content"),
    'A/D/G/omega' : Item(contents="New content"),
    })
  expected_status.remove('A/D/G/pi', 'A/D/G/rho', 'A/D/G/tau')
  expected_status.add({
    'A/D/G'       : Item(status='  ', wc_rev=7, switched='S'),
    'A/D/G/chi'   : Item(status='  ', wc_rev=7),
    'A/D/G/psi'   : Item(status='  ', wc_rev=7),
    'A/D/G/omega' : Item(status='  ', wc_rev=7),
    })
  svntest.actions.run_and_verify_switch(wc_dir,
                                        G_path,
                                        switch_url,
                                        expected_output,
                                        expected_disk,
                                        expected_status,
                                        None, None, None, None, None,
                                        False, '--ignore-ancestry')
  sbox.simple_update() # avoid mixed-revision error
  run_and_verify_reintegrate(
    A_path, sbox.repo_url + '/A_COPY', None, None, None,
    None, None, None,
    ".*Cannot merge into a working copy with a switched subtree.*",
    True, False)

#----------------------------------------------------------------------
# Test for issue #3603 'allow reintegrate merges into WCs with
# missing subtrees'.
@Issue(3603)
def reintegrate_on_shallow_wc(sbox):
  "merge --reintegrate in shallow wc"

  # Create a standard greek tree, branch A to A_COPY in r2.
  sbox.build()
  wc_dir = sbox.wc_dir
  expected_disk, expected_status = set_up_branch(sbox, branch_only = True)

  # Some paths we'll care about
  A_path         = sbox.ospath('A')
  A_D_path       = sbox.ospath('A/D')
  mu_COPY_path   = sbox.ospath('A_COPY/mu')
  psi_COPY_path  = sbox.ospath('A_COPY/D/H/psi')
  A_COPY_path    = sbox.ospath('A_COPY')

  # r3 - Make a change on the A_COPY branch that will be
  # reintegrated back to A.
  svntest.main.file_write(mu_COPY_path, "branch work")
  svntest.main.run_svn(None, 'commit', '-m',
                       'Some work on the A_COPY branch', wc_dir)

  # First try a reintegrate where the target WC has a shallow subtree
  # that is not affected by the reintegrate.  In this case we set the
  # depth of A/D to empty.  Since the only change made on the branch
  # since the branch point is to A_COPY/mu, the reintegrate should
  # simply work and update A/mu with the branch's contents.
  svntest.actions.run_and_verify_svn(None, None, [], 'up', wc_dir)
  svntest.actions.run_and_verify_svn(None, None, [], 'up',
                                     '--set-depth', 'empty', A_D_path)
  expected_output = wc.State(A_path, {
    'mu' : Item(status='U '),
    })
  expected_mergeinfo_output = wc.State(A_path, {
    '' : Item(status=' U'),
    })
  expected_elision_output = wc.State(A_path, {
    })
  expected_A_status = wc.State(A_path, {
    ''          : Item(status=' M'),
    'B'         : Item(status='  '),
    'mu'        : Item(status='M '),
    'B/E'       : Item(status='  '),
    'B/E/alpha' : Item(status='  '),
    'B/E/beta'  : Item(status='  '),
    'B/lambda'  : Item(status='  '),
    'B/F'       : Item(status='  '),
    'C'         : Item(status='  '),
    'D'         : Item(status='  '), # Don't expect anything under D,
                                     # its depth is empty!
    })
  expected_A_status.tweak(wc_rev=3)
  expected_A_disk = wc.State('', {
    ''          : Item(props={SVN_PROP_MERGEINFO : '/A_COPY:2-3'}),
    'B'         : Item(),
    'mu'        : Item("branch work"),
    'B/E'       : Item(),
    'B/E/alpha' : Item("This is the file 'alpha'.\n"),
    'B/E/beta'  : Item("This is the file 'beta'.\n"),
    'B/lambda'  : Item("This is the file 'lambda'.\n"),
    'B/F'       : Item(),
    'C'         : Item(),
    'D'         : Item(), # Don't expect anything under D, its depth is empty!
    })
  expected_A_skip = wc.State(A_path, {})
  run_and_verify_reintegrate(A_path,
                                       sbox.repo_url + '/A_COPY',
                                       expected_output,
                                       expected_mergeinfo_output,
                                       expected_elision_output,
                                       expected_A_disk,
                                       expected_A_status,
                                       expected_A_skip,
                                       None, 1, 1)

  # Now revert the reintegrate and make a second change on the
  # branch in r4, but this time change a subtree that corresponds
  # to the missing (shallow) portion of the source.  The reintegrate
  # should still succeed.
  svntest.actions.run_and_verify_svn(None, None, [], 'revert', '-R', wc_dir)
  svntest.main.file_write(psi_COPY_path, "more branch work")
  svntest.main.run_svn(None, 'commit', '-m',
                       'Some more work on the A_COPY branch', wc_dir)
  # Reuse the same expectations as the prior merge, except for the mergeinfo
  # on the target root that now includes the latest rev on the branch.
  expected_mergeinfo_output.add({
      'D' : Item(status=' U')
      })
  expected_A_status.tweak('D', status=' M')
  expected_A_disk.tweak('D', props={SVN_PROP_MERGEINFO : '/A_COPY/D:2-4*'})
  # ... a depth-restricted item is skipped ...
  expected_A_skip.add({
      'D/H' : Item(verb='Skipped missing target')
  })
  expected_output.add({
    # Below the skip
    'D/H/psi'           : Item(status='  ', treeconflict='U'),
  })
  # Currently this fails due to r1424469.  For a full explanation see
  # http://svn.haxx.se/dev/archive-2012-12/0472.shtml
  # and http://svn.haxx.se/dev/archive-2012-12/0475.shtml
  expected_A_disk.tweak('', props={SVN_PROP_MERGEINFO : '/A_COPY:2-4'})
  run_and_verify_reintegrate(A_path,
                                       sbox.repo_url + '/A_COPY',
                                       expected_output,
                                       expected_mergeinfo_output,
                                       expected_elision_output,
                                       expected_A_disk,
                                       expected_A_status,
                                       expected_A_skip,
                                       None, 1, 1)

#----------------------------------------------------------------------
@SkipUnless(server_has_mergeinfo)
def reintegrate_fail_on_stale_source(sbox):
  "merge --reintegrate should fail on stale source"
  sbox.build()
  wc_dir = sbox.wc_dir
  expected_disk, expected_status = set_up_branch(sbox)
  A_path = sbox.ospath('A')
  mu_path = os.path.join(A_path, "mu")
  svntest.main.file_append(mu_path, 'some text appended to mu\n')
  svntest.actions.run_and_verify_svn(None, None, [], 'commit',
                                     '-m', 'a change to mu', mu_path)
  # Unmix the revisions in the working copy.
  svntest.actions.run_and_verify_svn(None, None, [], 'update', wc_dir)
  # The merge --reintegrate succeeds but since there were no changes
  # on A_COPY after it was branched the only result is updated mergeinfo
  # on the reintegrate target.
  expected_output = wc.State(A_path, {})
  expected_mergeinfo_output = wc.State(A_path, {
    '' : Item(status=' U'),
    })
  expected_elision_output = wc.State(A_path, {
    })
  expected_status = wc.State(A_path, {
    ''          : Item(status=' M'),
    'B'         : Item(status='  '),
    'mu'        : Item(status='  '),
    'B/E'       : Item(status='  '),
    'B/E/alpha' : Item(status='  '),
    'B/E/beta'  : Item(status='  '),
    'B/lambda'  : Item(status='  '),
    'B/F'       : Item(status='  '),
    'C'         : Item(status='  '),
    'D'         : Item(status='  '),
    'D/G'       : Item(status='  '),
    'D/G/pi'    : Item(status='  '),
    'D/G/rho'   : Item(status='  '),
    'D/G/tau'   : Item(status='  '),
    'D/gamma'   : Item(status='  '),
    'D/H'       : Item(status='  '),
    'D/H/chi'   : Item(status='  '),
    'D/H/psi'   : Item(status='  '),
    'D/H/omega' : Item(status='  '),
    })
  expected_status.tweak(wc_rev=7)
  expected_disk = wc.State('', {
    ''          : Item(props={SVN_PROP_MERGEINFO : '/A_COPY:2-7'}),
    'B'         : Item(),
    'mu'        : Item("This is the file 'mu'.\nsome text appended to mu\n"),
    'B/E'       : Item(),
    'B/E/alpha' : Item("This is the file 'alpha'.\n"),
    'B/E/beta'  : Item("New content"),
    'B/lambda'  : Item("This is the file 'lambda'.\n"),
    'B/F'       : Item(),
    'C'         : Item(),
    'D'         : Item(),
    'D/G'       : Item(),
    'D/G/pi'    : Item("This is the file 'pi'.\n"),
    'D/G/rho'   : Item("New content"),
    'D/G/tau'   : Item("This is the file 'tau'.\n"),
    'D/gamma'   : Item("This is the file 'gamma'.\n"),
    'D/H'       : Item(),
    'D/H/chi'   : Item("This is the file 'chi'.\n"),
    'D/H/psi'   : Item("New content"),
    'D/H/omega' : Item("New content"),
    })
  expected_skip = wc.State(A_path, { })
  run_and_verify_reintegrate(A_path,
                                       sbox.repo_url + '/A_COPY',
                                       expected_output,
                                       expected_mergeinfo_output,
                                       expected_elision_output,
                                       expected_disk,
                                       expected_status,
                                       expected_skip,
                                       [], True, True)

#----------------------------------------------------------------------
def merge_file_with_space_in_its_path(sbox):
  "merge a file with space in its path"

  sbox.build()
  wc_dir = sbox.wc_dir
  some_dir = sbox.ospath('some dir')
  file1 = os.path.join(some_dir, "file1")
  file2 = os.path.join(some_dir, "file2")

  # Make r2.
  os.mkdir(some_dir)
  svntest.main.file_append(file1, "Initial text in the file.\n")
  svntest.main.run_svn(None, "add", some_dir)
  svntest.actions.run_and_verify_svn(None, None, [],
                                     "ci", "-m", "r2", wc_dir)

  # Make r3.
  svntest.main.run_svn(None, "copy", file1, file2)
  svntest.actions.run_and_verify_svn(None, None, [],
                                     "ci", "-m", "r3", wc_dir)

  # Make r4.
  svntest.main.file_append(file2, "Next line of text in the file.\n")
  svntest.actions.run_and_verify_svn(None, None, [],
                                     "ci", "-m", "r4", wc_dir)

  target_url = sbox.repo_url + '/some%20dir/file2'
  run_reintegrate(target_url, file1)

#----------------------------------------------------------------------
@SkipUnless(server_has_mergeinfo)
def reintegrate_with_subtree_mergeinfo(sbox):
  "merge --reintegrate with subtree mergeinfo"

  # Create a standard greek tree, branch A to A_COPY in r2, A to A_COPY_2 in
  # r3, A to A_COPY_3 in r4, and then make some changes under A in r5-8.
  #
  #   A_COPY_3      4---------
  #                /
  #   A     -1--------5-6-7-8-
  #            \ \
  #   A_COPY    2-\-----------
  #                \
  #   A_COPY_2      3---------

  sbox.build()
  wc_dir = sbox.wc_dir
  expected_disk, expected_status = set_up_branch(sbox, False, 3)

  # Some paths we'll care about
  gamma_COPY_3_path     = sbox.ospath('A_COPY_3/D/gamma')
  D_path                = sbox.ospath('A/D')
  gamma_path            = sbox.ospath('A/D/gamma')
  mu_COPY_2_path        = sbox.ospath('A_COPY_2/mu')
  mu_path               = sbox.ospath('A/mu')
  mu_COPY_path          = sbox.ospath('A_COPY/mu')
  A_COPY_path           = sbox.ospath('A_COPY')
  D_COPY_path           = sbox.ospath('A_COPY')
  beta_COPY_path        = sbox.ospath('A_COPY/B/E/beta')
  gamma_COPY_path       = sbox.ospath('A_COPY/D/gamma')
  gamma_moved_COPY_path = sbox.ospath('A_COPY/D/gamma_moved')
  gamma_moved_path      = sbox.ospath('A/D/gamma_moved')
  rho_COPY_path         = sbox.ospath('A_COPY/D/G/rho')
  omega_COPY_path       = sbox.ospath('A_COPY/D/H/omega')
  psi_COPY_path         = sbox.ospath('A_COPY/D/H/psi')
  D_COPY_path           = sbox.ospath('A_COPY/D')
  alpha_COPY_path       = sbox.ospath('A_COPY/B/E/alpha')
  A_path                = sbox.ospath('A')

  # Now set up a situation where we try to reintegrate A_COPY back to A but
  # both of these paths have subtree mergeinfo.  Iff the mergeinfo on A_COPY
  # reflects that the same revisions have been applied across all of A_COPY,
  # then the reintegrate merge should succeed.  We'll try that case first.
  #
  #   A_COPY_3       4-------[9]--
  #                 /          \
  #                /            \
  #   A     -1--------5-6-7-8---10-------------------WC--
  #            \ \              (D)         \        /reint.
  #             \ \                    (mu)  \      /
  #   A_COPY     2-\--------------------12---13--14------
  #                 \                   /
  #                  \                 /
  #   A_COPY_2        3-------------[11]--
  #
  #   Key: [#] = cherry-picked revision; (foo) = merge of subtree 'foo'
  #   Note: These diagrams show an overview and do not capture every detail.

  # r9 - Make a text change to A_COPY_3/D/gamma
  svntest.main.file_write(gamma_COPY_3_path, "New content")
  expected_output = wc.State(wc_dir, {'A_COPY_3/D/gamma' : Item(verb='Sending')})
  expected_status.tweak('A_COPY_3/D/gamma', wc_rev=9)
  svntest.actions.run_and_verify_commit(wc_dir, expected_output,
                                        expected_status, None, wc_dir)

  # r10 - Merge r9 from A_COPY_3/D to A/D, creating explicit subtree
  # mergeinfo under A.  For this and every subsequent merge we update the WC
  # first to allow full inheritance and elision.
  svntest.actions.run_and_verify_svn(None, exp_noop_up_out(9), [], 'up',
                                     wc_dir)
  expected_status.tweak(wc_rev=9)
  svntest.actions.run_and_verify_svn(
    None,
    expected_merge_output([[9]],
                          ['U    ' + gamma_path + '\n',
                           ' U   ' + D_path     + '\n',]),
    [], 'merge', '-c9', sbox.repo_url + '/A_COPY_3/D', D_path)
  expected_output = wc.State(wc_dir,
                             {'A/D'       : Item(verb='Sending'),
                              'A/D/gamma' : Item(verb='Sending')})
  expected_status.tweak('A/D', 'A/D/gamma', wc_rev=10)
  svntest.actions.run_and_verify_commit(wc_dir, expected_output,
                                        expected_status, None, wc_dir)

  # r11 - Make a text change to A_COPY_2/mu
  svntest.main.file_write(mu_COPY_2_path, "New content")
  expected_output = wc.State(wc_dir, {'A_COPY_2/mu' : Item(verb='Sending')})
  expected_status.tweak('A_COPY_2/mu', wc_rev=11)
  svntest.actions.run_and_verify_commit(wc_dir, expected_output,
                                        expected_status, None, wc_dir)

  # r12 - Merge r11 from A_COPY_2/mu to A_COPY/mu
  svntest.actions.run_and_verify_svn(None, exp_noop_up_out(11), [], 'up',
                                     wc_dir)
  expected_status.tweak(wc_rev=11)
  svntest.actions.run_and_verify_svn(
    None,
    expected_merge_output([[11]],
                          ['U    ' + mu_COPY_path + '\n',
                           ' U   ' + mu_COPY_path + '\n',]),
    [], 'merge', '-c11', sbox.repo_url + '/A_COPY_2/mu', mu_COPY_path)
  expected_output = wc.State(wc_dir,
                             {'A_COPY/mu' : Item(verb='Sending')})
  expected_status.tweak('A_COPY/mu', wc_rev=12)
  svntest.actions.run_and_verify_commit(wc_dir, expected_output,
                                        expected_status, None, wc_dir)

  # r13 - Do a 'synch' cherry harvest merge of all available revisions
  # from A to A_COPY
  svntest.actions.run_and_verify_svn(None, exp_noop_up_out(12), [], 'up',
                                     wc_dir)
  expected_status.tweak(wc_rev=12)
  svntest.actions.run_and_verify_svn(
    None,
    expected_merge_output([[2,12]],
                          ['U    ' + beta_COPY_path  + '\n',
                           'U    ' + gamma_COPY_path + '\n',
                           'U    ' + rho_COPY_path   + '\n',
                           'U    ' + omega_COPY_path + '\n',
                           'U    ' + psi_COPY_path   + '\n',
                           ' U   ' + A_COPY_path     + '\n',
                           ' U   ' + D_COPY_path     + '\n',
                           ' G   ' + D_COPY_path     + '\n',]),
    [], 'merge', sbox.repo_url + '/A', A_COPY_path)
  expected_output = wc.State(wc_dir,
                             {'A_COPY'           : Item(verb='Sending'),
                              #'A_COPY/mu'        : Item(verb='Sending'),
                              'A_COPY/B/E/beta'  : Item(verb='Sending'),
                              'A_COPY/D'         : Item(verb='Sending'),
                              'A_COPY/D/G/rho'   : Item(verb='Sending'),
                              'A_COPY/D/H/omega' : Item(verb='Sending'),
                              'A_COPY/D/H/psi'   : Item(verb='Sending'),
                              'A_COPY/D/gamma'   : Item(verb='Sending')})
  expected_status.tweak('A_COPY',
                        #'A_COPY/mu',
                        'A_COPY/B/E/beta',
                        'A_COPY/D',
                        'A_COPY/D/G/rho',
                        'A_COPY/D/H/omega',
                        'A_COPY/D/H/psi',
                        'A_COPY/D/gamma',
                        wc_rev=13)
  svntest.actions.run_and_verify_commit(wc_dir, expected_output,
                                        expected_status, None, wc_dir)

  # r14 - Make a text change on A_COPY/B/E/alpha
  svntest.main.file_write(alpha_COPY_path, "New content")
  expected_output = wc.State(wc_dir, {'A_COPY/B/E/alpha' : Item(verb='Sending')})
  expected_status.tweak('A_COPY/B/E/alpha', wc_rev=14)
  svntest.actions.run_and_verify_commit(wc_dir, expected_output,
                                        expected_status, None, wc_dir)

  # Now, reintegrate A_COPY to A.  This should succeed.
  svntest.actions.run_and_verify_svn(None, exp_noop_up_out(14), [], 'up',
                                     wc_dir)
  expected_status.tweak(wc_rev=14)
  expected_output = wc.State(A_path, {
    'B/E/alpha' : Item(status='U '),
    'mu'        : Item(status='UU'),
    'D'         : Item(status=' U'),
    })
  expected_mergeinfo_output = wc.State(A_path, {
    ''   : Item(status=' U'),
    'mu' : Item(status=' G'),
    'D'  : Item(status=' U'),
    })
  expected_elision_output = wc.State(A_path, {
    })
  expected_A_status = wc.State(A_path, {
    ''          : Item(status=' M'),
    'B'         : Item(status='  '),
    'mu'        : Item(status='MM'),
    'B/E'       : Item(status='  '),
    'B/E/alpha' : Item(status='M '),
    'B/E/beta'  : Item(status='  '),
    'B/lambda'  : Item(status='  '),
    'B/F'       : Item(status='  '),
    'C'         : Item(status='  '),
    'D'         : Item(status=' M'),
    'D/G'       : Item(status='  '),
    'D/G/pi'    : Item(status='  '),
    'D/G/rho'   : Item(status='  '),
    'D/G/tau'   : Item(status='  '),
    'D/gamma'   : Item(status='  '),
    'D/H'       : Item(status='  '),
    'D/H/chi'   : Item(status='  '),
    'D/H/psi'   : Item(status='  '),
    'D/H/omega' : Item(status='  '),
    })
  expected_A_status.tweak(wc_rev=14)
  expected_A_disk = wc.State('', {
    ''          : Item(props={SVN_PROP_MERGEINFO : '/A_COPY:2-14'}),
    'B'         : Item(),
    'mu'        : Item("New content",
                       props={SVN_PROP_MERGEINFO :
                              '/A_COPY/mu:2-14\n/A_COPY_2/mu:11'}),
    'B/E'       : Item(),
    'B/E/alpha' : Item("New content"),
    'B/E/beta'  : Item("New content"),
    'B/lambda'  : Item("This is the file 'lambda'.\n"),
    'B/F'       : Item(),
    'C'         : Item(),
    'D'         : Item(props=
                       {SVN_PROP_MERGEINFO : '/A_COPY/D:2-14\n/A_COPY_3/D:9'}),
    'D/G'       : Item(),
    'D/G/pi'    : Item("This is the file 'pi'.\n"),
    'D/G/rho'   : Item("New content"),
    'D/G/tau'   : Item("This is the file 'tau'.\n"),
    'D/gamma'   : Item("New content"),
    'D/H'       : Item(),
    'D/H/chi'   : Item("This is the file 'chi'.\n"),
    'D/H/psi'   : Item("New content"),
    'D/H/omega' : Item("New content"),
    })
  expected_A_skip = wc.State(A_COPY_path, {})
  run_and_verify_reintegrate(A_path,
                                       sbox.repo_url + '/A_COPY',
                                       expected_output,
                                       expected_mergeinfo_output,
                                       expected_elision_output,
                                       expected_A_disk,
                                       expected_A_status,
                                       expected_A_skip,
                                       None, 1, 1)

  # Make some more changes to A_COPY so that the same revisions have *not*
  # been uniformly applied from A to A_COPY.  In this case the reintegrate
  # merge should fail, but should provide a helpful message as to where the
  # problems are.
  #
  #   A_COPY_3        4-------[9]--
  #                  /          \
  #                 /            \          [-8]___
  #   A     -1---------5-6-7-8---10----------------\-------WC--
  #            \ \               (D)        \       \      /reint.
  #             \ \                    (mu)  \       \    /
  #   A_COPY     2-\--------------------12---13--14--15--------
  #                 \                   /            (D)
  #                  \                 /
  #   A_COPY_2        3-------------[11]--

  # First revert the previous reintegrate merge
  svntest.actions.run_and_verify_svn(None, None, [],
                                     'revert', '-R', wc_dir)

  # r15 - Reverse Merge r8 from A/D to A_COPY/D.
  svntest.actions.run_and_verify_svn(
    None,
    expected_merge_output([[-8]],
                          ['U    ' + omega_COPY_path + '\n',
                           ' U   ' + D_COPY_path     + '\n',]),
    [], 'merge', '-c-8', sbox.repo_url + '/A/D', D_COPY_path)
  expected_output = wc.State(wc_dir,
                             {'A_COPY/D'         : Item(verb='Sending'),
                              'A_COPY/D/H/omega' : Item(verb='Sending')})
  expected_status.tweak('A_COPY/D', 'A_COPY/D/H/omega', wc_rev=15)
  svntest.actions.run_and_verify_commit(wc_dir, expected_output,
                                        expected_status, None, wc_dir)

  # Now reintegrate A_COPY back to A.  Since A_COPY/D no longer has r8 merged
  # to it from A, the merge should fail.  Further we expect an error message
  # that highlights the fact that A_COPY/D is the offending subtree.
  #
  # We want to know that the error provides specific information about the
  # paths that are stopping --reintegrate from working.
  run_reintegrate_expect_error(sbox.repo_url + '/A_COPY', A_path,
                               [],
                                "(svn: E195016: Reintegrate can only be used if "
                                "revisions 2 through 15 were previously "
                                "merged from .*/A to the reintegrate source, "
                                "but this is not the case:\n)"
                                "|(  A_COPY/D\n)"
                                "|(    Missing ranges: /A/D:8\n)"
                                "|(  A_COPY/mu\n)"
                                "|(    Missing ranges: /A/mu:2-12\n)"
                                "|(\n)")

  # Test another common situation that can break reintegrate as a result
  # of copies and moves:
  #
  #   A) On our 'trunk' rename a subtree in such a way as the new
  #      subtree has explicit mergeinfo.  Commit this rename as rev N.
  #
  #   B) Synch merge the rename in A) to our 'branch' in rev N+1.  The
  #      renamed subtree now has the same explicit mergeinfo on both
  #      the branch and trunk.
  #
  #   C) Make some more changes on the renamed subtree in 'trunk' and
  #      commit in rev N+2.
  #
  #   D) Synch merge the changes in C) from 'trunk' to 'branch' and commit in
  #      rev N+3.  The renamed subtree on 'branch' now has additional explicit
  #      mergeinfo decribing the synch merge from trunk@N+1 to trunk@N+2.
  #
  #   E) Reintegrate 'branch' to 'trunk'.
  #
  #                                       Step:   A   B    C   D    E
  #   A_COPY_3    ---[9]--
  #              /     \                      (D/g.->
  #             /       \          [-8]___     D/g.m.) (D/g.m.)
  #   A     ------------10----------------\------16-------18--------WC
  #          \\         (D)        \       \        \        \      /reint.
  #           \\              (mu)  \       \        \        \    /
  #   A_COPY   -\--------------12---13--14--15-------17-------19------
  #              \             /            (D)
  #               \           /
  #   A_COPY_2     --------[11]--

  # r16 - A) REPOS-to-REPOS rename of A/D/gamma to A/D/gamma_moved.  Since
  # r874258 WC-to-WC moves won't create mergeinfo on the dest if the source
  # doesn't have any.  So do a repos-to-repos move so explicit mergeinfo
  # *is* created on the destination.
  svntest.actions.run_and_verify_svn(None, None,[], 'move',
                                     sbox.repo_url + '/A/D/gamma',
                                     sbox.repo_url + '/A/D/gamma_moved',
                                     '-m', 'REPOS-to-REPOS move'
                                     )
  svntest.actions.run_and_verify_svn(None, None, [], 'up', wc_dir)
  expected_status.tweak(wc_rev=16)
  expected_status.remove('A/D/gamma')
  expected_status.add({'A/D/gamma_moved' : Item(status='  ', wc_rev=16)})

  # Why is gamma_moved notified as ' G' rather than ' U'?  It was
  # added by the merge and there is only a single editor drive, so
  # how can any prop changes be merged to it?  The answer is that
  # the merge code does some quiet housekeeping, merging gamma_moved's
  # inherited mergeinfo into its incoming mergeinfo, see
  # http://subversion.tigris.org/issues/show_bug.cgi?id=4309
  # This test is not covering issue #4309 so we let the current
  # behavior pass.
  # r17 - B) Synch merge from A to A_COPY
  svntest.actions.run_and_verify_svn(
    None,
    expected_merge_output([[8], [13,16], [2,16]],
                          ['U    ' + omega_COPY_path + '\n',
                           'A    ' + gamma_moved_COPY_path + '\n',
                           'D    ' + gamma_COPY_path + '\n',
                           ' U   ' + A_COPY_path     + '\n',
                           ' U   ' + D_COPY_path     + '\n',
                           ' G   ' + gamma_moved_COPY_path + '\n']),
    [], 'merge', sbox.repo_url + '/A',  A_COPY_path)
  expected_output = wc.State(
    wc_dir,
    {'A_COPY'               : Item(verb='Sending'), # Mergeinfo update
     'A_COPY/D'             : Item(verb='Sending'), # Mergeinfo update
     'A_COPY/D/gamma'       : Item(verb='Deleting'),
     'A_COPY/D/gamma_moved' : Item(verb='Adding'),
     'A_COPY/D/H/omega'     : Item(verb='Sending'), # Redoing r15's
                                                    # reverse merge of r8.
     })
  expected_status.remove('A_COPY/D/gamma')

  expected_status.tweak('A_COPY',
                        'A_COPY/D',
                        'A_COPY/D/H/omega',
                        wc_rev=17)
  expected_status.add({'A_COPY/D/gamma_moved' : Item(status='  ', wc_rev=17)})
  svntest.actions.run_and_verify_commit(wc_dir, expected_output,
                                        expected_status, None, wc_dir)

  # r18 - C) Text mod to A/D/gamma_moved
  svntest.main.file_write(gamma_moved_path, "Even newer content")
  expected_output = wc.State(wc_dir, {'A/D/gamma_moved' : Item(verb='Sending')})
  expected_status.tweak('A/D/gamma_moved', wc_rev=18)
  svntest.actions.run_and_verify_commit(wc_dir, expected_output,
                                        expected_status, None, wc_dir)

  # r19 - D) Synch merge from A to A_COPY
  svntest.actions.run_and_verify_svn(
    None,
    expected_merge_output([[17,18], [2,18]],
                          ['U    ' + gamma_moved_COPY_path + '\n',
                           ' U   ' + A_COPY_path + '\n',
                           ' U   ' + D_COPY_path + '\n',
                           ' U   ' + gamma_moved_COPY_path + '\n']),
    [], 'merge', '--allow-mixed-revisions', sbox.repo_url + '/A',  A_COPY_path)
  expected_output = wc.State(
    wc_dir,
    {'A_COPY'               : Item(verb='Sending'), # Mergeinfo update
     'A_COPY/D'             : Item(verb='Sending'), # Mergeinfo update
     'A_COPY/D/gamma_moved' : Item(verb='Sending'), # Text change
     })
  expected_status.tweak('A_COPY',
                        'A_COPY/D',
                        'A_COPY/D/gamma_moved',
                        wc_rev=19)
  svntest.actions.run_and_verify_commit(wc_dir, expected_output,
                                        expected_status, None, wc_dir)

  # Reintegrate A_COPY to A, this should work since
  # A_COPY/D/gamma_moved's natural history,
  #
  #   /A/D/gamma:1-15
  #   /A/D/gamma_moved:16
  #   /A_COPY/D/gamma_moved:17-19
  #
  # shows that it is fully synched up with trunk.
  svntest.actions.run_and_verify_svn(None, exp_noop_up_out(19), [], 'up',
                                     wc_dir)
  expected_output = wc.State(A_path, {
    'B/E/alpha'     : Item(status='U '),
    'mu'            : Item(status='UU'),
    'D'             : Item(status=' U'),
    'D/gamma_moved' : Item(status=' U'),
    })
  expected_mergeinfo_output = wc.State(A_path, {
    ''              : Item(status=' U'),
    'mu'            : Item(status=' G'),
    'D'             : Item(status=' U'),
    'D/gamma_moved' : Item(status=' G'), # More issue #4309 (see above)
    })
  expected_elision_output = wc.State(A_path, {
    })
  expected_A_status = wc.State(A_path, {
    ''              : Item(status=' M'),
    'B'             : Item(status='  '),
    'mu'            : Item(status='MM'),
    'B/E'           : Item(status='  '),
    'B/E/alpha'     : Item(status='M '),
    'B/E/beta'      : Item(status='  '),
    'B/lambda'      : Item(status='  '),
    'B/F'           : Item(status='  '),
    'C'             : Item(status='  '),
    'D'             : Item(status=' M'),
    'D/G'           : Item(status='  '),
    'D/G/pi'        : Item(status='  '),
    'D/G/rho'       : Item(status='  '),
    'D/G/tau'       : Item(status='  '),
    'D/gamma_moved' : Item(status=' M'),
    'D/H'           : Item(status='  '),
    'D/H/chi'       : Item(status='  '),
    'D/H/psi'       : Item(status='  '),
    'D/H/omega'     : Item(status='  '),
    })
  expected_A_status.tweak(wc_rev=19)
  expected_A_disk = wc.State('', {
    ''          : Item(props={SVN_PROP_MERGEINFO : '/A_COPY:2-19'}),
    'B'         : Item(),
    'mu'        : Item("New content",
                       props={SVN_PROP_MERGEINFO :
                              '/A_COPY/mu:2-19\n/A_COPY_2/mu:11'}),
    'B/E'           : Item(),
    'B/E/alpha'     : Item("New content"),
    'B/E/beta'      : Item("New content"),
    'B/lambda'      : Item("This is the file 'lambda'.\n"),
    'B/F'           : Item(),
    'C'             : Item(),
    'D'             : Item(props={SVN_PROP_MERGEINFO :
                                  '/A_COPY/D:2-19\n/A_COPY_3/D:9'}),
    'D/G'           : Item(),
    'D/G/pi'        : Item("This is the file 'pi'.\n"),
    'D/G/rho'       : Item("New content"),
    'D/G/tau'       : Item("This is the file 'tau'.\n"),
    # What's with all this mergeinfo?
    #
    # '/A/D/gamma_moved:2-7,9-12' - Incoming from the merge source.  Yes,
    # this mergeinfo describes non-existent path-revs, this is the effect
    # of issue #3669 'inheritance can result in mergeinfo describing
    # nonexistent sources', but there is already a test for that issue so
    # we tolerate it here.
    #
    # '/A_COPY/D/gamma_moved:17-19' - Describes the merge performed.
    #
    # '/A_COPY_3/D/gamma:9' - Explicit prior to the merge.
    #
    #'/A_COPY_3/D/gamma_moved:9' - Incoming from the merge source.
    # For the curious, this was originally created in r17 when we merged
    # ^/A to A_COPY.  This merge added A_COPY/D/gamma_moved, which had
    # explicit mergeinfo and due to issue #4309 'wrong notification and
    # bogus mergeinfo during merge which adds subtree with mergeinfo'
    # this file inherited this bogus mergeinfo from A_COPY/D.  Yes, this
    # is all quite ugly as the intersection or multiple known issues
    # is likely to be.  However, given that none of this mergeinfo is
    # particularly harmful and that this test is *not* about issues #3669
    # or #4309, we are tolerting it.
    'D/gamma_moved' : Item(
      "Even newer content", props={SVN_PROP_MERGEINFO :
                                   '/A/D/gamma_moved:2-7,9-12\n'
                                   '/A_COPY/D/gamma_moved:17-19\n'
                                   '/A_COPY_3/D/gamma:9\n'
                                   '/A_COPY_3/D/gamma_moved:9'}),
    'D/H'           : Item(),
    'D/H/chi'       : Item("This is the file 'chi'.\n"),
    'D/H/psi'       : Item("New content"),
    'D/H/omega'     : Item("New content"),
    })
  expected_A_skip = wc.State(A_COPY_path, {})
  run_and_verify_reintegrate(A_path,
                                       sbox.repo_url + '/A_COPY',
                                       expected_output,
                                       expected_mergeinfo_output,
                                       expected_elision_output,
                                       expected_A_disk,
                                       expected_A_status,
                                       expected_A_skip,
                                       None, 1, 1)

#----------------------------------------------------------------------
@SkipUnless(server_has_mergeinfo)
def multiple_reintegrates_from_the_same_branch(sbox):
  "multiple reintegrates create self-referential"

  # Make A_COPY branch in r2, and do a few more commits to A in r3-6.
  sbox.build()
  wc_dir = sbox.wc_dir
  expected_disk, expected_status = set_up_branch(sbox)

  # Some paths we'll care about
  A_path              = sbox.ospath('A')
  mu_path             = sbox.ospath('A/mu')
  A_COPY_path         = sbox.ospath('A_COPY')
  psi_COPY_path       = sbox.ospath('A_COPY/D/H/psi')
  Feature_branch_path = sbox.ospath('A_FEATURE_BRANCH')
  Feature_beta_path   = os.path.join(wc_dir, "A_FEATURE_BRANCH", "B", "E",
                                     "beta")

  # Create a feature branch and do multiple reintegrates from the branch
  # without deleting and recreating it.  We don't recommend doing this,
  # but regardless, it shouldn't create self-referential mergeinfo on
  # the reintegrate target.
  #
  # r7 - Create the feature branch.
  svntest.actions.run_and_verify_svn(None, None, [], 'up', wc_dir)
  svntest.actions.run_and_verify_svn(None, None, [],
                                     'copy', A_path, Feature_branch_path)
  svntest.actions.run_and_verify_svn(None, None, [],
                                     'ci', '-m', 'Make a feature branch',
                                     wc_dir)

  # r8 - Make a change under 'A'.
  svntest.main.file_write(mu_path, "New trunk content.\n")
  svntest.actions.run_and_verify_svn(None, None, [], 'ci', '-m',
                                     "A text change under 'A'",
                                     wc_dir)

  # r9 - Make a change on the feature branch.
  svntest.main.file_write(Feature_beta_path, "New branch content.\n")
  svntest.actions.run_and_verify_svn(None, None, [], 'ci', '-m',
                                     "A text change on the feature branch",
                                     wc_dir)

  # r10 - Sync merge all changes from 'A' to the feature branch.
  svntest.actions.run_and_verify_svn(None, None, [], 'up', wc_dir)
  svntest.actions.run_and_verify_svn(None, None, [], 'merge',
                                     sbox.repo_url + '/A',
                                     Feature_branch_path)
  svntest.actions.run_and_verify_svn(None, None, [], 'ci', '-m',
                                     "Sync merge 'A' to feature branch",
                                     wc_dir)

  # r11 - Reintegrate the feature branch back to 'A'.
  svntest.actions.run_and_verify_svn(None, None, [], 'up', wc_dir)
  run_reintegrate(sbox.repo_url + '/A_FEATURE_BRANCH', A_path)
  svntest.actions.run_and_verify_svn(None, None, [], 'ci', '-m',
                                     "Reintegrate feature branch back to 'A'",
                                     wc_dir)

  # r12 - Do a --record-only merge from 'A' to the feature branch so we
  # don't try to merge r11 from trunk during the next sync merge.
  svntest.actions.run_and_verify_svn(None, None, [], 'up', wc_dir)
  svntest.actions.run_and_verify_svn(None, None, [], 'merge', '-c11',
                                     '--record-only',
                                     sbox.repo_url + '/A',
                                     Feature_branch_path)
  svntest.actions.run_and_verify_svn(None, None, [], 'ci', '-m',
                                     "Sync merge 'A' to feature branch",
                                     wc_dir)

  # r13 - Make another change on the feature branch.
  svntest.main.file_write(Feature_beta_path, "Even newer branch content.\n")
  svntest.actions.run_and_verify_svn(None, None, [], 'ci', '-m',
                                     "Different text on the feature branch",
                                     wc_dir)

  # r14 - Sync merge all changes from 'A' to the feature branch in
  # preparation for a second reintegrate from this branch.
  svntest.actions.run_and_verify_svn(None, None, [], 'up', wc_dir)
  svntest.actions.run_and_verify_svn(None, None, [], 'merge',
                                     sbox.repo_url + '/A',
                                     Feature_branch_path)
  svntest.actions.run_and_verify_svn(None, None, [], 'ci', '-m',
                                     "2nd Sync merge 'A' to feature branch",
                                     wc_dir)

  # r15 - Reintegrate the feature branch back to 'A' a second time.
  # No self-referential mergeinfo should be applied on 'A'.
  svntest.actions.run_and_verify_svn(None, None, [], 'up', wc_dir)
  expected_output = wc.State(A_path, {
     #'' : Item(status=' U'), #<-- no self-referential mergeinfo applied!
    'B/E/beta' : Item(status='U '),
    })
  expected_mergeinfo_output = wc.State(A_path, {
    '' : Item(status=' U'),
    })
  expected_elision_output = wc.State(A_path, {
    })
  expected_status = wc.State(A_path, {
    ''          : Item(status=' M'),
    'B'         : Item(status='  '),
    'mu'        : Item(status='  '),
    'B/E'       : Item(status='  '),
    'B/E/alpha' : Item(status='  '),
    'B/E/beta'  : Item(status='M '),
    'B/lambda'  : Item(status='  '),
    'B/F'       : Item(status='  '),
    'C'         : Item(status='  '),
    'D'         : Item(status='  '),
    'D/G'       : Item(status='  '),
    'D/G/pi'    : Item(status='  '),
    'D/G/rho'   : Item(status='  '),
    'D/G/tau'   : Item(status='  '),
    'D/gamma'   : Item(status='  '),
    'D/H'       : Item(status='  '),
    'D/H/chi'   : Item(status='  '),
    'D/H/psi'   : Item(status='  '),
    'D/H/omega' : Item(status='  '),
    })
  expected_status.tweak(wc_rev=14)
  expected_disk = wc.State('', {
    ''          : Item(props={SVN_PROP_MERGEINFO :
                              # Prior to r????? we'd get this
                              # self-referential mergeinfo:
                              #'/A:2-6\n/A_FEATURE_BRANCH:7-14'}),
                              '/A_FEATURE_BRANCH:7-14'}),
    'B'         : Item(),
    'mu'        : Item("New trunk content.\n"),
    'B/E'       : Item(),
    'B/E/alpha' : Item("This is the file 'alpha'.\n"),
    'B/E/beta'  : Item("Even newer branch content.\n"),
    'B/lambda'  : Item("This is the file 'lambda'.\n"),
    'B/F'       : Item(),
    'C'         : Item(),
    'D'         : Item(),
    'D/G'       : Item(),
    'D/G/pi'    : Item("This is the file 'pi'.\n"),
    'D/G/rho'   : Item("New content"),
    'D/G/tau'   : Item("This is the file 'tau'.\n"),
    'D/gamma'   : Item("This is the file 'gamma'.\n"),
    'D/H'       : Item(),
    'D/H/chi'   : Item("This is the file 'chi'.\n"),
    'D/H/psi'   : Item("New content"),
    'D/H/omega' : Item("New content"),
    })
  expected_skip = wc.State(A_path, { })
  run_and_verify_reintegrate(A_path,
                                       sbox.repo_url + '/A_FEATURE_BRANCH',
                                       expected_output,
                                       expected_mergeinfo_output,
                                       expected_elision_output,
                                       expected_disk,
                                       expected_status,
                                       expected_skip,
                                       None, 1, 1)
  svntest.actions.run_and_verify_svn(None, None, [], 'ci', '-m',
                                     "2nd Reintegrate feature branch back to 'A'",
                                     wc_dir)

  # Demonstrate the danger of any self-referential mergeinfo on trunk.
  #
  # Merge all available revisions except r3 from 'A' to 'A_COPY'.
  svntest.actions.run_and_verify_svn(None, None, [], 'up', wc_dir)
  svntest.actions.run_and_verify_svn(None, None, [], 'merge', '-r3:HEAD',
                                     sbox.repo_url + '/A',
                                     A_COPY_path)
  svntest.actions.run_and_verify_svn(None, None, [], 'ci', '-m',
                                     "Merge -r3:HEAD from 'A' to 'A_COPY'",
                                     wc_dir)
  # No self-referential mergeinfo should have been carried on 'A_COPY' from
  # 'A' that would prevent the following merge from being operative.
  svntest.actions.run_and_verify_svn(
    None,
    expected_merge_output([[2,3],[2,16]],
                          ['U    ' + psi_COPY_path + '\n',
                           ' U   ' + A_COPY_path   + '\n',]),
    [], 'merge', '--allow-mixed-revisions', sbox.repo_url + '/A', A_COPY_path)

#----------------------------------------------------------------------
# Test for a reintegrate bug which can occur when the merge source
# has mergeinfo that explicitly describes common history with the reintegrate
# target, see http://svn.haxx.se/dev/archive-2009-12/0338.shtml
#
# Also tests Issue #3591 'reintegrate merges update subtree mergeinfo
# unconditionally'.
@Issue(3591)
def reintegrate_with_self_referential_mergeinfo(sbox):
  "source has target's history as explicit mergeinfo"

  sbox.build()
  wc_dir = sbox.wc_dir

  # Make some changes under 'A' in r2-5.
  wc_disk, wc_status = set_up_branch(sbox, nbr_of_branches=0)

  # Some paths we'll care about
  A_path       = sbox.ospath('A')
  A2_path      = sbox.ospath('A2')
  A2_B_path    = sbox.ospath('A2/B')
  A2_1_path    = sbox.ospath('A2.1')
  A2_1_mu_path = sbox.ospath('A2.1/mu')

  # r6 Copy A to A2 and then manually set some self-referential mergeinfo on
  # A2/B and A2.
  svntest.actions.run_and_verify_svn(None, exp_noop_up_out(5), [],
                                     'up', wc_dir)
  svntest.actions.run_and_verify_svn(None, None, [],
                                     'copy', A_path, A2_path)
  # /A:3 describes A2's natural history, a.k.a. it's implicit mergeinfo, so
  # it is self-referential.  Same for /A/B:4 and A2/B.  Normally this is
  # redundant but not harmful.
  svntest.actions.run_and_verify_svn(None, None, [],
                                     'ps', 'svn:mergeinfo', '/A:3', A2_path)
  svntest.actions.run_and_verify_svn(None, None, [],
                                     'ps', 'svn:mergeinfo', '/A/B:4', A2_B_path)
  svntest.actions.run_and_verify_svn(
    None, None, [], 'ci', '-m',
    'copy A to A2 and set some self-referential mergeinfo on the latter.',
    wc_dir)

  # r7 Copy A2 to A2.1
  svntest.actions.run_and_verify_svn(None, None, [],
                                     'copy', A2_path, A2_1_path)
  svntest.actions.run_and_verify_svn(None, None, [], 'ci',
                                     '-m', 'copy A2to A2.1.', wc_dir)

  # r8 Make a change on A2.1/mu
  svntest.main.file_write(A2_1_mu_path, 'New A2.1 stuff')
  svntest.actions.run_and_verify_svn(None, None, [], 'ci',
                                     '-m', 'Work done on the A2.1 branch.',
                                     wc_dir)

  # Update to uniform revision and reintegrate A2.1 back to A2.
  # Note that the mergeinfo on A2/B is not changed by the reintegration
  # and so is not expected to by updated to describe the merge.
  svntest.actions.run_and_verify_svn(None, exp_noop_up_out(8), [],
                                     'up', wc_dir)
  expected_output = wc.State(A2_path, {
    'mu' : Item(status='U '),
    })
  expected_mergeinfo_output = wc.State(A2_path, {
    ''  : Item(status=' U'),
    })
  expected_elision_output = wc.State(A2_path, {
    })
  expected_status = wc.State(A2_path, {
    ''          : Item(status=' M'),
    'B'         : Item(status='  '),
    'mu'        : Item(status='M '),
    'B/E'       : Item(status='  '),
    'B/E/alpha' : Item(status='  '),
    'B/E/beta'  : Item(status='  '),
    'B/lambda'  : Item(status='  '),
    'B/F'       : Item(status='  '),
    'C'         : Item(status='  '),
    'D'         : Item(status='  '),
    'D/G'       : Item(status='  '),
    'D/G/pi'    : Item(status='  '),
    'D/G/rho'   : Item(status='  '),
    'D/G/tau'   : Item(status='  '),
    'D/gamma'   : Item(status='  '),
    'D/H'       : Item(status='  '),
    'D/H/chi'   : Item(status='  '),
    'D/H/psi'   : Item(status='  '),
    'D/H/omega' : Item(status='  '),
    })
  expected_status.tweak(wc_rev=8)
  expected_disk = wc.State('', {
    ''          : Item(props={SVN_PROP_MERGEINFO : '/A:3\n/A2.1:7-8'}),
    'B'         : Item(props={SVN_PROP_MERGEINFO : '/A/B:4'}),
    'mu'        : Item("New A2.1 stuff"),
    'B/E'       : Item(),
    'B/E/alpha' : Item("This is the file 'alpha'.\n"),
    'B/E/beta'  : Item("New content"),
    'B/lambda'  : Item("This is the file 'lambda'.\n"),
    'B/F'       : Item(),
    'C'         : Item(),
    'D'         : Item(),
    'D/G'       : Item(),
    'D/G/pi'    : Item("This is the file 'pi'.\n"),
    'D/G/rho'   : Item("New content"),
    'D/G/tau'   : Item("This is the file 'tau'.\n"),
    'D/gamma'   : Item("This is the file 'gamma'.\n"),
    'D/H'       : Item(),
    'D/H/chi'   : Item("This is the file 'chi'.\n"),
    'D/H/psi'   : Item("New content"),
    'D/H/omega' : Item("New content"),
    })
  expected_skip = wc.State(A2_path, { })
  # Previously failed with this error:
  #
  #   svn merge ^/A2.1" A2 --reintegrate
  #  ..\..\..\subversion\svn\merge-cmd.c:349: (apr_err=160013)
  #  ..\..\..\subversion\libsvn_client\merge.c:9219: (apr_err=160013)
  #  ..\..\..\subversion\libsvn_client\ra.c:728: (apr_err=160013)
  #  ..\..\..\subversion\libsvn_client\mergeinfo.c:733: (apr_err=160013)
  #  ..\..\..\subversion\libsvn_client\ra.c:526: (apr_err=160013)
  #  ..\..\..\subversion\libsvn_repos\rev_hunt.c:908: (apr_err=160013)
  #  ..\..\..\subversion\libsvn_repos\rev_hunt.c:607: (apr_err=160013)
  #  ..\..\..\subversion\libsvn_fs_fs\tree.c:2886: (apr_err=160013)
  #  ..\..\..\subversion\libsvn_fs_fs\tree.c:669: (apr_err=160013)
  #  svn: File not found: revision 4, path '/A2'
  run_and_verify_reintegrate(A2_path,
                                       sbox.repo_url + '/A2.1',
                                       expected_output,
                                       expected_mergeinfo_output,
                                       expected_elision_output,
                                       expected_disk,
                                       expected_status,
                                       expected_skip,
                                       None, 1, 0)

#----------------------------------------------------------------------
# Test for issue #3577 '1.7 subtree mergeinfo recording breaks reintegrate'
# and issue #4329 'automatic merge uses reintegrate type merge if source is
# fully synced'.
@Issue(3577,4329)
@SkipUnless(server_has_mergeinfo)
def reintegrate_with_subtree_merges(sbox):
  "reintegrate with prior subtree merges to source"

  # Create a standard greek tree, branch A to A_COPY in r2, and make
  # some changes under A in r3-6.
  sbox.build()
  wc_dir = sbox.wc_dir
  expected_disk, expected_status = set_up_branch(sbox)

  # Some paths we'll care about
  A_path        = sbox.ospath('A')
  psi_path      = sbox.ospath('A/D/H/psi')
  mu_COPY_path  = sbox.ospath('A_COPY/mu')
  A_COPY_path   = sbox.ospath('A_COPY')
  B_COPY_path   = sbox.ospath('A_COPY/B')
  rho_COPY_path = sbox.ospath('A_COPY/D/G/rho')
  H_COPY_path   = sbox.ospath('A_COPY/D/H')

  # r7 - Make a change on the A_COPY branch that will be
  # reintegrated back to A.
  svntest.main.file_write(mu_COPY_path, "branch work")
  svntest.main.run_svn(None, 'commit', '-m',
                       'Some work on the A_COPY branch', wc_dir)

  # Update the WC to a uniform revision, then merge all of the changes
  # from A to A_COPY, but do it via subtree merges so the mergeinfo
  # record of the merges insn't neatly reflected in the root of the
  # branch.  Commit the merge as r8.
  svntest.actions.run_and_verify_svn(None, None, [], 'up', wc_dir)
  svntest.actions.run_and_verify_svn(None, None, [], 'merge', '-c5',
                                     sbox.repo_url + '/A/B',
                                     B_COPY_path)
  svntest.actions.run_and_verify_svn(None, None, [], 'merge', '-c4',
                                     sbox.repo_url + '/A/D/G/rho',
                                     rho_COPY_path)
  svntest.actions.run_and_verify_svn(None, None, [], 'merge', '-c3',
                                     sbox.repo_url + '/A/D/H',
                                     H_COPY_path)
  svntest.actions.run_and_verify_svn(None, None, [], 'merge', '-c6',
                                     sbox.repo_url + '/A',
                                     A_COPY_path)
  svntest.actions.run_and_verify_svn(None, None, [], 'commit', '-m',
                                     'Merge everything from A to A_COPY',
                                     wc_dir)

  # Now update the WC and try to reintegrate.  Since we really have merged
  # everything from A to A_COPY, even though it was done via subtree merges,
  # the reintegrate should succeed.  Previously it failed because the naive
  # interpretation of the mergeinfo on A_COPY didn't reflect that it was
  # fully synced with A, resulting in this error:
  #
  #    svn merge ^/A_COPY A --reintegrate
  #    ..\..\..\subversion\svn\merge-cmd.c:358: (apr_err=195016)
  #    ..\..\..\subversion\libsvn_client\merge.c:9318: (apr_err=195016)
  #    svn: Reintegrate can only be used if revisions 2 through 7 were
  #    previously merged from file:///C%3A/SVN/src-trunk-2/Debug/subversion
  #    /tests/cmdline/svn-test-work/repositories/merge_tests-142/A to the
  #     reintegrate source, but this is not the case:
  #      A_COPY
  #        Missing ranges: /A:2-5
  #      A_COPY/B
  #        Missing ranges: /A/B:2-4,6
  #      A_COPY/D/G/rho
  #        Missing ranges: /A/D/G/rho:2-3,5-6
  #      A_COPY/D/H
  #        Missing ranges: /A/D/H:2,4-5
  svntest.actions.run_and_verify_svn(None, None, [], 'up', wc_dir)
  expected_output = wc.State(A_path, {
    'mu' : Item(status='U '),
    })
  expected_mergeinfo_output = wc.State(A_path, {
    '' : Item(status=' U'),
    })
  expected_elision_output = wc.State(A_path, {
    })
  expected_A_status = wc.State(A_path, {
    ''          : Item(status=' M'),
    'B'         : Item(status='  '),
    'mu'        : Item(status='M '),
    'B/E'       : Item(status='  '),
    'B/E/alpha' : Item(status='  '),
    'B/E/beta'  : Item(status='  '),
    'B/lambda'  : Item(status='  '),
    'B/F'       : Item(status='  '),
    'C'         : Item(status='  '),
    'D'         : Item(status='  '),
    'D/G'       : Item(status='  '),
    'D/G/pi'    : Item(status='  '),
    'D/G/rho'   : Item(status='  '),
    'D/G/tau'   : Item(status='  '),
    'D/gamma'   : Item(status='  '),
    'D/H'       : Item(status='  '),
    'D/H/chi'   : Item(status='  '),
    'D/H/psi'   : Item(status='  '),
    'D/H/omega' : Item(status='  '),
    })
  expected_A_status.tweak(wc_rev=8)
  expected_A_disk = wc.State('', {
    ''          : Item(props={SVN_PROP_MERGEINFO : '/A_COPY:2-8'}),
    'B'         : Item(),
    'mu'        : Item("branch work"),
    'B/E'       : Item(),
    'B/E/alpha' : Item("This is the file 'alpha'.\n"),
    'B/E/beta'  : Item("New content"),
    'B/lambda'  : Item("This is the file 'lambda'.\n"),
    'B/F'       : Item(),
    'C'         : Item(),
    'D'         : Item(),
    'D/G'       : Item(),
    'D/G/pi'    : Item("This is the file 'pi'.\n"),
    'D/G/rho'   : Item("New content"),
    'D/G/tau'   : Item("This is the file 'tau'.\n"),
    'D/gamma'   : Item("This is the file 'gamma'.\n"),
    'D/H'       : Item(),
    'D/H/chi'   : Item("This is the file 'chi'.\n"),
    'D/H/psi'   : Item("New content"),
    'D/H/omega' : Item("New content"),
    })
  expected_A_skip = wc.State(A_COPY_path, {})
  run_and_verify_reintegrate(A_path,
                             sbox.repo_url + '/A_COPY',
                             expected_output,
                             expected_mergeinfo_output,
                             expected_elision_output,
                             expected_A_disk,
                             expected_A_status,
                             expected_A_skip,
                             None, 1, 1)

  # Test issue #4329.  Revert previous merge and commit a new edit to
  # A/D/H/psi. Attempt the same merge without the --reintegrate option.
  # It should succeed because the automatic merge code should detect that
  # a reintegrate-style merge is required, that merge should succeed and
  # there should be not conflict on A/D/H/psi.
  svntest.actions.run_and_verify_svn(None, None, [], 'revert', '-R', wc_dir)
  svntest.main.file_write(psi_path, "Non-conflicting trunk edit.\n")
  svntest.main.run_svn(None, 'commit', '-m',
                       'An edit on trunk prior to reintegrate.', wc_dir)
  sbox.simple_update()
  expected_A_status.tweak(wc_rev=9)
  expected_A_disk.tweak('', props={SVN_PROP_MERGEINFO: '/A_COPY:2-9'})
  expected_A_disk.tweak('D/H/psi', contents='Non-conflicting trunk edit.\n')
  svntest.actions.run_and_verify_merge(A_path, None, None,
                                       sbox.repo_url + '/A_COPY', None,
                                       expected_output,
                                       expected_mergeinfo_output,
                                       expected_elision_output,
                                       expected_A_disk, expected_A_status,
                                       expected_A_skip, None, None, None,
                                       None, None, True, False, A_path)

#----------------------------------------------------------------------
# Test for issue #3654 'added subtrees with mergeinfo break reintegrate'.
@Issue(3654)
def added_subtrees_with_mergeinfo_break_reintegrate(sbox):
  "added subtrees with mergeinfo break reintegrate"

  sbox.build()
  wc_dir = sbox.wc_dir

  # Some paths we'll care about
  A_path           = sbox.ospath('A')
  nu_path          = sbox.ospath('A/C/nu')
  mu_path          = sbox.ospath('A/mu')
  A_COPY_path      = sbox.ospath('A_COPY')
  lambda_COPY_path = sbox.ospath('A_COPY/B/lambda')
  A_COPY_2_path    = sbox.ospath('A_COPY_2')
  nu_COPY_2_path   = sbox.ospath('A_COPY_2/C/nu')

  # Branch A@1 to A_COPY and A_COPY_2 in r2 and r3 respectively.
  # Make some changes under 'A' in r4-7.
  wc_disk, wc_status = set_up_branch(sbox, nbr_of_branches=2)

  # r8 - Add a new file A_COPY_2/C/nu.
  svntest.main.file_write(nu_COPY_2_path, "This is the file 'nu'.\n")
  svntest.actions.run_and_verify_svn(None, None, [], 'add', nu_COPY_2_path)
  svntest.actions.run_and_verify_svn(None, None, [], 'ci',
                                     '-m', 'Add new file in A_COPY_2 branch',
                                     wc_dir)


  # r9 - Cyclic cherry pick merge r8 from A_COPY_2 back to A.
  svntest.actions.run_and_verify_svn(None, None, [], 'up', wc_dir)
  svntest.actions.run_and_verify_svn(None, svntest.verify.AnyOutput, [],
                                     'merge', '-c', '8',
                                     sbox.repo_url + '/A_COPY_2',
                                     A_path)
  svntest.actions.run_and_verify_svn(None, None, [], 'ci',
                                     '-m', 'Merge r8 from A_COPY_2 to A.',
                                     wc_dir)

  # r10 - Make an edit to A_COPY_2/C/nu.
  svntest.main.file_write(nu_COPY_2_path, "A_COPY_2 edit to file 'nu'.\n")
  svntest.actions.run_and_verify_svn(None, None, [], 'ci',
                                     '-m', 'Edit new file on A_COPY_2 branch',
                                     wc_dir)

  # r11 - Cyclic subtree cherry pick merge r10 from A_COPY_2/C/nu
  # back to A/C/nu.
  svntest.actions.run_and_verify_svn(None, svntest.verify.AnyOutput, [],
                                     'merge', '-c', '10',
                                     sbox.repo_url + '/A_COPY_2/C/nu',
                                     nu_path)
  svntest.actions.run_and_verify_svn(None, None, [], 'ci', '-m',
                                     'Merge r8 from A_COPY_2/C/nu to A/C/nu.',
                                     wc_dir)

  # r12 - Edit under A_COPY.
  svntest.main.file_write(mu_path, "mu edits on A_COPY.\n")
  svntest.actions.run_and_verify_svn(None, None, [], 'ci',
                                     '-m', 'Work on A_COPY branch.',
                                     wc_dir)

  # r13 - Sync merge A to A_COPY in preparation for reintegrate.
  svntest.actions.run_and_verify_svn(None, None, [], 'up', wc_dir)
  svntest.actions.run_and_verify_svn(None, svntest.verify.AnyOutput, [],
                                     'merge', sbox.repo_url + '/A', A_COPY_path)
  svntest.actions.run_and_verify_svn(None, None, [], 'ci', '-m',
                                     'Prep for reintegrate: Sync A to A_COPY.',
                                     wc_dir)

  # r14 - Reintegrate A_COPY to A.
  svntest.actions.run_and_verify_svn(None, None, [], 'up', wc_dir)
  run_reintegrate(sbox.repo_url + '/A_COPY', A_path)
  svntest.actions.run_and_verify_svn(None, None, [], 'ci', '-m',
                                     'Reintegrate A_COPY to A.',
                                     wc_dir)

  # r15 - Delete A_COPY.
  svntest.actions.run_and_verify_svn(None, svntest.verify.AnyOutput, [],
                                     'delete', A_COPY_path)
  svntest.actions.run_and_verify_svn(None, None, [], 'ci', '-m',
                                     'Delete A_COPY branch', wc_dir)

  # r16 - Create new A_COPY from A@HEAD=15.
  #
  # Update so we copy HEAD:
  svntest.actions.run_and_verify_svn(None, None, [], 'up', wc_dir)
  svntest.actions.run_and_verify_svn(None, svntest.verify.AnyOutput, [],
                                     'copy', A_path, A_COPY_path)
  svntest.actions.run_and_verify_svn(None, None, [], 'ci', '-m',
                                     'Create new A_COPY branch from A', wc_dir)

  # r17 - Unrelated edits under both A and A_COPY.
  svntest.main.file_write(nu_path, "Trunk work on nu.\n")
  svntest.main.file_write(lambda_COPY_path, "lambda edit on A_COPY.\n")
  svntest.actions.run_and_verify_svn(None, None, [], 'ci', '-m',
                                     'Unrelated edits on A and A_COPY branch.',
                                     wc_dir)

  # r18 - Sync A to A_COPY in preparation for another reintegrate.
  svntest.actions.run_and_verify_svn(None, None, [], 'up', wc_dir)
  svntest.actions.run_and_verify_svn(None, svntest.verify.AnyOutput, [],
                                     'merge', sbox.repo_url + '/A', A_COPY_path)
  svntest.actions.run_and_verify_svn(None, None, [], 'ci', '-m',
                                     'Prep for reintegrate: Sync A to A_COPY.',
                                     wc_dir)

  # Reintegrate A_COPY back to A.  We just synced A_COPY with A, so this
  # should work.  The only text change should be the change made to
  # A_COPY/B/lambda in r17 after the new A_COPY was created.
  svntest.actions.run_and_verify_svn(None, None, [], 'up', wc_dir)
  expected_output = wc.State(A_path, {
    ''         : Item(status=' U'),
    'B/lambda' : Item(status='U '),
    'C/nu'     : Item(status=' U'),
    })
  expected_mergeinfo_output = wc.State(A_path, {
    ''     : Item(status=' U'),
    'C/nu' : Item(status=' U'),
    })
  expected_elision_output = wc.State(A_path, {
    })
  expected_status = wc.State(A_path, {
    ''          : Item(status=' M'),
    'B'         : Item(status='  '),
    'mu'        : Item(status='  '),
    'B/E'       : Item(status='  '),
    'B/E/alpha' : Item(status='  '),
    'B/E/beta'  : Item(status='  '),
    'B/lambda'  : Item(status='M '),
    'B/F'       : Item(status='  '),
    'C'         : Item(status='  '),
    'C/nu'      : Item(status=' M'),
    'D'         : Item(status='  '),
    'D/G'       : Item(status='  '),
    'D/G/pi'    : Item(status='  '),
    'D/G/rho'   : Item(status='  '),
    'D/G/tau'   : Item(status='  '),
    'D/gamma'   : Item(status='  '),
    'D/H'       : Item(status='  '),
    'D/H/chi'   : Item(status='  '),
    'D/H/psi'   : Item(status='  '),
    'D/H/omega' : Item(status='  '),
    })
  expected_status.tweak(wc_rev=18)
  expected_disk = wc.State('', {
    ''          : Item(props={SVN_PROP_MERGEINFO :
                              '/A_COPY:2-13,16-18\n'
                              #         ^     ^
                              #         |     |
                              #   from _|     |
                              #    1st        |
                              # reintegrate   |
                              #               |
                              #        from this reintegrate
                              #
                              '/A_COPY_2:8'}), # <-- From cyclic merge in r9
    'B'         : Item(),
    'mu'        : Item("mu edits on A_COPY.\n"), # From earlier reintegrate.
    'B/E'       : Item(),
    'B/E/alpha' : Item("This is the file 'alpha'.\n"),
    'B/E/beta'  : Item("New content"),
    'B/lambda'  : Item("lambda edit on A_COPY.\n"), # From this reintegrate.
    'B/F'       : Item(),
    'C'         : Item(),
    'C/nu'      : Item("Trunk work on nu.\n",
                       props={SVN_PROP_MERGEINFO :
                              '/A_COPY/C/nu:13,16-18\n'
                              '/A_COPY_2/C/nu:10'}), # <-- From cyclic
                                                     # merge in r11
    'D'         : Item(),
    'D/G'       : Item(),
    'D/G/pi'    : Item("This is the file 'pi'.\n"),
    'D/G/rho'   : Item("New content"),
    'D/G/tau'   : Item("This is the file 'tau'.\n"),
    'D/gamma'   : Item("This is the file 'gamma'.\n"),
    'D/H'       : Item(),
    'D/H/chi'   : Item("This is the file 'chi'.\n"),
    'D/H/psi'   : Item("New content"),
    'D/H/omega' : Item("New content"),
    })
  expected_skip = wc.State(A_COPY_path, {})
  run_and_verify_reintegrate(A_path,
                                       sbox.repo_url + '/A_COPY',
                                       expected_output,
                                       expected_mergeinfo_output,
                                       expected_elision_output,
                                       expected_disk,
                                       expected_status,
                                       expected_skip,
                                       None, 1, 1)

#----------------------------------------------------------------------
# Test for issue #3648 '2-URL merges incorrectly reverse-merge mergeinfo
# for merge target'.
@Issue(3648)
def two_URL_merge_removes_valid_mergeinfo_from_target(sbox):
  "2-URL merge removes valid mergeinfo from target"

  sbox.build()
  wc_dir = sbox.wc_dir

  # Some paths we'll care about
  lambda_COPY_path = sbox.ospath('A_COPY/B/lambda')
  mu_path          = sbox.ospath('A/mu')
  A_COPY_path      = sbox.ospath('A_COPY')
  A_COPY_2_path    = sbox.ospath('A_COPY_2')

  # Branch A@1 to A_COPY r2
  # Branch A@1 to A_COPY_2 in r3.
  # Make some changes under 'A' in r4-7.
  wc_disk, wc_status = set_up_branch(sbox, nbr_of_branches=2)

  # r8 - A simple text edit on the A_COPY branch.
  svntest.main.file_write(lambda_COPY_path, "Edit on 'branch 1'.\n")
  svntest.actions.run_and_verify_svn(None, None, [], 'ci',
                                     '-m', "Work on 'branch 1'.",
                                     wc_dir)

  # r9 - Sync the A_COPY branch with A up the HEAD (r8).  Now A_COPY
  # differs from A only by the change made in r8 and by the mergeinfo
  # '/A:2-8' on A_COPY which was set to describe the merge.
  svntest.actions.run_and_verify_svn(None, None, [], 'up', wc_dir)
  svntest.actions.run_and_verify_svn(None, svntest.verify.AnyOutput, [],
                                     'merge', sbox.repo_url + '/A', A_COPY_path)
  svntest.actions.run_and_verify_svn(None, None, [], 'ci',
                                     '-m', 'Sync A to A_COPY.',
                                     wc_dir)

  # r10 - A simple text edit on our "trunk" A.
  svntest.main.file_write(mu_path, "Edit on 'trunk'.\n")
  svntest.actions.run_and_verify_svn(None, None, [], 'ci',
                                     '-m', "Work on 'trunk'",
                                     wc_dir)

  # r11 - Sync the A_COPY_2 branch with A up to HEAD (r10).
  svntest.actions.run_and_verify_svn(None, None, [], 'up', wc_dir)
  svntest.actions.run_and_verify_svn(None, svntest.verify.AnyOutput, [],
                                     'merge', sbox.repo_url + '/A',
                                     A_COPY_2_path)
  svntest.actions.run_and_verify_svn(None, None, [], 'ci',
                                     '-m', 'Sync A to A_COPY_2.',
                                     wc_dir)

  # Confirm that the mergeinfo on each branch is what we expect.
  svntest.actions.run_and_verify_svn(None,
                                     [A_COPY_path + ' - /A:2-8\n'],
                                     [], 'pg', SVN_PROP_MERGEINFO,
                                     '-R', A_COPY_path)
  svntest.actions.run_and_verify_svn(None,
                                     [A_COPY_2_path + ' - /A:3-10\n'],
                                     [], 'pg', SVN_PROP_MERGEINFO,
                                     '-R', A_COPY_2_path)

  # Now say we want to apply the changes made on the first branch (A_COPY)
  # to the second branch (A_COPY_2).  One way to do this is a 2-URL merge
  # between A at the revision last synced to A_COPY and A_COPY_2 at HEAD (r11),
  # i.e.:
  #
  #   svn merge ^/A@8 ^/A_COPY@11 A_COPY_2_WC
  #
  # Recall from the note on r9 that this diff is simply the one text change
  # made on branch 1 and some mergeinfo:
  #
  #   >svn diff ^/A@8 ^/A_COPY@11
  #   Index: B/lambda
  #   ===================================================================
  #   --- B/lambda    (.../A) (revision 8)
  #   +++ B/lambda    (.../A_COPY)    (revision 11)
  #   @@ -1 +1 @@
  #   -This is the file 'lambda'.
  #   +Edit on 'branch 1'.
  #
  #   Property changes on: .
  #   ___________________________________________________________________
  #   Added: svn:mergeinfo
  #      Merged /A:r2-8
  #
  # The mergeinfo diff is already represented in A_COPY_2's mergeinfo, so the
  # result of the merge should be the text change to lambda and the addition
  # of mergeinfo showing that the history of A_COPY is now part of A_COPY_2,
  # i.e. '/A_COPY:2-11'
  #
  # Before issue #3648 was fixed this test failed because the valid mergeinfo
  # '/A:r3-8' on A_COPY_2 was removed by the merge.
  svntest.actions.run_and_verify_svn(None, None, [], 'up', wc_dir)
  expected_output = wc.State(A_COPY_2_path, {
    ''         : Item(status=' G'),
    'B/lambda' : Item(status='U '),
    })
  expected_mergeinfo_output = wc.State(A_COPY_2_path, {
    '' : Item(status=' U'),
    })
  expected_elision_output = wc.State(A_COPY_2_path, {
    })
  expected_status = wc.State(A_COPY_2_path, {
    ''          : Item(status=' M'),
    'B'         : Item(status='  '),
    'mu'        : Item(status='  '),
    'B/E'       : Item(status='  '),
    'B/E/alpha' : Item(status='  '),
    'B/E/beta'  : Item(status='  '),
    'B/lambda'  : Item(status='M '),
    'B/F'       : Item(status='  '),
    'C'         : Item(status='  '),
    'D'         : Item(status='  '),
    'D/G'       : Item(status='  '),
    'D/G/pi'    : Item(status='  '),
    'D/G/rho'   : Item(status='  '),
    'D/G/tau'   : Item(status='  '),
    'D/gamma'   : Item(status='  '),
    'D/H'       : Item(status='  '),
    'D/H/chi'   : Item(status='  '),
    'D/H/psi'   : Item(status='  '),
    'D/H/omega' : Item(status='  '),
    })
  expected_status.tweak(wc_rev=11)
  expected_disk = wc.State('', {
    ''          : Item(props={SVN_PROP_MERGEINFO :
                              '/A:3-10\n/A_COPY:2-11'}),
    'B'         : Item(),
    'mu'        : Item("Edit on 'trunk'.\n"),
    'B/E'       : Item(),
    'B/E/alpha' : Item("This is the file 'alpha'.\n"),
    'B/E/beta'  : Item("New content"),
    'B/lambda'  : Item("Edit on 'branch 1'.\n"),
    'B/F'       : Item(),
    'C'         : Item(),
    'D'         : Item(),
    'D/G'       : Item(),
    'D/G/pi'    : Item("This is the file 'pi'.\n"),
    'D/G/rho'   : Item("New content"),
    'D/G/tau'   : Item("This is the file 'tau'.\n"),
    'D/gamma'   : Item("This is the file 'gamma'.\n"),
    'D/H'       : Item(),
    'D/H/chi'   : Item("This is the file 'chi'.\n"),
    'D/H/psi'   : Item("New content"),
    'D/H/omega' : Item("New content"),
    })
  expected_skip = wc.State(A_COPY_path, {})
  svntest.actions.run_and_verify_merge(A_COPY_2_path, 8, 11,
                                       sbox.repo_url + '/A',
                                       sbox.repo_url + '/A_COPY',
                                       expected_output,
                                       expected_mergeinfo_output,
                                       expected_elision_output,
                                       expected_disk,
                                       expected_status,
                                       expected_skip,
                                       None, None, None, None,
                                       None, 1, 1)

#----------------------------------------------------------------------
# Test for issue #3867 'reintegrate merges create mergeinfo for
# non-existent paths'.
@Issue(3867)
def reintegrate_creates_bogus_mergeinfo(sbox):
  "reintegrate creates bogus mergeinfo"

  sbox.build()
  wc_dir=sbox.wc_dir

  mu_path         = sbox.ospath('A/mu')
  lambda_path     = sbox.ospath('A/B/lambda')
  alpha_path      = sbox.ospath('A/B/E/alpha')
  beta_path       = sbox.ospath('A/B/E/beta')
  A_path          = sbox.ospath('A')
  A_path_1        = sbox.ospath('A@1')
  A_COPY_path     = sbox.ospath('A_COPY')
  A_COPY_psi_path = sbox.ospath('A_COPY/D/H/psi')
  A_COPY_url      = sbox.repo_url + "/A_COPY"

  # Make 2 commits under /A pushing the repo to rev3

  svntest.main.file_write(mu_path, "New content.\n")
  svntest.main.run_svn(None, "ci", "-m", "simple text edit", wc_dir)
  svntest.main.file_write(lambda_path, "New content.\n")
  svntest.main.run_svn(None, "ci", "-m", "simple text edit", wc_dir)

  # Branch A@1 as A_COPY in revision 4

  svntest.main.run_svn(None, "cp", A_path_1, A_COPY_path)
  svntest.main.run_svn(None, "ci", "-m", "create a branch", wc_dir)

  # Make a text edit on the branch pushing the repo to r5
  svntest.main.file_write(A_COPY_psi_path, "Branch edit.\n")
  svntest.main.run_svn(None, "ci", "-m", "branch edit", wc_dir)

  # Sync the A_COPY with A in preparation for reintegrate and commit as r6.
  svntest.main.run_svn(None, "up", wc_dir)
  svntest.main.run_svn(None, "merge", sbox.repo_url + "/A", A_COPY_path)
  svntest.main.run_svn(None, "ci", "-m", "sync A_COPY with A", wc_dir)

  # Update the working copy to allow the merge
  svntest.main.run_svn(None, "up", wc_dir)

  # Reintegrate A_COPY to A.  The resulting merginfo on A should be
  # /A_COPY:4-6
  expected_output = wc.State(A_path, {
    'D/H/psi' : Item(status='U '),
    })
  expected_mergeinfo_output = wc.State(A_path, {
    '' : Item(status=' U'),
    })
  expected_elision_output = wc.State(A_path, {
    })
  expected_disk = wc.State('', {
    ''          : Item(props={SVN_PROP_MERGEINFO :
                              '/A_COPY:4-6'}),
    'B'         : Item(),
    'mu'        : Item("New content.\n"),
    'B/E'       : Item(),
    'B/E/alpha' : Item("This is the file 'alpha'.\n"),
    'B/E/beta'  : Item("This is the file 'beta'.\n"),
    'B/lambda'  : Item("New content.\n"),
    'B/F'       : Item(),
    'C'         : Item(),
    'D'         : Item(),
    'D/G'       : Item(),
    'D/G/pi'    : Item("This is the file 'pi'.\n"),
    'D/G/rho'   : Item("This is the file 'rho'.\n"),
    'D/G/tau'   : Item("This is the file 'tau'.\n"),
    'D/gamma'   : Item("This is the file 'gamma'.\n"),
    'D/H'       : Item(),
    'D/H/chi'   : Item("This is the file 'chi'.\n"),
    'D/H/psi'   : Item("Branch edit.\n"),
    'D/H/omega' : Item("This is the file 'omega'.\n"),
    })
  expected_skip = wc.State(A_COPY_path, {})

  run_and_verify_reintegrate(A_path,
                                       A_COPY_url,
                                       expected_output,
                                       expected_mergeinfo_output,
                                       expected_elision_output,
                                       expected_disk, None, expected_skip,
                                       None,
                                       1, 1)


#----------------------------------------------------------------------
# Test for regression on 1.6.x branch, merge fails when source without
# subtree mergeinfo is reintegrated into a target with subtree
# mergeinfo.  Deliberately written in a style that works with the 1.6
# testsuite.
@Issue(3957)
def no_source_subtree_mergeinfo(sbox):
  "source without subtree mergeinfo"

  sbox.build()
  wc_dir=sbox.wc_dir

  svntest.main.file_write(sbox.ospath('A/B/E/alpha'),
                          'AAA\n' +
                          'BBB\n' +
                          'CCC\n')
  svntest.main.run_svn(None, 'commit', '-m', 'log message', wc_dir)
  svntest.main.run_svn(None, 'update', wc_dir)

  # Create branch-1
  svntest.main.run_svn(None, 'copy',
                       sbox.ospath('A/B'),
                       sbox.ospath('A/B1'))
  svntest.main.run_svn(None, 'commit', '-m', 'log message', wc_dir)

  # Create branch-1
  svntest.main.run_svn(None, 'copy',
                       sbox.ospath('A/B'),
                       sbox.ospath('A/B2'))
  svntest.main.run_svn(None, 'commit', '-m', 'log message', wc_dir)

  # Change on trunk
  svntest.main.file_write(sbox.ospath('A/B/E/alpha'),
                          'AAAxx\n' +
                          'BBB\n' +
                          'CCC\n')
  svntest.main.run_svn(None, 'commit', '-m', 'log message', wc_dir)

  # Change on branch-1
  svntest.main.file_write(sbox.ospath('A/B1/E/alpha'),
                          'AAA\n' +
                          'BBBxx\n' +
                          'CCC\n')
  svntest.main.run_svn(None, 'commit', '-m', 'log message', wc_dir)

  # Change on branch-2
  svntest.main.file_write(sbox.ospath('A/B2/E/alpha'),
                          'AAA\n' +
                          'BBB\n' +
                          'CCCxx\n')
  svntest.main.run_svn(None, 'commit', '-m', 'log message', wc_dir)
  svntest.main.run_svn(None, 'update', wc_dir)

  # Merge trunk to branch-1
  svntest.main.run_svn(None, 'merge', '^/A/B', sbox.ospath('A/B1'))
  svntest.main.run_svn(None, 'commit', '-m', 'log message', wc_dir)
  svntest.main.run_svn(None, 'update', wc_dir)

  # Reintegrate branch-1 subtree to trunk subtree
  run_reintegrate('^/A/B1/E', sbox.ospath('A/B/E'))
  svntest.main.run_svn(None, 'commit', '-m', 'log message', wc_dir)
  svntest.main.run_svn(None, 'update', wc_dir)

  # Merge trunk to branch-2
  svntest.main.run_svn(None, 'merge', '^/A/B', sbox.ospath('A/B2'))
  svntest.main.run_svn(None, 'commit', '-m', 'log message', wc_dir)
  svntest.main.run_svn(None, 'update', wc_dir)

  # Reverse merge branch-1 subtree to branch-2 subtree, this removes
  # the subtree mergeinfo from branch 2
  svntest.main.run_svn(None, 'merge', '-r8:2',
                       '^/A/B1/E', sbox.ospath('A/B2/E'))
  svntest.main.run_svn(None, 'commit', '-m', 'log message', wc_dir)
  svntest.main.run_svn(None, 'update', wc_dir)

  # Verify that merge results in no subtree mergeinfo
  svntest.actions.run_and_verify_svn(None, [], [], 'propget', 'svn:mergeinfo',
                                     sbox.repo_url + '/A/B2/E')

  # Merge trunk to branch-2
  svntest.main.run_svn(None, 'merge', '^/A/B', sbox.ospath('A/B2'))
  svntest.main.run_svn(None, 'commit', '-m', 'log message', wc_dir)
  svntest.main.run_svn(None, 'update', wc_dir)

  # Verify that there is still no subtree mergeinfo
  svntest.actions.run_and_verify_svn(None, [], [], 'propget', 'svn:mergeinfo',
                                     sbox.repo_url + '/A/B2/E')

  # Reintegrate branch-2 to trunk, this fails in 1.6.x from 1.6.13.
  # The error message states revisions /A/B/E:3-11 are missing from
  # /A/B2/E and yet the mergeinfo on /A/B2 is /A/B:3-11 and /A/B2/E
  # has no mergeinfo.
  expected_output = wc.State(sbox.ospath('A/B'), {
      'E'       : Item(status=' U'),
      'E/alpha' : Item(status='U '),
      })
  expected_mergeinfo = wc.State(sbox.ospath('A/B'), {
      '' : Item(status=' U'),
      })
  expected_elision = wc.State(sbox.ospath('A/B'), {
      })
  expected_disk = wc.State('', {
      ''        : Item(props={SVN_PROP_MERGEINFO : '/A/B2:4-12'}),
      'E'       : Item(),
      'E/alpha' : Item("AAA\n" +
                       "BBB\n" +
                       "CCCxx\n"),
      'E/beta'  : Item("This is the file 'beta'.\n"),
      'F'       : Item(),
      'lambda'  : Item("This is the file 'lambda'.\n"),
      })
  expected_skip = wc.State(sbox.ospath('A/B'), {
      })
  run_and_verify_reintegrate(sbox.ospath('A/B'),
                                       '^/A/B2',
                                       expected_output, expected_mergeinfo,
                                       expected_elision, expected_disk,
                                       None, expected_skip,
                                       None,
                                       1, 1)

#----------------------------------------------------------------------
@SkipUnless(server_has_mergeinfo)
@Issue(3961)
def reintegrate_replaced_source(sbox):
  "reintegrate a replaced source branch"

  # Make A_COPY branch in r2, and do a few more commits to A in r3-6.
  sbox.build()
  wc_dir = sbox.wc_dir
  expected_disk, expected_status = set_up_branch(sbox)

  A_path         = sbox.ospath('A')
  A_COPY_path    = sbox.ospath('A_COPY')
  beta_COPY_path = sbox.ospath('A_COPY/B/E/beta')
  mu_COPY_path   = sbox.ospath('A_COPY/mu')

  # Using cherrypick merges, simulate a series of sync merges from A to
  # A_COPY with a replace of A_COPY along the way.
  #
  # r7 - Merge r3 from A to A_COPY
  svntest.main.run_svn(None, 'up', wc_dir)
  svntest.main.run_svn(None, 'merge', sbox.repo_url + '/A', A_COPY_path,
                       '-c3')
  svntest.main.run_svn(None, 'ci', '-m', 'Merge r3 from A to A_COPY', wc_dir)

  # r8 - Merge r4 from A to A_COPY
  svntest.main.run_svn(None, 'up', wc_dir)
  svntest.main.run_svn(None, 'merge', sbox.repo_url + '/A', A_COPY_path,
                       '-c4')
  svntest.main.run_svn(None, 'ci', '-m', 'Merge r4 from A to A_COPY', wc_dir)

  # r9 - Merge r5 from A to A_COPY. Make an additional edit to
  # A_COPY/B/E/beta.
  svntest.main.run_svn(None, 'up', wc_dir)
  svntest.main.run_svn(None, 'merge', sbox.repo_url + '/A', A_COPY_path,
                       '-c5')
  svntest.main.file_write(beta_COPY_path, "Branch edit mistake.\n")
  svntest.main.run_svn(None, 'ci', '-m', 'Merge r5 from A to A_COPY', wc_dir)

  # r10 - Delete A_COPY and replace it with A_COPY@8. This removes the edit
  # we made above in r9 to A_COPY/B/E/beta.
  svntest.main.run_svn(None, 'up', wc_dir)
  svntest.main.run_svn(None, 'delete', A_COPY_path)
  svntest.main.run_svn(None, 'copy', sbox.repo_url + '/A_COPY@8',
                       A_COPY_path)
  svntest.main.run_svn(None, 'ci', '-m', 'Replace A_COPY with A_COPY@8',
                       wc_dir)

  # r11 - Make an edit on A_COPY/mu.
  svntest.main.file_write(mu_COPY_path, "Branch edit.\n")
  svntest.main.run_svn(None, 'ci', '-m', 'Branch edit',
                       wc_dir)

  # r12 - Do a final sync merge of A to A_COPY in preparation for
  # reintegration.
  svntest.main.run_svn(None, 'up', wc_dir)
  svntest.main.run_svn(None, 'merge', sbox.repo_url + '/A', A_COPY_path)
  svntest.main.run_svn(None, 'ci', '-m', 'Sycn A_COPY with A', wc_dir)

  # Reintegrate A_COPY to A.  The resulting mergeinfo should be
  # '/A_COPY:2-8,10-12' because of the replacement which removed /A_COPY:9
  # from the reintegrate source's history.
  svntest.main.run_svn(None, 'up', wc_dir)
  expected_output = wc.State(A_path, {
    'mu' : Item(status='U '),
    })
  expected_mergeinfo_output = wc.State(A_path, {
    ''   : Item(status=' U'),
    })
  expected_elision_output = wc.State(A_path, {
    })
  expected_status = wc.State(A_path, {
    ''          : Item(status=' M'),
    'B'         : Item(status='  '),
    'mu'        : Item(status='M '),
    'B/E'       : Item(status='  '),
    'B/E/alpha' : Item(status='  '),
    'B/E/beta'  : Item(status='  '),
    'B/lambda'  : Item(status='  '),
    'B/F'       : Item(status='  '),
    'C'         : Item(status='  '),
    'D'         : Item(status='  '),
    'D/G'       : Item(status='  '),
    'D/G/pi'    : Item(status='  '),
    'D/G/rho'   : Item(status='  '),
    'D/G/tau'   : Item(status='  '),
    'D/gamma'   : Item(status='  '),
    'D/H'       : Item(status='  '),
    'D/H/chi'   : Item(status='  '),
    'D/H/psi'   : Item(status='  '),
    'D/H/omega' : Item(status='  '),
    })
  expected_status.tweak(wc_rev=12)
  expected_disk = wc.State('', {
    ''          : Item(props={SVN_PROP_MERGEINFO : '/A_COPY:2-8,10-12'}),
    'B'         : Item(),
    'mu'        : Item("Branch edit.\n"),
    'B/E'       : Item(),
    'B/E/alpha' : Item("This is the file 'alpha'.\n"),
    'B/E/beta'  : Item("New content"),
    'B/lambda'  : Item("This is the file 'lambda'.\n"),
    'B/F'       : Item(),
    'C'         : Item(),
    'D'         : Item(),
    'D/G'       : Item(),
    'D/G/pi'    : Item("This is the file 'pi'.\n"),
    'D/G/rho'   : Item("New content"),
    'D/G/tau'   : Item("This is the file 'tau'.\n"),
    'D/gamma'   : Item("This is the file 'gamma'.\n"),
    'D/H'       : Item(),
    'D/H/chi'   : Item("This is the file 'chi'.\n"),
    'D/H/psi'   : Item("New content"),
    'D/H/omega' : Item("New content"),
    })
  expected_skip = wc.State(A_path, { })
  run_and_verify_reintegrate(A_path,
                                       sbox.repo_url + '/A_COPY',
                                       expected_output,
                                       expected_mergeinfo_output,
                                       expected_elision_output,
                                       expected_disk,
                                       expected_status,
                                       expected_skip,
                                       [], True, True)

#----------------------------------------------------------------------
@SkipUnless(svntest.main.is_posix_os)
@Issue(4052)
def reintegrate_symlink_deletion(sbox):
  "reintegrate symlink deletion"

  sbox.build()
  wc_dir = sbox.wc_dir

  ## path vars
  A_path = sbox.ospath('A')
  A_omicron_path = sbox.ospath('A/omicron')
  mu_path = sbox.ospath('A/mu')
  A_COPY_path = sbox.ospath('A_COPY')
  A_COPY_omicron_path = sbox.ospath('A_COPY/omicron')
  A_url = sbox.repo_url + "/A"
  A_COPY_url = sbox.repo_url + "/A_COPY"

  ## add symlink
  os.symlink(mu_path, A_omicron_path)
  sbox.simple_add('A/omicron')
  sbox.simple_commit(message='add symlink')

  ## branch
  sbox.simple_repo_copy('A', 'A_COPY')
  sbox.simple_update()

  ## branch rm
  sbox.simple_rm('A_COPY/omicron')
  sbox.simple_commit(message='remove symlink on branch')

  ## Note: running update at this point avoids the bug.

  ## reintegrate
  # ### TODO: verify something here
  run_reintegrate(A_COPY_url, A_path)

#----------------------------------------------------------------------
def no_op_reintegrate(sbox):
  """no-op reintegrate"""

  # Make A_COPY branch in r2, and do a few more commits to A in r3-6.
  sbox.build()
  wc_dir = sbox.wc_dir
  A_path = sbox.ospath('A')
  A_COPY_path = sbox.ospath('A_COPY')
  expected_disk, expected_status = set_up_branch(sbox)

  # Sync merge from trunk to branch
  svntest.main.run_svn(None, 'merge', sbox.repo_url + '/A', A_COPY_path)
  sbox.simple_commit()
  sbox.simple_update()

  # Reintegrate; there are no relevant changes on the branch.
  # ### TODO: Check the result more carefully than merely that it completed.
  run_reintegrate(sbox.repo_url + '/A_COPY', A_path)

#----------------------------------------------------------------------
def renamed_branch_reintegrate(sbox):
  """reintegrate a branch that has been renamed"""

  # The idea of this test is to ensure that the reintegrate merge is able to
  # cope when one or both of the branches have been renamed.
  #
  # A       -1-----3-4-5-6----------------------9--------
  #            \              \                / reintegrate
  # A_COPY      2--------------7--------      /
  #                        sync        \     /
  # RENAMED                      rename 8----------------

  # TODO: Make some changes between the sync/rename/reintegrate steps so
  #   the reintegrate merge actually has to do something.
  # TODO: Rename the other branch as well.

  # Make A_COPY branch in r2, and do a few more commits to A in r3-6.
  sbox.build()

  wc_dir = sbox.wc_dir
  A_path = sbox.ospath('A')
  A_COPY_path = sbox.ospath('A_COPY')
  expected_disk, expected_status = set_up_branch(sbox)

  # Sync merge from trunk to branch
  svntest.main.run_svn(None, 'merge', sbox.repo_url + '/A', A_COPY_path)
  sbox.simple_commit()
  sbox.simple_update()

  # Rename the branch
  sbox.simple_move('A_COPY', 'RENAMED')
  sbox.simple_commit()
  sbox.simple_update()

  # Reintegrate; there are no relevant changes on the branch.
  # ### TODO: Check the result more carefully than merely that it completed.
  run_reintegrate(sbox.repo_url + '/RENAMED@8', A_path)

########################################################################
# Run the tests


# list all tests here, starting with None:
test_list = [ None,
              basic_reintegrate,
              reintegrate_with_rename,
              reintegrate_branch_never_merged_to,
              reintegrate_fail_on_modified_wc,
              reintegrate_fail_on_mixed_rev_wc,
              reintegrate_fail_on_switched_wc,
              reintegrate_on_shallow_wc,
              reintegrate_fail_on_stale_source,
              merge_file_with_space_in_its_path,
              reintegrate_with_subtree_mergeinfo,
              multiple_reintegrates_from_the_same_branch,
              reintegrate_with_self_referential_mergeinfo,
              reintegrate_with_subtree_merges,
              added_subtrees_with_mergeinfo_break_reintegrate,
              two_URL_merge_removes_valid_mergeinfo_from_target,
              reintegrate_creates_bogus_mergeinfo,
              no_source_subtree_mergeinfo,
              reintegrate_replaced_source,
              reintegrate_symlink_deletion,
              no_op_reintegrate,
              renamed_branch_reintegrate,
             ]

if __name__ == '__main__':
  svntest.main.run_tests(test_list)
  # NOTREACHED


### End of file.