summaryrefslogtreecommitdiff
path: root/subversion/tests/cmdline/externals_tests.py
blob: 34f471face38535c674351f649dbf7384edc1418 (plain)
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
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
#!/usr/bin/env python
#
#  module_tests.py:  testing modules / external sources.
#
#  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 sys
import os
import re
import shutil

# Our testing module
import svntest

# (abbreviation)
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
Item = svntest.wc.StateItem

######################################################################
# Tests
#
#   Each test must return on success or raise on failure.


#----------------------------------------------------------------------

### todo: it's inefficient to keep calling externals_test_setup() for
### every test.  It's slow.  But it's very safe -- we're guaranteed to
### have a clean repository, built from the latest Subversion, with
### the svn:externals properties preset in a known way.  Right now I
### can't think of any other way to achieve that guarantee, so the
### result is that each individual test is slow.

def externals_test_setup(sbox):
  """Set up a repository in which some directories have the externals property,
  and set up another repository, referred to by some of those externals.
  Both repositories contain greek trees with five revisions worth of
  random changes, then in the sixth revision the first repository --
  and only the first -- has some externals properties set.  ### Later,
  test putting externals on the second repository. ###

  The arrangement of the externals in the first repository is:

    /A/B/ ==>  ^/A/D/gamma                      gamma
    /A/C/ ==>  exdir_G                          <scheme>:///<other_repos>/A/D/G
               ../../../<other_repos_basename>/A/D/H@1 exdir_H

    /A/D/ ==>  ^/../<other_repos_basename>/A    exdir_A
               //<other_repos>/A/D/G/           exdir_A/G/
               exdir_A/H -r 1                   <scheme>:///<other_repos>/A/D/H
               /<some_paths>/A/B                x/y/z/blah

  A dictionary is returned keyed by the directory created by the
  external whose value is the URL of the external.
  """

  # The test itself will create a working copy
  sbox.build(create_wc = False)

  svntest.main.safe_rmtree(sbox.wc_dir)

  wc_init_dir    = sbox.add_wc_path('init')  # just for setting up props
  repo_dir       = sbox.repo_dir
  repo_url       = sbox.repo_url
  other_repo_dir, other_repo_url = sbox.add_repo_path('other')
  other_repo_basename = os.path.basename(other_repo_dir)

  # Get a scheme relative URL to the other repository.
  scheme_relative_other_repo_url = other_repo_url[other_repo_url.find(':')+1:]

  # Get a server root relative URL to the other repository by trimming
  # off the first three /'s.
  server_relative_other_repo_url = other_repo_url
  for i in range(3):
    j = server_relative_other_repo_url.find('/') + 1
    server_relative_other_repo_url = server_relative_other_repo_url[j:]
  server_relative_other_repo_url = '/' + server_relative_other_repo_url

  # These files will get changed in revisions 2 through 5.
  mu_path = os.path.join(wc_init_dir, "A/mu")
  pi_path = os.path.join(wc_init_dir, "A/D/G/pi")
  lambda_path = os.path.join(wc_init_dir, "A/B/lambda")
  omega_path = os.path.join(wc_init_dir, "A/D/H/omega")

  # These are the directories on which `svn:externals' will be set, in
  # revision 6 on the first repo.
  B_path = os.path.join(wc_init_dir, "A/B")
  C_path = os.path.join(wc_init_dir, "A/C")
  D_path = os.path.join(wc_init_dir, "A/D")

  # Create a working copy.
  svntest.actions.run_and_verify_svn(None, [],
                                     'checkout',
                                     repo_url, wc_init_dir)

  # Make revisions 2 through 5, but don't bother with pre- and
  # post-commit status checks.

  svntest.main.file_append(mu_path, "Added to mu in revision 2.\n")
  svntest.actions.run_and_verify_svn(None, [],
                                     'ci', '-m', 'log msg',
                                     '--quiet', wc_init_dir)

  svntest.main.file_append(pi_path, "Added to pi in revision 3.\n")
  svntest.actions.run_and_verify_svn(None, [],
                                     'ci', '-m', 'log msg',
                                     '--quiet', wc_init_dir)

  svntest.main.file_append(lambda_path, "Added to lambda in revision 4.\n")
  svntest.actions.run_and_verify_svn(None, [],
                                     'ci', '-m', 'log msg',
                                     '--quiet', wc_init_dir)

  svntest.main.file_append(omega_path, "Added to omega in revision 5.\n")
  svntest.actions.run_and_verify_svn(None, [],
                                     'ci', '-m', 'log msg',
                                     '--quiet', wc_init_dir)

  # Get the whole working copy to revision 5.
  expected_output = svntest.wc.State(wc_init_dir, {
  })
  svntest.actions.run_and_verify_update(wc_init_dir,
                                        expected_output, None, None)

  # Now copy the initial repository to create the "other" repository,
  # the one to which the first repository's `svn:externals' properties
  # will refer.  After this, both repositories have five revisions
  # of random stuff, with no svn:externals props set yet.
  svntest.main.copy_repos(repo_dir, other_repo_dir, 5)

  # This is the returned dictionary.
  external_url_for = { }

  external_url_for["A/B/gamma"] = "^/A/D/gamma"
  external_url_for["A/C/exdir_G"] = other_repo_url + "/A/D/G"
  external_url_for["A/C/exdir_H"] = "../../../" + \
                                    other_repo_basename + \
                                    "/A/D/H@1"

  # Set up the externals properties on A/B/, A/C/ and A/D/.
  externals_desc = \
           external_url_for["A/B/gamma"] + " gamma\n"

  change_external(B_path, externals_desc, commit=False)

  externals_desc = \
           "exdir_G       " + external_url_for["A/C/exdir_G"] + "\n" + \
           external_url_for["A/C/exdir_H"] + " exdir_H\n"

  change_external(C_path, externals_desc, commit=False)

  external_url_for["A/D/exdir_A"]    = "^/../" + other_repo_basename + "/A"
  external_url_for["A/D/exdir_A/G/"] = scheme_relative_other_repo_url + \
                                       "/A/D/G/"
  external_url_for["A/D/exdir_A/H"]  = other_repo_url + "/A/D/H"
  external_url_for["A/D/x/y/z/blah"] = server_relative_other_repo_url + "/A/B"

  externals_desc = \
           external_url_for["A/D/exdir_A"] + " exdir_A"           + \
           "\n"                                                  + \
           external_url_for["A/D/exdir_A/G/"] + " exdir_A/G/"    + \
           "\n"                                                  + \
           "exdir_A/H -r 1 " + external_url_for["A/D/exdir_A/H"] + \
           "\n"                                                  + \
           external_url_for["A/D/x/y/z/blah"] + " x/y/z/blah"    + \
           "\n"

  change_external(D_path, externals_desc, commit=False)

  # Commit the property changes.

  expected_output = svntest.wc.State(wc_init_dir, {
    'A/B' : Item(verb='Sending'),
    'A/C' : Item(verb='Sending'),
    'A/D' : Item(verb='Sending'),
    })

  expected_status = svntest.actions.get_virginal_state(wc_init_dir, 5)
  expected_status.tweak('A/B', 'A/C', 'A/D', wc_rev=6, status='  ')

  svntest.actions.run_and_verify_commit(wc_init_dir,
                                        expected_output,
                                        expected_status)

  return external_url_for

def change_external(path, new_val, commit=True):
  """Change the value of the externals property on PATH to NEW_VAL,
  and commit the change unless COMMIT is False."""

  svntest.actions.set_prop('svn:externals', new_val, path)
  if commit:
    svntest.actions.run_and_verify_svn(None, [], 'ci',
                                       '-m', 'log msg', '--quiet', path)

def change_external_expect_error(path, new_val, expected_err):
  """Try to change the value of the externals property on PATH to NEW_VAL,
  but expect to get an error message that matches EXPECTED_ERR."""

  svntest.actions.set_prop('svn:externals', new_val, path,
                           expected_re_string=expected_err)


def probe_paths_exist(paths):
  """ Probe each one of PATHS to see if it exists, otherwise throw a
      Failure exception. """

  for path in paths:
    if not os.path.exists(path):
      raise svntest.Failure("Probing for " + path + " failed.")


def probe_paths_missing(paths):
  """ Probe each one of PATHS to see if does not exist, otherwise throw a
      Failure exception. """

  for path in paths:
    if os.path.exists(path):
      raise svntest.Failure(path + " unexpectedly still exists.")


#----------------------------------------------------------------------


### todo: It would be great if everything used the new wc.py system to
### check output/status.  In fact, it would be great to do more output
### and status checking period!  But must first see how well the
### output checkers deal with multiple summary lines.  With external
### modules, you can get the first "Updated to revision X" line, and
### then there will be more "Updated to..." and "Checked out..." lines
### following it, one line for each new or changed external.


#----------------------------------------------------------------------

def checkout_with_externals(sbox):
  "test checkouts with externals"

  externals_test_setup(sbox)

  wc_dir         = sbox.wc_dir
  repo_url       = sbox.repo_url

  # Create a working copy.
  svntest.actions.run_and_verify_svn(None, [],
                                     'checkout',
                                     repo_url, wc_dir)

  # Probe the working copy a bit, see if it's as expected.
  expected_existing_paths = [
    sbox.ospath('A/B/gamma'),
    sbox.ospath('A/C/exdir_G'),
    sbox.ospath('A/C/exdir_G/pi'),
    sbox.ospath('A/C/exdir_H'),
    sbox.ospath('A/C/exdir_H/omega'),
    sbox.ospath('A/D/x'),
    sbox.ospath('A/D/x/y'),
    sbox.ospath('A/D/x/y/z'),
    sbox.ospath('A/D/x/y/z/blah'),
    sbox.ospath('A/D/x/y/z/blah/E/alpha'),
    sbox.ospath('A/D/x/y/z/blah/E/beta'),
    ]
  probe_paths_exist(expected_existing_paths)

  # Pick a file at random, make sure it has the expected contents.
  for path, contents in ((sbox.ospath('A/C/exdir_H/omega'),
                          "This is the file 'omega'.\n"),
                         (sbox.ospath('A/B/gamma'),
                          "This is the file 'gamma'.\n")):
    if open(path).read() != contents:
      raise svntest.Failure("Unexpected contents for rev 1 of " + path)

#----------------------------------------------------------------------

def update_receive_new_external(sbox):
  "update to receive a new external module"

  external_url_for = externals_test_setup(sbox)
  wc_dir         = sbox.wc_dir

  other_wc_dir   = sbox.add_wc_path('other')
  repo_url       = sbox.repo_url
  other_repo_url = repo_url + ".other"

  # Checkout two working copies.
  svntest.actions.run_and_verify_svn(None, [],
                                     'checkout',
                                     repo_url, wc_dir)

  svntest.actions.run_and_verify_svn(None, [],
                                     'checkout',
                                     repo_url, other_wc_dir)

  # Add one new external item to the property on A/D.  The new item is
  # "exdir_E", deliberately added in the middle not at the end.
  new_externals_desc = \
           external_url_for["A/D/exdir_A"] + " exdir_A"           + \
           "\n"                                                   + \
           external_url_for["A/D/exdir_A/G/"] + " exdir_A/G/"     + \
           "\n"                                                   + \
           "exdir_E           " + other_repo_url + "/A/B/E"       + \
           "\n"                                                   + \
           "exdir_A/H -r 1  " + external_url_for["A/D/exdir_A/H"] + \
           "\n"                                                   + \
           external_url_for["A/D/x/y/z/blah"] + " x/y/z/blah"     + \
           "\n"

  # Set and commit the property
  change_external(sbox.ospath('A/D'), new_externals_desc)

  # Update the other working copy, see if we get the new item.
  expected_output = svntest.wc.State(other_wc_dir, {
    'A/D'               : Item(status=' U'),
    'A/D/exdir_E/beta'  : Item(status='A '),
    'A/D/exdir_E/alpha' : Item(status='A '),
  })
  svntest.actions.run_and_verify_update(other_wc_dir,
                                        expected_output, None, None)

  probe_paths_exist([os.path.join(other_wc_dir, "A", "D", "exdir_E")])

#----------------------------------------------------------------------

def update_lose_external(sbox):
  "update to lose an external module"

  external_url_for = externals_test_setup(sbox)
  wc_dir         = sbox.wc_dir

  other_wc_dir   = sbox.add_wc_path('other')
  repo_url       = sbox.repo_url

  # Checkout two working copies.
  svntest.actions.run_and_verify_svn(None, [],
                                     'checkout',
                                     repo_url, wc_dir)

  svntest.actions.run_and_verify_svn(None, [],
                                     'checkout',
                                     repo_url, other_wc_dir)

  # Lose one new external item from A/D.  The lost item is
  # "exdir_A", chosen because there are two other externals underneath
  # it (G and H) which are not being removed.  We expect them to
  # remain -- in other words:
  #
  #      BEFORE                                AFTER
  #    ------------                          ------------
  #    A/D/exdir_A                           A/D/exdir_A
  #    A/D/exdir_A/.svn/...                    <GONE>
  #    A/D/exdir_A/mu                          <GONE>
  #    A/D/exdir_A/B/...                       <GONE>
  #    A/D/exdir_A/C/...                       <GONE>
  #    A/D/exdir_A/D/...                       <GONE>
  #    A/D/exdir_A/G/...                     A/D/exdir_A/G/...
  #    A/D/exdir_A/H/...                     A/D/exdir_A/H/...

  new_externals_desc = \
           external_url_for["A/D/exdir_A/G/"] + " exdir_A/G"      + \
           "\n"                                                   + \
           "exdir_A/H -r 1  " + external_url_for["A/D/exdir_A/H"] + \
           "\n"                                                   + \
           external_url_for["A/D/x/y/z/blah"] + " x/y/z/blah"     + \
           "\n"

  # Set and commit the property
  change_external(sbox.ospath('A/D'), new_externals_desc)

  # The code should handle a missing local externals item
  svntest.main.safe_rmtree(os.path.join(other_wc_dir, "A", "D", "exdir_A", \
                                        "D"))

  # Update other working copy, see if lose & preserve things appropriately
  expected_output = svntest.wc.State(other_wc_dir, {
    'A/D'               : Item(status=' U'),
    'A/D/exdir_A'       : Item(verb='Removed external'),
  })
  svntest.actions.run_and_verify_update(other_wc_dir,
                                        expected_output, None, None)

  expected_existing_paths = [
    os.path.join(other_wc_dir, "A", "D", "exdir_A"),
    os.path.join(other_wc_dir, "A", "D", "exdir_A", "G"),
    os.path.join(other_wc_dir, "A", "D", "exdir_A", "H"),
    ]
  probe_paths_exist(expected_existing_paths)

  expected_missing_paths = [
    os.path.join(other_wc_dir, "A", "D", "exdir_A", "mu"),
    os.path.join(other_wc_dir, "A", "D", "exdir_A", "B"),
    os.path.join(other_wc_dir, "A", "D", "exdir_A", "C"),
    os.path.join(other_wc_dir, "A", "D", "exdir_A", "D"),
    ]
  probe_paths_missing(expected_missing_paths)

#----------------------------------------------------------------------

def update_change_pristine_external(sbox):
  "update change to an unmodified external module"

  external_url_for = externals_test_setup(sbox)
  wc_dir         = sbox.wc_dir

  other_wc_dir   = sbox.add_wc_path('other')
  repo_url       = sbox.repo_url
  other_repo_url = repo_url + ".other"

  # Checkout two working copies.
  svntest.actions.run_and_verify_svn(None, [],
                                     'checkout',
                                     repo_url, wc_dir)

  svntest.actions.run_and_verify_svn(None, [],
                                     'checkout',
                                     repo_url, other_wc_dir)

  # Change the "x/y/z/blah" external on A/D to point to a different
  # URL.  Since no changes were made to the old checked-out external,
  # we should get a clean replace.
  new_externals_desc = \
           external_url_for["A/D/exdir_A"] + " exdir_A"          + \
           "\n"                                                  + \
           external_url_for["A/D/exdir_A/G/"] + " exdir_A/G"     + \
           "\n"                                                  + \
           "exdir_A/H -r 1 " + external_url_for["A/D/exdir_A/H"] + \
           "\n"                                                  + \
           "x/y/z/blah     " + other_repo_url + "/A/B/F"         + \
           "\n"

  # Set and commit the property
  change_external(sbox.ospath('A/D'), new_externals_desc)

  # Update other working copy, see if get the right change.
  expected_output = svntest.wc.State(other_wc_dir, {
    'A/D'               : Item(status=' U'),
    'A/D/x/y/z/blah/F'  : Item(status='D '),
    'A/D/x/y/z/blah/E'  : Item(status='D '),
    'A/D/x/y/z/blah/lambda': Item(status='D '),
  })
  svntest.actions.run_and_verify_update(other_wc_dir,
                                        expected_output, None, None)

  xyzb_path = os.path.join(other_wc_dir, "x", "y", "z", "blah")

  expected_missing_paths = [
    os.path.join(xyzb_path, "alpha"),
    os.path.join(xyzb_path, "beta"),
    ]
  probe_paths_missing(expected_missing_paths)

def update_change_modified_external(sbox):
  "update changes to a modified external module"

  external_url_for = externals_test_setup(sbox)
  wc_dir         = sbox.wc_dir

  other_wc_dir   = sbox.add_wc_path('other')
  repo_url       = sbox.repo_url
  other_repo_url = repo_url + ".other"

  # Checkout two working copies.
  svntest.actions.run_and_verify_svn(None, [],
                                     'checkout',
                                     repo_url, wc_dir)

  svntest.actions.run_and_verify_svn(None, [],
                                     'checkout',
                                     repo_url, other_wc_dir)

  # Make a couple of mods in the "x/y/z/blah/" external.
  alpha_path = os.path.join(other_wc_dir, "A", "D",
                            "x", "y", "z", "blah", "alpha")
  svntest.main.file_append(alpha_path, "Some new text in alpha.\n")
  new_file = os.path.join(other_wc_dir, "A", "D",
                          "x", "y", "z", "blah", "fish.txt")
  svntest.main.file_append(new_file, "This is an unversioned file.\n")

  # Change the "x/y/z/blah" external on A/D to point to a different
  # URL.  There are some local mods under the old checked-out external,
  # so the old dir should be saved under a new name.
  new_externals_desc = \
           external_url_for["A/D/exdir_A"] + " exdir_A"          + \
           "\n"                                                  + \
           external_url_for["A/D/exdir_A/G/"] + " exdir_A/G/"    + \
           "\n"                                                  + \
           "exdir_A/H -r 1 " + external_url_for["A/D/exdir_A/H"] + \
           "\n"                                                  + \
           "x/y/z/blah     " + other_repo_url + "/A/B/F"         + \
           "\n"

  # Set and commit the property
  change_external(sbox.ospath('A/D'), new_externals_desc)

  # Update other working copy, see if get the right change.
  expected_output = svntest.wc.State(other_wc_dir, {
    'A/D'               : Item(status=' U'),
    'A/D/x/y/z/blah/F'  : Item(status='D '),
    'A/D/x/y/z/blah/lambda': Item(status='D '),
    'A/D/x/y/z/blah/E'  : Item(status='D '),
  })
  svntest.actions.run_and_verify_update(other_wc_dir,
                                        expected_output, None, None)


  xyzb_path = os.path.join(other_wc_dir, "x", "y", "z", "blah")

  expected_missing_paths = [
    os.path.join(xyzb_path, "alpha"),
    os.path.join(xyzb_path, "beta"),
    ]
  probe_paths_missing(expected_missing_paths)

def update_receive_change_under_external(sbox):
  "update changes under an external module"

  externals_test_setup(sbox)
  wc_dir         = sbox.wc_dir

  other_wc_dir   = sbox.add_wc_path('other')
  repo_url       = sbox.repo_url
  other_repo_url = repo_url + ".other"

  # Checkout two working copies.
  svntest.actions.run_and_verify_svn(None, [],
                                     'checkout',
                                     repo_url, wc_dir)

  svntest.actions.run_and_verify_svn(None, [],
                                     'checkout',
                                     other_repo_url, other_wc_dir)

  # Commit some modifications from the other_wc.
  other_gamma_path = os.path.join(other_wc_dir, 'A', 'D', 'gamma')
  svntest.main.file_append(other_gamma_path, "New text in other gamma.\n")

  expected_output = svntest.wc.State(other_wc_dir, {
    'A/D/gamma' : Item(verb='Sending'),
    })
  expected_status = svntest.actions.get_virginal_state(other_wc_dir, 5)
  expected_status.tweak('A/D/gamma', wc_rev=6)
  svntest.actions.run_and_verify_commit(other_wc_dir,
                                        expected_output,
                                        expected_status)

  # Now update the regular wc to see if we get the change.  Note that
  # none of the module *properties* in this wc have been changed; only
  # the source repository of the modules has received a change, and
  # we're verifying that an update here pulls that change.

  # The output's going to be all screwy because of the module
  # notifications, so don't bother parsing it, just run update
  # directly.
  expected_output = svntest.wc.State(wc_dir, {
    'A/D/exdir_A/D/gamma': Item(status='U '),
  })
  svntest.actions.run_and_verify_update(wc_dir,
                                        expected_output, None, None)

  external_gamma_path = sbox.ospath('A/D/exdir_A/D/gamma')
  contents = open(external_gamma_path).read()
  if contents != ("This is the file 'gamma'.\n"
                  "New text in other gamma.\n"):
    raise svntest.Failure("Unexpected contents for externally modified " +
                          external_gamma_path)

  # Commit more modifications
  other_rho_path = os.path.join(other_wc_dir, 'A', 'D', 'G', 'rho')
  svntest.main.file_append(other_rho_path, "New text in other rho.\n")

  expected_output = svntest.wc.State(other_wc_dir, {
    'A/D/G/rho' : Item(verb='Sending'),
    })
  expected_status = svntest.actions.get_virginal_state(other_wc_dir, 5)
  expected_status.tweak('A/D/gamma', wc_rev=6)
  expected_status.tweak('A/D/G/rho', wc_rev=7)
  svntest.actions.run_and_verify_commit(other_wc_dir,
                                        expected_output,
                                        expected_status)

  expected_output = svntest.wc.State(sbox.ospath('A/C'), {
    'exdir_G/rho'       : Item(status='U '),
  })
  svntest.actions.run_and_verify_update(sbox.ospath('A/C'),
                                        expected_output, None, None)

  external_rho_path = sbox.ospath('A/C/exdir_G/rho')
  contents = open(external_rho_path).read()
  if contents != ("This is the file 'rho'.\n"
                  "New text in other rho.\n"):
    raise svntest.Failure("Unexpected contents for externally modified " +
                          external_rho_path)

#----------------------------------------------------------------------

def modify_and_update_receive_new_external(sbox):
  "commit and update additional externals"

  external_url_for = externals_test_setup(sbox)
  wc_dir         = sbox.wc_dir
  repo_url       = sbox.repo_url

  # Checkout a working copy
  svntest.actions.run_and_verify_svn(None, [],
                                     'checkout',
                                     repo_url, wc_dir)

  # Add one more external item
  B_path = sbox.ospath('A/B')
  externals_desc = \
          external_url_for["A/D/exdir_A/G/"] + " exdir_G"     + \
          "\n"                                                + \
          "exdir_H -r 1 " + external_url_for["A/D/exdir_A/H"] + \
          "\n"                                                + \
          "exdir_Z      " + external_url_for["A/D/exdir_A/H"] + \
          "\n"

  change_external(B_path, externals_desc)

  # Now cd into A/B and try updating
  was_cwd = os.getcwd()
  os.chdir(B_path)

  # Once upon a time there was a core-dump here

  svntest.actions.run_and_verify_svn(svntest.verify.AnyOutput, [], 'up' )

  os.chdir(was_cwd)

  probe_paths_exist([os.path.join(B_path, "exdir_Z")])

#----------------------------------------------------------------------

def disallow_dot_or_dotdot_directory_reference(sbox):
  "error if external target dir involves '.' or '..'"

  external_url_for = externals_test_setup(sbox)
  wc_dir         = sbox.wc_dir
  repo_url       = sbox.repo_url

  # Checkout a working copy
  svntest.actions.run_and_verify_svn(None, [],
                                     'checkout',
                                     repo_url, wc_dir)

  # Try to set illegal externals in the original WC.
  def set_externals_for_path_expect_error(path, val):
    expected_err = ".*Invalid svn:externals property on '.*': target " + \
                   "'.*' is an absolute path or involves '..'.*"
    change_external_expect_error(path, val, expected_err)

  B_path = sbox.ospath('A/B')
  G_path = sbox.ospath('A/D/G')
  H_path = sbox.ospath('A/D/H')
  C_path = sbox.ospath('A/C')
  F_path = sbox.ospath('A/B/F')

  external_urls = list(external_url_for.values())

  # The external_urls contains some examples of relative urls that are
  # ambiguous with these local test paths, so we have to use the
  # <url> <path> ordering here to check the local path validator.

  externals_value_1 = external_urls.pop() + " ../foo\n"
  if not external_urls: external_urls = list(external_url_for.values())
  externals_value_2 = external_urls.pop() + " foo/bar/../baz\n"
  if not external_urls: external_urls = list(external_url_for.values())
  externals_value_3 = external_urls.pop() + " foo/..\n"
  if not external_urls: external_urls = list(external_url_for.values())
  externals_value_4 = external_urls.pop() + " .\n"
  if not external_urls: external_urls = list(external_url_for.values())
  externals_value_5 = external_urls.pop() + " ./\n"
  if not external_urls: external_urls = list(external_url_for.values())
  externals_value_6 = external_urls.pop() + " ..\n"
  if not external_urls: external_urls = list(external_url_for.values())
  externals_value_7 = external_urls.pop() + " ././/.///. \n"
  if not external_urls: external_urls = list(external_url_for.values())
  externals_value_8 = external_urls.pop() + " /foo \n"
  if not external_urls: external_urls = list(external_url_for.values())
  if svntest.main.is_os_windows():
    externals_value_9 = external_urls.pop() + " D:/foo\n"
    if not external_urls: external_urls = list(external_url_for.values())
    externals_value_10 = external_urls.pop() + " D:\\foo\n"
    if not external_urls: external_urls = list(external_url_for.values())
    externals_value_11 = external_urls.pop() + " D:foo\n"
    if not external_urls: external_urls = list(external_url_for.values())

  set_externals_for_path_expect_error(B_path, externals_value_1)
  set_externals_for_path_expect_error(G_path, externals_value_2)
  set_externals_for_path_expect_error(H_path, externals_value_3)
  set_externals_for_path_expect_error(C_path, externals_value_4)
  set_externals_for_path_expect_error(F_path, externals_value_5)
  set_externals_for_path_expect_error(B_path, externals_value_6)
  set_externals_for_path_expect_error(G_path, externals_value_7)
  set_externals_for_path_expect_error(H_path, externals_value_8)
  if svntest.main.is_os_windows():
    set_externals_for_path_expect_error(B_path, externals_value_9)
    set_externals_for_path_expect_error(B_path, externals_value_10)
    set_externals_for_path_expect_error(B_path, externals_value_11)


#----------------------------------------------------------------------

def export_with_externals(sbox):
  "test exports with externals"

  externals_test_setup(sbox)

  wc_dir         = sbox.wc_dir
  repo_url       = sbox.repo_url

  # Create a working copy.
  svntest.actions.run_and_verify_svn(None, [],
                                     'export',
                                     repo_url, wc_dir)

  # Probe the working copy a bit, see if it's as expected.
  expected_existing_paths = [
    sbox.ospath('A/C/exdir_G'),
    sbox.ospath('A/C/exdir_G/pi'),
    sbox.ospath('A/C/exdir_H'),
    sbox.ospath('A/C/exdir_H/omega'),
    sbox.ospath('A/D/x'),
    sbox.ospath('A/D/x/y'),
    sbox.ospath('A/D/x/y/z'),
    sbox.ospath('A/D/x/y/z/blah'),
    sbox.ospath('A/D/x/y/z/blah/E/alpha'),
    sbox.ospath('A/D/x/y/z/blah/E/beta'),
    ]
  probe_paths_exist(expected_existing_paths)

  # Pick some files, make sure their contents are as expected.
  exdir_G_pi_path = sbox.ospath('A/C/exdir_G/pi')
  contents = open(exdir_G_pi_path).read()
  if contents != ("This is the file 'pi'.\n"
                  "Added to pi in revision 3.\n"):
    raise svntest.Failure("Unexpected contents for rev 1 of " +
                          exdir_G_pi_path)

  exdir_H_omega_path = sbox.ospath('A/C/exdir_H/omega')
  contents = open(exdir_H_omega_path).read()
  if contents != "This is the file 'omega'.\n":
    raise svntest.Failure("Unexpected contents for rev 1 of " +
                          exdir_H_omega_path)

#----------------------------------------------------------------------

# Test for issue #2429
@Issue(2429)
def export_wc_with_externals(sbox):
  "test exports from working copies with externals"

  paths_dict = externals_test_setup(sbox)

  wc_dir         = sbox.wc_dir
  repo_url       = sbox.repo_url
  export_target = sbox.add_wc_path('export')

  # Create a working copy.
  svntest.actions.run_and_verify_svn(None, [],
                                     'checkout',
                                     repo_url, wc_dir)
  # Export the working copy.
  svntest.actions.run_and_verify_svn(None, [],
                                     'export', wc_dir, export_target)

  ### We should be able to check exactly the paths that externals_test_setup()
  ### set up; however, --ignore-externals fails to ignore 'A/B/gamma' so this
  ### doesn't work:
  # paths = [ os.path.join(export_target, path) for path in paths_dict.keys() ]
  ### Therefore currently we check only a particular selection of paths.
  paths = [
    os.path.join(export_target, "A", "C", "exdir_G"),
    os.path.join(export_target, "A", "C", "exdir_G", "pi"),
    os.path.join(export_target, "A", "C", "exdir_H"),
    os.path.join(export_target, "A", "C", "exdir_H", "omega"),
    os.path.join(export_target, "A", "D", "x"),
    os.path.join(export_target, "A", "D", "x", "y"),
    os.path.join(export_target, "A", "D", "x", "y", "z"),
    os.path.join(export_target, "A", "D", "x", "y", "z", "blah"),
    os.path.join(export_target, "A", "D", "x", "y", "z", "blah", "E", "alpha"),
    os.path.join(export_target, "A", "D", "x", "y", "z", "blah", "E", "beta"),
    ]
  probe_paths_exist(paths)

  svntest.main.safe_rmtree(export_target)

  # Export it again, without externals.
  svntest.actions.run_and_verify_svn(None, [],
                                     'export', '--ignore-externals',
                                     wc_dir, export_target)
  probe_paths_missing(paths)

#----------------------------------------------------------------------

def external_with_peg_and_op_revision(sbox):
  "use a peg revision to specify an external module"

  external_url_for = externals_test_setup(sbox)
  wc_dir         = sbox.wc_dir
  repo_url       = sbox.repo_url

  # Checkout a working copy.
  svntest.actions.run_and_verify_svn(None, [],
                                     'checkout',
                                     repo_url, wc_dir)

  # remove A/D/H in the other repo
  svntest.actions.run_and_verify_svn(None, [],
                                     'rm',
                                     external_url_for["A/D/exdir_A/H"],
                                     '-m', 'remove original A/D/H')

  # Set an external property using peg revision syntax.
  new_externals_desc = \
           external_url_for["A/D/exdir_A/H"]  + "@4 exdir_A/H" + \
           "\n"                                                + \
           external_url_for["A/D/exdir_A/G/"] + "   exdir_A/G" + \
           "\n"

  # Set and commit the property.
  change_external(sbox.ospath('A/D'), new_externals_desc)

  # Update other working copy, see if we get the right change.
  expected_output = svntest.wc.State(wc_dir, {
    'A/D/x/y/z/blah'    : Item(verb='Removed external'),
    'A/D/exdir_A'       : Item(verb='Removed external'),
  })
  svntest.actions.run_and_verify_update(wc_dir,
                                        expected_output, None, None)


  external_chi_path = sbox.ospath('A/D/exdir_A/H/chi')
  contents = open(external_chi_path).read()
  if contents != "This is the file 'chi'.\n":
    raise svntest.Failure("Unexpected contents for externally modified " +
                          external_chi_path)

#----------------------------------------------------------------------

def new_style_externals(sbox):
  "check the new '-rN URL PATH' syntax"

  external_url_for = externals_test_setup(sbox)
  wc_dir         = sbox.wc_dir
  repo_url       = sbox.repo_url

  # Checkout a working copy.
  svntest.actions.run_and_verify_svn(None, [],
                                     'checkout',
                                     repo_url, wc_dir)

  # Set an external property using the new '-rN URL PATH' syntax.
  new_externals_desc = \
           external_url_for["A/C/exdir_G"] + " exdir_G"           + \
           "\n"                                                   + \
           "-r 1 " + external_url_for["A/C/exdir_H"] + " exdir_H" + \
           "\n"                                                   + \
           "-r1 "  + external_url_for["A/C/exdir_H"] + " exdir_I" + \
           "\n"

  # Set and commit the property.
  change_external(sbox.ospath('A/C'), new_externals_desc)

  # Update other working copy.
  expected_output = svntest.wc.State(wc_dir, {
    'A/C/exdir_I/chi'   : Item(status='A '),
    'A/C/exdir_I/omega' : Item(status='A '),
    'A/C/exdir_I/psi'   : Item(status='A '),
  })
  svntest.actions.run_and_verify_update(wc_dir,
                                        expected_output, None, None)
  for dir_name in ["exdir_H", "exdir_I"]:
    exdir_X_omega_path = os.path.join(wc_dir, "A", "C", dir_name, "omega")
    contents = open(exdir_X_omega_path).read()
    if contents != "This is the file 'omega'.\n":
      raise svntest.Failure("Unexpected contents for rev 1 of " +
                            exdir_X_omega_path)

#----------------------------------------------------------------------

def disallow_propset_invalid_formatted_externals(sbox):
  "error if propset'ing external with invalid format"

  # Bootstrap
  sbox.build()
  wc_dir = sbox.wc_dir

  A_path = sbox.ospath('A')

  expected_status = svntest.actions.get_virginal_state(wc_dir, 1)
  svntest.actions.run_and_verify_status(wc_dir, expected_status)

  # It should not be possible to set these external properties on a
  # directory.
  for ext in [ 'arg1',
               'arg1 arg2 arg3',
               'arg1 arg2 arg3 arg4',
               'arg1 arg2 arg3 arg4 arg5',
               '-r',
               '-r1',
               '-r 1',
               '-r1 arg1',
               '-r 1 arg1',
               'arg1 -r',
               'arg1 -r1',
               'arg1 -r 1',
               ]:
    change_external_expect_error(A_path, ext,
                                 '.*Error parsing svn:externals.*')

  for ext in [ '-r abc arg1 arg2',
               '-rabc arg1 arg2',
               'arg1 -r abc arg2',
               'arg1 -rabc arg2',
               ]:
    change_external_expect_error(A_path, ext,
                                 '.*Error parsing svn:externals.*')

  for ext in [ 'http://example.com/ http://example.com/',
               '-r1 http://example.com/ http://example.com/',
               '-r 1 http://example.com/ http://example.com/',
               'http://example.com/ -r1 http://example.com/',
               'http://example.com/ -r 1 http://example.com/',
               ]:
    change_external_expect_error(A_path, ext,
                                 '.*cannot use two absolute URLs.*')

  for ext in [ 'http://example.com/ -r1 foo',
               'http://example.com/ -r 1 foo',
               '-r1 foo http://example.com/',
               '-r 1 foo http://example.com/'
               ]:
    change_external_expect_error(A_path, ext,
                                 '.*cannot use a URL \'.*\' as the ' \
                                   'target directory for an external ' \
                                   'definition.*')

#----------------------------------------------------------------------

def old_style_externals_ignore_peg_reg(sbox):
  "old 'PATH URL' format should ignore peg revisions"

  external_url_for = externals_test_setup(sbox)
  wc_dir         = sbox.wc_dir
  repo_url       = sbox.repo_url

  # Checkout a working copy.
  svntest.actions.run_and_verify_svn(None, [],
                                     'checkout',
                                     repo_url, wc_dir)

  # Update the working copy.
  expected_output = svntest.wc.State(wc_dir, {
  })
  svntest.actions.run_and_verify_update(wc_dir,
                                        expected_output, None, None)

  # Set an external property using the old 'PATH URL' syntax with
  # @HEAD in the URL.
  ext = "exdir_G " + external_url_for["A/C/exdir_G"] + "@HEAD\n"

  # Set and commit the property.
  change_external(sbox.ospath('A'), ext)

  # Update the working copy.  This should succeed (exitcode 0) but
  # should print warnings on the external because the URL with '@HEAD'
  # does not exist.
  expected_error = "|".join([".*Error handling externals definition.*",
                             ".*URL .*/A/D/G@HEAD' .* doesn't exist.*",
                             ])
  svntest.actions.run_and_verify_svn2(None,
                                      expected_error,
                                      1,
                                      'up',
                                      wc_dir)


#----------------------------------------------------------------------

def cannot_move_or_remove_file_externals(sbox):
  "should not be able to mv or rm a file external"

  external_url_for = externals_test_setup(sbox)
  wc_dir         = sbox.wc_dir
  repo_url       = sbox.repo_url

  # Checkout a working copy.
  svntest.actions.run_and_verify_svn(None, [],
                                     'checkout',
                                     repo_url, wc_dir)

  # Should not be able to delete the file external.
  svntest.actions.run_and_verify_svn(None,
                                     ".*Cannot remove the external at "
                                     ".*gamma.*; please .* "
                                     "the svn:externals .*",
                                     'rm',
                                     sbox.ospath('A/B/gamma'))

  # Should not be able to move the file external.
  svntest.actions.run_and_verify_svn(None,
                                     ".*Cannot move the external at "
                                     ".*gamma.*; please .*edit.*"
                                     "svn:externals.*",
                                     'mv',
                                     sbox.ospath('A/B/gamma'),
                                     sbox.ospath('A/B/gamma1'))

  # But the directory that contains it can be deleted.
  expected_status = svntest.actions.get_virginal_state(wc_dir, 6)

  svntest.actions.run_and_verify_svn(None, [],
                                     'rm',
                                     sbox.ospath('A/B'))

  expected_status.tweak('A/B', status='D ')
  expected_output = svntest.wc.State(wc_dir, {
      'A/B' : Item(verb='Deleting'),
      })
  expected_status = svntest.actions.get_virginal_state(wc_dir, 6)
  expected_status.remove('A/B', 'A/B/E', 'A/B/E/alpha', 'A/B/E/beta',
                         'A/B/F', 'A/B/lambda')

  expected_status.add({
    'A/D/exdir_A'           : Item(status='  ', wc_rev='5', prev_status='X '),
    'A/D/exdir_A/D'         : Item(status='  ', wc_rev='5'),
    'A/D/exdir_A/D/gamma'   : Item(status='  ', wc_rev='5'),
    'A/D/exdir_A/D/G'       : Item(status='  ', wc_rev='5'),
    'A/D/exdir_A/D/G/pi'    : Item(status='  ', wc_rev='5'),
    'A/D/exdir_A/D/G/rho'   : Item(status='  ', wc_rev='5'),
    'A/D/exdir_A/D/G/tau'   : Item(status='  ', wc_rev='5'),
    'A/D/exdir_A/D/H'       : Item(status='  ', wc_rev='5'),
    'A/D/exdir_A/D/H/chi'   : Item(status='  ', wc_rev='5'),
    'A/D/exdir_A/D/H/psi'   : Item(status='  ', wc_rev='5'),
    'A/D/exdir_A/D/H/omega' : Item(status='  ', wc_rev='5'),
    'A/D/exdir_A/B'         : Item(status='  ', wc_rev='5'),
    'A/D/exdir_A/B/E'       : Item(status='  ', wc_rev='5'),
    'A/D/exdir_A/B/E/beta'  : Item(status='  ', wc_rev='5'),
    'A/D/exdir_A/B/E/alpha' : Item(status='  ', wc_rev='5'),
    'A/D/exdir_A/B/F'       : Item(status='  ', wc_rev='5'),
    'A/D/exdir_A/B/lambda'  : Item(status='  ', wc_rev='5'),
    'A/D/exdir_A/G'         : Item(status='  ', wc_rev='5'),
    'A/D/exdir_A/G/pi'      : Item(status='  ', wc_rev='5'),
    'A/D/exdir_A/G/tau'     : Item(status='  ', wc_rev='5'),
    'A/D/exdir_A/G/rho'     : Item(status='  ', wc_rev='5'),
    'A/D/exdir_A/H'         : Item(status='  ', wc_rev='1'),
    'A/D/exdir_A/H/psi'     : Item(status='  ', wc_rev='1'),
    'A/D/exdir_A/H/omega'   : Item(status='  ', wc_rev='1'),
    'A/D/exdir_A/H/chi'     : Item(status='  ', wc_rev='1'),
    'A/D/exdir_A/C'         : Item(status='  ', wc_rev='5'),
    'A/D/exdir_A/mu'        : Item(status='  ', wc_rev='5'),

    'A/C/exdir_G'           : Item(status='  ', prev_status='X ', wc_rev='5'),
    'A/C/exdir_G/tau'       : Item(status='  ', wc_rev='5'),
    'A/C/exdir_G/pi'        : Item(status='  ', wc_rev='5'),
    'A/C/exdir_G/rho'       : Item(status='  ', wc_rev='5'),

    'A/D/x'                 : Item(status='X '),
    'A/D/x/y/z/blah'        : Item(status='  ', wc_rev='5'),
    'A/D/x/y/z/blah/lambda' : Item(status='  ', wc_rev='5'),
    'A/D/x/y/z/blah/E'      : Item(status='  ', wc_rev='5'),
    'A/D/x/y/z/blah/E/beta' : Item(status='  ', wc_rev='5'),
    'A/D/x/y/z/blah/E/alpha': Item(status='  ', wc_rev='5'),
    'A/D/x/y/z/blah/F'      : Item(status='  ', wc_rev='5'),

    'A/C/exdir_H'           : Item(status='  ', prev_status='X ', wc_rev='1'),
    'A/C/exdir_H/omega'     : Item(status='  ', wc_rev='1'),
    'A/C/exdir_H/chi'       : Item(status='  ', wc_rev='1'),
    'A/C/exdir_H/psi'       : Item(status='  ', wc_rev='1'),
  })

  svntest.actions.run_and_verify_commit(wc_dir,
                                        expected_output, expected_status)

  # Bring the working copy up to date and check that the file the file
  # external is switched to still exists.
  expected_output = svntest.wc.State(wc_dir, {
  })
  svntest.actions.run_and_verify_update(wc_dir,
                                        expected_output, None, None)

  open(sbox.ospath('A/D/gamma')).close()

#----------------------------------------------------------------------

def cant_place_file_external_into_dir_external(sbox):
  "place a file external into a directory external"

  external_url_for = externals_test_setup(sbox)
  wc_dir = sbox.wc_dir
  repo_url = sbox.repo_url
  other_repo_url = repo_url + ".other"

  # Checkout a working copy.
  svntest.actions.run_and_verify_svn(None, [],
                                     'checkout',
                                     repo_url, wc_dir)

  # Put a directory external into the same repository and then a file
  # external into that.
  ext = "^/A/D        A/D-copy\n" + \
        "^/A/B/E/beta A/D-copy/G/beta\n"
  change_external(wc_dir, ext)

  # Bring the working copy up to date and check that the file the file
  # external is switched to still exists.
  svntest.actions.run_and_verify_svn(None, 'svn: E205011: ' +
                                     'Failure occurred.*definitions',
                                     'up', wc_dir)

#----------------------------------------------------------------------

# Issue #2461.
@Issue(2461)
def external_into_path_with_spaces(sbox):
  "allow spaces in external local paths"

  sbox.build()
  wc_dir = sbox.wc_dir
  repo_url = sbox.repo_url

  ext = '^/A/D        "A/copy of D"\n' +\
        '^/A/D        A/another\ copy\ of\ D'
  change_external(wc_dir, ext)

  expected_output = svntest.wc.State(wc_dir, {
    'A/another copy of D/G': Item(status='A '),
    'A/another copy of D/G/pi': Item(status='A '),
    'A/another copy of D/G/tau': Item(status='A '),
    'A/another copy of D/G/rho': Item(status='A '),
    'A/another copy of D/H': Item(status='A '),
    'A/another copy of D/H/chi': Item(status='A '),
    'A/another copy of D/H/omega': Item(status='A '),
    'A/another copy of D/H/psi': Item(status='A '),
    'A/another copy of D/gamma': Item(status='A '),
    'A/copy of D/H'     : Item(status='A '),
    'A/copy of D/H/chi' : Item(status='A '),
    'A/copy of D/H/omega': Item(status='A '),
    'A/copy of D/H/psi' : Item(status='A '),
    'A/copy of D/gamma' : Item(status='A '),
    'A/copy of D/G'     : Item(status='A '),
    'A/copy of D/G/rho' : Item(status='A '),
    'A/copy of D/G/tau' : Item(status='A '),
    'A/copy of D/G/pi'  : Item(status='A '),
  })
  svntest.actions.run_and_verify_update(wc_dir,
                                        expected_output, None, None)
  probe_paths_exist([
      sbox.ospath('A/copy of D'),
      sbox.ospath('A/another copy of D'),
  ])

#----------------------------------------------------------------------

# Issue #3368
@Issue(3368)
def binary_file_externals(sbox):
  "binary file externals"

  sbox.build()
  wc_dir = sbox.wc_dir

  # Add a binary file A/theta, write PNG file data into it.
  theta_contents = open(os.path.join(sys.path[0], "theta.bin"), 'rb').read()
  theta_path = sbox.ospath('A/theta')
  svntest.main.file_write(theta_path, theta_contents, 'wb')

  svntest.main.run_svn(None, 'add', theta_path)

  # Commit the binary file
  expected_output = svntest.wc.State(wc_dir, {
    'A/theta' : Item(verb='Adding  (bin)'),
    })

  expected_status = svntest.actions.get_virginal_state(wc_dir, 1)
  expected_status.add({
    'A/theta' : Item(status='  ', wc_rev=2),
    })

  svntest.actions.run_and_verify_commit(wc_dir, expected_output,
                                        expected_status)


  # Create a file external on the binary file A/theta
  C = sbox.ospath('A/C')
  external = os.path.join(C, 'external')
  externals_prop = "^/A/theta external\n"

  # Set and commit the property.
  change_external(C, externals_prop)


  # Now, /A/C/external is designated as a file external pointing to
  # the binary file /A/theta, but the external file is not there yet.
  # Try to actually insert the external file via a verified update:
  expected_output = svntest.wc.State(wc_dir, {
      'A/C/external'      : Item(status='A '),
    })

  expected_disk = svntest.main.greek_state.copy()
  expected_disk.add({
    'A/theta'      : Item(
                       theta_contents,
                       props={'svn:mime-type' : 'application/octet-stream'}),
    'A/C'          : Item(props={'svn:externals':externals_prop}),
    'A/C/external' : Item(
                       theta_contents,
                       props={'svn:mime-type' : 'application/octet-stream'}),
    })

  expected_status = svntest.actions.get_virginal_state(wc_dir, 3)
  expected_status.add({
    'A/theta'      : Item(status='  ', wc_rev=3),
    'A/C/external' : Item(status='  ', wc_rev=3, switched='X'),
    })

  svntest.actions.run_and_verify_update(wc_dir,
                                        expected_output,
                                        expected_disk,
                                        expected_status,
                                        check_props=True)

#----------------------------------------------------------------------

# Issue #3351.
@Issue(3351)
def update_lose_file_external(sbox):
  "delete a file external"

  sbox.build()
  wc_dir = sbox.wc_dir


  # Create a file external in A/C/external on the file A/mu
  C = sbox.ospath('A/C')
  external = os.path.join(C, 'external')
  externals_prop = "^/A/mu external\n"

  # Set and commit the property.
  change_external(C, externals_prop)


  # Now, /A/C/external is designated as a file external pointing to
  # the file /A/mu, but the external file is not there yet.
  # Try to actually insert the external file via an update:
  expected_output = svntest.wc.State(wc_dir, {
      'A/C/external'      : Item(status='A '),
    })

  expected_disk = svntest.main.greek_state.copy()
  expected_disk.add({
    'A/C'          : Item(props={'svn:externals':externals_prop}),
    'A/C/external' : Item("This is the file 'mu'.\n"),
    })

  expected_status = svntest.actions.get_virginal_state(wc_dir, 2)
  expected_status.add({
    'A/C/external' : Item(status='  ', wc_rev='2', switched='X'),
    })

  svntest.actions.run_and_verify_update(wc_dir,
                                        expected_output,
                                        expected_disk,
                                        expected_status,
                                        check_props=True)

  # now remove the svn:external prop
  svntest.actions.run_and_verify_svn(None, [],
                                     'propdel', 'svn:externals', C)

  # commit the property change
  expected_output = svntest.wc.State(wc_dir, {
    'A/C' : Item(verb='Sending'),
    })

  # (re-use above expected_status)
  expected_status.tweak('A/C', wc_rev = 3)

  svntest.actions.run_and_verify_commit(wc_dir, expected_output,
                                        expected_status)

  # try to actually get rid of the external via an update
  expected_output = svntest.wc.State(wc_dir, {
    'A/C/external'      : Item(verb='Removed external')
  })

  # (re-use above expected_disk)
  expected_disk.tweak('A/C', props = {})
  expected_disk.remove('A/C/external')

  # (re-use above expected_status)
  expected_status.tweak(wc_rev = 3)

  # And assume that the external will be removed.
  expected_status.remove('A/C/external')

  svntest.actions.run_and_verify_update(wc_dir,
                                        expected_output,
                                        expected_disk,
                                        expected_status,
                                        check_props=True)

  probe_paths_missing([sbox.ospath('A/C/external')])


#----------------------------------------------------------------------

# Issue #3351.
@Issue(3351)
def switch_relative_external(sbox):
  "switch a relative external"

  sbox.build()
  wc_dir = sbox.wc_dir
  repo_url = sbox.repo_url

  # Create a relative external in A/D on ../B
  A_path = sbox.ospath('A')
  A_copy_path = sbox.ospath('A_copy')
  A_copy_url = repo_url + '/A_copy'
  D_path = os.path.join(A_path, 'D')
  ext_path = os.path.join(D_path, 'ext')
  externals_prop = "../B ext\n"
  change_external(D_path, externals_prop)

  # Update our working copy, and create a "branch" (A => A_copy)
  expected_output = svntest.wc.State(wc_dir, {
    'A/D/ext/E'         : Item(status='A '),
    'A/D/ext/E/beta'    : Item(status='A '),
    'A/D/ext/E/alpha'   : Item(status='A '),
    'A/D/ext/F'         : Item(status='A '),
    'A/D/ext/lambda'    : Item(status='A '),
  })
  svntest.actions.run_and_verify_update(wc_dir,
                                        expected_output, None, None)
  svntest.actions.run_and_verify_svn(None, [], 'cp',
                                     '--quiet', A_path, A_copy_path)
  svntest.actions.run_and_verify_svn(None, [],
                                     'ci', '-m', 'log msg',
                                     '--quiet', wc_dir)

  # Okay.  We now want to switch A to A_copy, which *should* cause
  # A/D/ext to point to the URL for A_copy/B (instead of A/B).
  svntest.actions.run_and_verify_svn(None, [], 'sw',
                                     A_copy_url, A_path)

  expected_infos = [
    { 'Path' : re.escape(D_path),
      'URL' : sbox.repo_url + '/A_copy/D',
      },
    { 'Path' : re.escape(ext_path),
      'URL' : sbox.repo_url + '/A_copy/B',
      },
    ]
  svntest.actions.run_and_verify_info(expected_infos, D_path, ext_path)

#----------------------------------------------------------------------

# A regression test for a bug in exporting externals from a mixed-depth WC.
def export_sparse_wc_with_externals(sbox):
  "export from a sparse working copy with externals"

  externals_test_setup(sbox)

  repo_url = sbox.repo_url + '/A/B'
  wc_dir = sbox.wc_dir
  # /A/B contains (dir 'E', dir 'F', file 'lambda', external dir 'gamma').
  children = [ 'E', 'F', 'lambda' ]
  ext_children = [ 'gamma' ]

  def wc_paths_of(relative_paths):
    return [ os.path.join(wc_dir, path) for path in relative_paths ]

  child_paths = wc_paths_of(children)
  ext_child_paths = wc_paths_of(ext_children)

  export_target = sbox.add_wc_path('export')

  # Create a working copy with depth=empty itself but children that are
  # depth=infinity.
  svntest.actions.run_and_verify_svn(None, [],
                                     'checkout', '--depth=empty',
                                     repo_url, wc_dir)
  svntest.actions.run_and_verify_svn(None, [],
                                     'update', *child_paths)
  # Export the working copy.
  svntest.actions.run_and_verify_svn(None, [],
                                     'export', wc_dir, export_target)
  # It failed with "'gamma' is not under version control" because the
  # depth-infinity children led it wrongly to try to process externals
  # in the parent.

  svntest.main.safe_rmtree(export_target)

#----------------------------------------------------------------------

# Change external from one repo to another
def relegate_external(sbox):
  "relegate external from one repo to another"

  sbox.build()
  wc_dir = sbox.wc_dir
  repo_dir = sbox.repo_dir
  repo_url = sbox.repo_url
  A_path = sbox.ospath('A')

  # setup an external within the same repository
  externals_desc = '^/A/B/E        external'
  change_external(A_path, externals_desc)
  expected_output = svntest.wc.State(wc_dir, {
    'A/external/alpha'  : Item(status='A '),
    'A/external/beta'   : Item(status='A '),
  })
  svntest.actions.run_and_verify_update(wc_dir,
                                        expected_output, None, None)

  # create another repository
  other_repo_dir, other_repo_url = sbox.add_repo_path('other')
  svntest.main.copy_repos(repo_dir, other_repo_dir, 2)

  # point external to the other repository
  externals_desc = other_repo_url + '/A/B/E        external\n'
  change_external(A_path, externals_desc)

  # Update "relegates", i.e. throws-away and recreates, the external
  expected_output = svntest.wc.State(wc_dir, {
      'A/external'       : Item(), # No A?
      'A/external/alpha' : Item(status='A '),
      'A/external/beta'  : Item(status='A '),
    })
  expected_disk = svntest.main.greek_state.copy()
  expected_disk.tweak('A', props={'svn:externals' : externals_desc})
  expected_disk.add({
      'A/external'       : Item(),
      'A/external/alpha' : Item('This is the file \'alpha\'.\n'),
      'A/external/beta'  : Item('This is the file \'beta\'.\n'),
      })
  expected_status = svntest.actions.get_virginal_state(wc_dir, 3)
  expected_status.add({
    'A/external'        : Item(status='  ', prev_status='X ', wc_rev='2'),
    'A/external/alpha'  : Item(status='  ', wc_rev='2'),
    'A/external/beta'   : Item(status='  ', wc_rev='2'),
  })
  svntest.actions.run_and_verify_update(wc_dir,
                                        expected_output,
                                        expected_disk,
                                        expected_status,
                                        check_props=True)

#----------------------------------------------------------------------

# Issue #3552
@Issue(3552)
def wc_repos_file_externals(sbox):
  "tag directory with file externals from wc to url"

  sbox.build()
  wc_dir = sbox.wc_dir
  repo_url = sbox.repo_url

  # Add a file A/theta.
  theta_path = sbox.ospath('A/theta')
  svntest.main.file_write(theta_path, 'theta', 'w')
  svntest.main.run_svn(None, 'add', theta_path)

  # Created expected output tree for 'svn ci'
  expected_output = svntest.wc.State(wc_dir, {
    'A/theta' : Item(verb='Adding'),
    })

  # Create expected status tree
  expected_status = svntest.actions.get_virginal_state(wc_dir, 1)
  expected_status.add({
    'A/theta' : Item(status='  ', wc_rev=2),
    })

  # Commit the new file, creating revision 2.
  svntest.actions.run_and_verify_commit(wc_dir, expected_output,
                                        expected_status)


  # Create a file external on the file A/theta
  C = sbox.ospath('A/C')
  external = os.path.join(C, 'theta')
  externals_prop = "^/A/theta theta\n"

  # Set and commit the property.
  change_external(C, externals_prop)


  # Now, /A/C/theta is designated as a file external pointing to
  # the file /A/theta, but the external file is not there yet.
  # Try to actually insert the external file via a verified update:
  expected_output = svntest.wc.State(wc_dir, {
      'A/C/theta'      : Item(status='A '),
    })

  expected_disk = svntest.main.greek_state.copy()
  expected_disk.add({
    'A/theta'      : Item('theta'),
    'A/C'          : Item(props={'svn:externals':externals_prop}),
    'A/C/theta'    : Item('theta'),
    })

  expected_status = svntest.actions.get_virginal_state(wc_dir, 3)
  expected_status.add({
    'A/theta'   : Item(status='  ', wc_rev=3),
    'A/C/theta' : Item(status='  ', wc_rev=3, switched='X'),
    })

  svntest.actions.run_and_verify_update(wc_dir,
                                        expected_output,
                                        expected_disk,
                                        expected_status,
                                        check_props=True)

  # Copy A/C to a new tag in the repos
  tag_url = repo_url + '/A/I'
  svntest.main.run_svn(None, 'cp', C, tag_url, '-m', 'create tag')

  # Try to actually insert the external file (A/I/theta) via a verified update:
  expected_output = svntest.wc.State(wc_dir, {
      'A/I'            : Item(status='A '),
      'A/I/theta'      : Item(status='A '),
    })

  expected_disk = svntest.main.greek_state.copy()
  expected_disk.add({
    'A/theta'      : Item('theta'),
    'A/C'          : Item(props={'svn:externals':externals_prop}),
    'A/C/theta'    : Item('theta'),
    'A/I'          : Item(props={'svn:externals':externals_prop}),
    'A/I/theta'    : Item('theta'),
    })

  expected_status = svntest.actions.get_virginal_state(wc_dir, 4)
  expected_status.add({
    'A/theta'   : Item(status='  ', wc_rev=4),
    'A/C/theta' : Item(status='  ', wc_rev=4, switched='X'),
    'A/I'       : Item(status='  ', wc_rev=4),
    'A/I/theta' : Item(status='  ', wc_rev=4, switched='X'),
    })

  svntest.actions.run_and_verify_update(wc_dir,
                                        expected_output,
                                        expected_disk,
                                        expected_status,
                                        check_props=True)

#----------------------------------------------------------------------
@SkipUnless(svntest.main.server_has_mergeinfo)
@Issue(3843)
def merge_target_with_externals(sbox):
  "merge target with externals"

  # Test for a problem the plagued Subversion in the pre-1.7-single-DB world:
  # Externals in a merge target would get meaningless explicit mergeinfo set
  # on them.  See http://svn.haxx.se/dev/archive-2010-08/0088.shtml
  externals_test_setup(sbox)
  wc_dir = sbox.wc_dir
  repo_url = sbox.repo_url

  # Some paths we'll care about
  A_path              = sbox.ospath('A')
  A_branch_path       = sbox.ospath('A-branch')
  A_gamma_branch_path = sbox.ospath('A-branch/D/gamma')

  svntest.actions.run_and_verify_svn(None, [],
                                     'checkout',
                                     repo_url, wc_dir)

  # Setup A/external as file external to A/mu
  # and A/external-pinned as a pinned file external to A/mu
  externals_prop = "^/A/mu external\n^/A/mu@6 external-pinned\n"
  change_external(sbox.ospath('A'), externals_prop)

  # Branch A@1 to A-branch and make a simple text change on the latter in r8.
  svntest.actions.run_and_verify_svn(None, [], 'copy', A_path + '@1',
                                     A_branch_path)
  svntest.actions.run_and_verify_svn(None, [], 'ci',
                                     '-m', 'make a copy', wc_dir)
  svntest.main.file_write(A_gamma_branch_path, "The new gamma!\n")
  svntest.actions.run_and_verify_svn(None, [], 'ci',
                                     '-m', 'branch edit', wc_dir)
  expected_output = svntest.wc.State(wc_dir, {
    'A/external'        : Item(status='A '),
    'A/external-pinned' : Item(status='A '),
  })
  svntest.actions.run_and_verify_update(wc_dir,
                                        expected_output, None, None)

  # Merge r8 from A-branch back to A.  There should be explicit mergeinfo
  # only at the root of A; the externals should not get any.
  svntest.actions.run_and_verify_svn(None, [], 'merge', '-c8',
                                     repo_url + '/A-branch', A_path)
  svntest.actions.run_and_verify_svn(
    ["Properties on '" + A_path + "':\n",
     "  svn:mergeinfo\n",
     "    /A-branch:8\n"],
    [], 'pg', svntest.main.SVN_PROP_MERGEINFO, '-vR', wc_dir)

def update_modify_file_external(sbox):
  "update that modifies a file external"

  sbox.build()
  wc_dir = sbox.wc_dir

  # Setup A/external as file external to A/mu
  externals_prop = "^/A/mu external\n"
  change_external(sbox.ospath('A'), externals_prop)
  expected_output = svntest.wc.State(wc_dir, {
      'A/external'      : Item(status='A '),
    })
  expected_disk = svntest.main.greek_state.copy()
  expected_disk.add({
    'A'          : Item(props={'svn:externals':externals_prop}),
    'A/external' : Item("This is the file 'mu'.\n"),
    })
  expected_status = svntest.actions.get_virginal_state(wc_dir, 2)
  expected_status.add({
    'A/external' : Item(status='  ', wc_rev='2', switched='X'),
    })
  svntest.actions.run_and_verify_update(wc_dir,
                                        expected_output,
                                        expected_disk,
                                        expected_status,
                                        check_props=True)

  # Modify A/mu
  svntest.main.file_append(sbox.ospath('A/mu'), 'appended mu text')
  expected_output = svntest.wc.State(wc_dir, {
    'A/mu' : Item(verb='Sending'),
    })
  expected_status.tweak('A/mu', wc_rev=3)
  svntest.actions.run_and_verify_commit(wc_dir,
                                        expected_output,
                                        expected_status)

  # Update to modify the file external, this asserts in update_editor.c
  expected_output = svntest.wc.State(wc_dir, {
      'A/external'      : Item(status='U '),
    })
  expected_disk.tweak('A/mu', 'A/external',
                      contents=expected_disk.desc['A/mu'].contents
                      + 'appended mu text')
  expected_status = svntest.actions.get_virginal_state(wc_dir, 3)
  expected_status.add({
    'A/external' : Item(status='  ', wc_rev='3', switched='X'),
    })
  svntest.actions.run_and_verify_update(wc_dir,
                                        expected_output,
                                        expected_disk,
                                        expected_status,
                                        check_props=True)

# Test for issue #2267
@Issue(2267)
def update_external_on_locally_added_dir(sbox):
  "update an external on a locally added dir"

  external_url_for = externals_test_setup(sbox)
  wc_dir         = sbox.wc_dir

  repo_url       = sbox.repo_url
  other_repo_url = repo_url + ".other"

  # Checkout a working copy
  svntest.actions.run_and_verify_svn(None, [],
                                     'checkout',
                                     repo_url, wc_dir)

  # Add one new external item to the property on A/foo.  The new item is
  # "exdir_E", deliberately added in the middle not at the end.
  new_externals_desc = \
           external_url_for["A/D/exdir_A"] + " exdir_A"           + \
           "\n"                                                   + \
           external_url_for["A/D/exdir_A/G/"] + " exdir_A/G/"     + \
           "\n"                                                   + \
           "exdir_E           " + other_repo_url + "/A/B/E"       + \
           "\n"                                                   + \
           "exdir_A/H -r 1 " + external_url_for["A/D/exdir_A/H"]  + \
           "\n"                                                   + \
           external_url_for["A/D/x/y/z/blah"] + " x/y/z/blah"     + \
           "\n"

  # Add A/foo and set the property on it
  new_dir = sbox.ospath("A/foo")
  sbox.simple_mkdir("A/foo")
  change_external(new_dir, new_externals_desc, commit=False)

  # Update the working copy, see if we get the new item.
  expected_output = svntest.wc.State(wc_dir, {
    'A/foo/exdir_A/B'   : Item(status='A '),
    'A/foo/exdir_A/B/E' : Item(status='A '),
    'A/foo/exdir_A/B/E/beta': Item(status='A '),
    'A/foo/exdir_A/B/E/alpha': Item(status='A '),
    'A/foo/exdir_A/B/F' : Item(status='A '),
    'A/foo/exdir_A/B/lambda': Item(status='A '),
    'A/foo/exdir_A/D'   : Item(status='A '),
    'A/foo/exdir_A/D/G' : Item(status='A '),
    'A/foo/exdir_A/D/G/rho': Item(status='A '),
    'A/foo/exdir_A/D/G/pi': Item(status='A '),
    'A/foo/exdir_A/D/G/tau': Item(status='A '),
    'A/foo/exdir_A/D/gamma': Item(status='A '),
    'A/foo/exdir_A/D/H' : Item(status='A '),
    'A/foo/exdir_A/D/H/chi': Item(status='A '),
    'A/foo/exdir_A/D/H/omega': Item(status='A '),
    'A/foo/exdir_A/D/H/psi': Item(status='A '),
    'A/foo/exdir_A/C'   : Item(status='A '),
    'A/foo/exdir_A/mu'  : Item(status='A '),
    'A/foo/exdir_A/H/omega': Item(status='A '),
    'A/foo/exdir_A/H/psi': Item(status='A '),
    'A/foo/exdir_A/H/chi': Item(status='A '),
    'A/foo/exdir_A/G/tau': Item(status='A '),
    'A/foo/exdir_A/G/rho': Item(status='A '),
    'A/foo/exdir_A/G/pi': Item(status='A '),
    'A/foo/x/y/z/blah/F': Item(status='A '),
    'A/foo/x/y/z/blah/E': Item(status='A '),
    'A/foo/x/y/z/blah/E/beta': Item(status='A '),
    'A/foo/x/y/z/blah/E/alpha': Item(status='A '),
    'A/foo/x/y/z/blah/lambda': Item(status='A '),
    'A/foo/exdir_E/beta': Item(status='A '),
    'A/foo/exdir_E/alpha': Item(status='A '),
  })
  svntest.actions.run_and_verify_update(wc_dir,
                                        expected_output, None, None)

  probe_paths_exist([sbox.ospath('A/foo/exdir_E')])

# Test for issue #2267
@Issue(2267)
def switch_external_on_locally_added_dir(sbox):
  "switch an external on a locally added dir"

  external_url_for = externals_test_setup(sbox)
  wc_dir         = sbox.wc_dir

  repo_url       = sbox.repo_url
  other_repo_url = repo_url + ".other"
  A_path         = repo_url + "/A"
  A_copy_path    = repo_url + "/A_copy"

  # Create a branch of A
  # Checkout a working copy
  svntest.actions.run_and_verify_svn(None, [],
                                     'copy',
                                     A_path, A_copy_path,
                                     '-m', 'Create branch of A')

  # Checkout a working copy
  svntest.actions.run_and_verify_svn(None, [],
                                     'checkout',
                                     A_path, wc_dir)

  # Add one new external item to the property on A/foo.  The new item is
  # "exdir_E", deliberately added in the middle not at the end.
  new_externals_desc = \
           external_url_for["A/D/exdir_A"] + " exdir_A"           + \
           "\n"                                                   + \
           external_url_for["A/D/exdir_A/G/"] + " exdir_A/G/"     + \
           "\n"                                                   + \
           "exdir_E           " + other_repo_url + "/A/B/E"       + \
           "\n"                                                   + \
           "exdir_A/H -r 1 " + external_url_for["A/D/exdir_A/H"]  + \
           "\n"                                                   + \
           external_url_for["A/D/x/y/z/blah"] + " x/y/z/blah"     + \
           "\n"

  # Add A/foo and set the property on it
  new_dir = sbox.ospath("foo")
  sbox.simple_mkdir("foo")
  change_external(new_dir, new_externals_desc, commit=False)

  # Switch the working copy to the branch, see if we get the new item.
  svntest.actions.run_and_verify_svn(None, [], 'sw', A_copy_path, wc_dir)

  probe_paths_exist([sbox.ospath('foo/exdir_E')])

@Issue(3819)
def file_external_in_sibling(sbox):
  "update a file external in sibling dir"

  sbox.build()
  wc_dir = sbox.wc_dir

  # Setup A2/iota as file external to ^/iota
  externals_prop = "^/iota iota\n"
  sbox.simple_mkdir("A2")
  change_external(sbox.ospath('A2'), externals_prop)
  sbox.simple_update()

  os.chdir(sbox.ospath("A"))
  svntest.actions.run_and_verify_svn(svntest.actions.expected_noop_update_output(2),
                            [], 'update')

@Issue(3823)
def file_external_update_without_commit(sbox):
  "update a file external without committing target"

  sbox.build(read_only=True)

  # Setup A2/iota as file external to ^/iota
  externals_prop = "^/iota iota\n"
  sbox.simple_mkdir("A2")
  change_external(sbox.ospath('A2'), externals_prop, commit=False)
  # A2/ is an uncommitted added dir with an svn:externals property set.
  sbox.simple_update()

def incoming_file_on_file_external(sbox):
  "bring in a new file over a file external"

  sbox.build()
  repo_url = sbox.repo_url
  wc_dir = sbox.wc_dir

  change_external(sbox.wc_dir, "^/A/B/lambda ext\n")
  # And bring in the file external
  sbox.simple_update()

  svntest.main.run_svn(None, 'cp', repo_url + '/iota',
                       repo_url + '/ext', '-m', 'copied')

  # Until recently this took over the file external as 'E'xisting file, with
  # a textual conflict.
  expected_output = svntest.wc.State(wc_dir, {
    'ext' : Item(verb='Skipped'),
    })
  svntest.actions.run_and_verify_update(wc_dir, expected_output, None, None)

def incoming_file_external_on_file(sbox):
  "bring in a new file external over a file"

  sbox.build()
  wc_dir = sbox.wc_dir

  change_external(sbox.wc_dir, "^/A/B/lambda iota\n")

  # And bring in the file external
  # Returns an error: WC status of external unchanged.
  svntest.actions.run_and_verify_update(wc_dir, None, None, None,
                                        '.*The file external.*overwrite.*')


def exclude_externals(sbox):
  "try to exclude externals"

  external_url_for = externals_test_setup(sbox)
  wc_dir         = sbox.wc_dir
  repo_url       = sbox.repo_url

  # Checkout two working copies.
  svntest.actions.run_and_verify_svn(None, [],
                                     'checkout',
                                     repo_url, wc_dir)

  # Excluding a file external should either fail (current behavior)
  # or register the file external as excluded (preferred behavior)
  svntest.actions.run_and_verify_update(sbox.ospath('A/B/gamma'),
                                        None, None, None,
                                        '.*Cannot exclude.*', False,
                                        '--set-depth', 'exclude',
                                        sbox.ospath('A/B/gamma'))

  # Excluding a directory external should either fail (current behavior)
  # or register the directory external as excluded (preferred behavior)
  svntest.actions.run_and_verify_update(sbox.ospath('A/C/exdir_G'),
                                        None, None, None,
                                        '.*Cannot exclude.*', False,
                                        '--set-depth', 'exclude',
                                        sbox.ospath('A/C/exdir_G'))

  # And after an update with --set-depth infinity all externals should
  # be there again.
  expected_status = svntest.actions.get_virginal_state(wc_dir, 6)
  expected_status.add({
      'A/B/gamma'         : Item(status='  ', wc_rev='6', switched='X'),

      'A/C/exdir_H'       : Item(status='  ', prev_status='X ', wc_rev='1'),
      'A/C/exdir_H/omega' : Item(status='  ', wc_rev='1'),
      'A/C/exdir_H/chi'   : Item(status='  ', wc_rev='1'),
      'A/C/exdir_H/psi'   : Item(status='  ', wc_rev='1'),

      'A/C/exdir_G'       : Item(status='  ', prev_status='X ', wc_rev='5'),
      'A/C/exdir_G/pi'    : Item(status='  ', wc_rev='5'),
      'A/C/exdir_G/rho'   : Item(status='  ', wc_rev='5'),
      'A/C/exdir_G/tau'   : Item(status='  ', wc_rev='5'),

      'A/D/exdir_A'       : Item(status='  ', prev_status='X ', wc_rev='5'),
      'A/D/exdir_A/H'     : Item(status='  ', wc_rev='1'),
      'A/D/exdir_A/H/psi' : Item(status='  ', wc_rev='1'),
      'A/D/exdir_A/H/chi' : Item(status='  ', wc_rev='1'),
      'A/D/exdir_A/H/omega': Item(status='  ', wc_rev='1'),
      'A/D/exdir_A/D'     : Item(status='  ', wc_rev='5'),
      'A/D/exdir_A/D/H'   : Item(status='  ', wc_rev='5'),
      'A/D/exdir_A/D/H/chi': Item(status='  ', wc_rev='5'),
      'A/D/exdir_A/D/H/omega': Item(status='  ', wc_rev='5'),
      'A/D/exdir_A/D/H/psi': Item(status='  ', wc_rev='5'),
      'A/D/exdir_A/D/G'   : Item(status='  ', wc_rev='5'),
      'A/D/exdir_A/D/G/pi': Item(status='  ', wc_rev='5'),
      'A/D/exdir_A/D/G/rho': Item(status='  ', wc_rev='5'),
      'A/D/exdir_A/D/G/tau': Item(status='  ', wc_rev='5'),
      'A/D/exdir_A/D/gamma': Item(status='  ', wc_rev='5'),
      'A/D/exdir_A/B'     : Item(status='  ', wc_rev='5'),
      'A/D/exdir_A/B/F'   : Item(status='  ', wc_rev='5'),
      'A/D/exdir_A/B/E'   : Item(status='  ', wc_rev='5'),
      'A/D/exdir_A/B/E/beta': Item(status='  ', wc_rev='5'),
      'A/D/exdir_A/B/E/alpha': Item(status='  ', wc_rev='5'),
      'A/D/exdir_A/B/lambda': Item(status='  ', wc_rev='5'),
      'A/D/exdir_A/C'     : Item(status='  ', wc_rev='5'),
      'A/D/exdir_A/G'     : Item(status='  ', wc_rev='5'),
      'A/D/exdir_A/G/tau' : Item(status='  ', wc_rev='5'),
      'A/D/exdir_A/G/rho' : Item(status='  ', wc_rev='5'),
      'A/D/exdir_A/G/pi'  : Item(status='  ', wc_rev='5'),
      'A/D/exdir_A/mu'    : Item(status='  ', wc_rev='5'),

      'A/D/x'             : Item(status='X '),
      'A/D/x/y/z/blah'    : Item(status='  ', wc_rev='5'),
      'A/D/x/y/z/blah/E'  : Item(status='  ', wc_rev='5'),
      'A/D/x/y/z/blah/E/alpha': Item(status='  ', wc_rev='5'),
      'A/D/x/y/z/blah/E/beta': Item(status='  ', wc_rev='5'),
      'A/D/x/y/z/blah/lambda': Item(status='  ', wc_rev='5'),
      'A/D/x/y/z/blah/F'  : Item(status='  ', wc_rev='5'),
  })
  svntest.actions.run_and_verify_update(wc_dir,
                                        None, None, expected_status,
                                        [], False,
                                        '--set-depth', 'infinity', wc_dir)

def file_externals_different_url(sbox):
  "update file externals via different url"

  sbox.build()

  wc_dir = sbox.wc_dir
  r1_url = sbox.repo_url

  r2_dir, r2_url = sbox.add_repo_path('2')
  svntest.main.copy_repos(sbox.repo_dir, r2_dir, 1, 0)


  sbox.simple_propset('svn:externals',
                      'r1-e-1   ' + r1_url + '/iota\n' +
                      r1_url + '/iota  r1-e-2\n' +
                      'r2-e-1   ' + r2_url + '/iota\n' +
                      r2_url + '/iota  r2-e-2\n' +
                      '^/iota  rr-e-1\n', '')

  # All file externals appear in the working copy, with normalised URLs.
  expected_output = svntest.wc.State(wc_dir, {
    'r1-e-1'            : Item(status='A '),
    'r1-e-2'            : Item(status='A '),
    'r2-e-1'            : Item(status='A '),
    'r2-e-2'            : Item(status='A '),
    'rr-e-1'            : Item(status='A '),
  })

  expected_status = actions.get_virginal_state(wc_dir, 1)
  expected_status.tweak('', status=' M')
  expected_status.add({
    'r2-e-1'            : Item(status='  ', wc_rev='1', switched='X'),
    'r1-e-1'            : Item(status='  ', wc_rev='1', switched='X'),
    'r1-e-2'            : Item(status='  ', wc_rev='1', switched='X'),
    'rr-e-1'            : Item(status='  ', wc_rev='1', switched='X'),
    'r2-e-2'            : Item(status='  ', wc_rev='1', switched='X'),
  })

  svntest.actions.run_and_verify_update(wc_dir,
                                        expected_output, None,
                                        expected_status)

  # Verify that all file external URLs are descendants of r1_url
  for e in ['r1-e-1', 'r1-e-2', 'r2-e-1', 'r2-e-2', 'rr-e-1']:
    actions.run_and_verify_info([{'Repository Root' : r1_url}],
                                os.path.join(sbox.wc_dir, e))


  svntest.actions.run_and_verify_svn(None, [],
                                     'relocate', r1_url, r2_url, wc_dir)


  # URLs of existing file externals are silently rewritten
  expected_output = svntest.wc.State(wc_dir, {
  })

  svntest.actions.run_and_verify_update(wc_dir,
                                        expected_output, None,
                                        expected_status)

  # Verify that all file external URLs are descendants of r2_url
  for e in ['r1-e-1', 'r1-e-2', 'r2-e-1', 'r2-e-2', 'rr-e-1']:
    actions.run_and_verify_info([{'Repository Root' : r2_url}],
                                os.path.join(sbox.wc_dir, e))


def file_external_in_unversioned(sbox):
  "file external in unversioned dir"

  sbox.build()
  wc_dir = sbox.wc_dir

  sbox.simple_propset('svn:externals', '^/A/mu X/mu', 'A')

  expected_output = svntest.wc.State(wc_dir, {
    'A/X/mu' : Item(status='A '),
  })
  svntest.actions.run_and_verify_update(wc_dir, expected_output, None, None)

  # At one point this failed with SVN_DEBUG wcng consistency checks enabled
  svntest.actions.run_and_verify_svn(None, [], 'cleanup', wc_dir)


from svntest import verify, actions, main

@Issue(3589, 4000)
def copy_file_externals(sbox):
  "a WC->WC copy should exclude file externals"

  #  svntest.factory.make(sbox,"""
  #  svn mkdir X
  #  ### manual edit: add '\n ^/A/mu xmu' to externals definition:
  #  svn ps svn:externals "^/iota xiota" X
  #  """)

  sbox.build()
  wc_dir = sbox.wc_dir

  X = sbox.ospath('X')

  # svn mkdir X
  expected_stdout = ['A         ' + X + '\n']

  actions.run_and_verify_svn2(expected_stdout, [], 0, 'mkdir', X)

  # svn ps svn:externals "^/iota xiota" X
  expected_stdout = ["property 'svn:externals' set on '" + X + "'\n"]

  actions.run_and_verify_svn2(expected_stdout, [], 0, 'ps',
    'svn:externals', '''
    ^/iota xiota
    ^/A/mu xmu
    ''', X)

  #  svntest.factory.make(sbox, '''
  #  svn ci
  #  svn up
  #  # have a commit on one of the files
  #  echo mod >> X/xmu
  #  svn ci X/xmu
  #  svn up
  #  # now perform the WC->WC copy
  #  svn cp X X_copy
  #  ### manual edit: add a verify_disk(check_props=True) here
  #  svn ci
  #  ### manual edit: add check_props=True to below update
  #  svn up
  #  ''')

  X = sbox.ospath('X')
  X_copy = sbox.ospath('X_copy')
  X_xmu = sbox.ospath('X/xmu')

  # svn ci
  expected_output = svntest.wc.State(wc_dir, {
    'X'                 : Item(verb='Adding'),
  })

  expected_status = actions.get_virginal_state(wc_dir, 1)
  expected_status.add({
    'X'                 : Item(status='  ', wc_rev='2'),
  })

  actions.run_and_verify_commit(wc_dir, expected_output, expected_status)

  # svn up
  expected_output = svntest.wc.State(wc_dir, {
    'X/xmu'             : Item(status='A '),
    'X/xiota'           : Item(status='A '),
  })

  expected_disk = svntest.main.greek_state.copy()
  expected_disk.add({
    'X'                 : Item(),
    'X/xiota'           : Item(contents="This is the file 'iota'.\n"),
    'X/xmu'             : Item(contents="This is the file 'mu'.\n"),
  })

  expected_status.add({
    'X/xiota'           : Item(status='  ', wc_rev='2', switched='X'),
    'X/xmu'             : Item(status='  ', wc_rev='2', switched='X'),
  })
  expected_status.tweak(wc_rev='2')

  actions.run_and_verify_update(wc_dir, expected_output, expected_disk,
                                expected_status)

  # have a commit on one of the files
  # echo mod >> X/xmu
  main.file_append(X_xmu, 'mod\n')

  # svn ci X/xmu
  expected_output = svntest.wc.State(wc_dir, {
    'X/xmu'             : Item(verb='Sending'),
  })

  expected_status.tweak('X/xmu', wc_rev='3')

  actions.run_and_verify_commit(wc_dir, expected_output, expected_status,
                                [], X_xmu)

  # svn up
  expected_output = svntest.wc.State(wc_dir, {
    'A/mu'              : Item(status='U '),
  })

  expected_disk.tweak('A/mu', 'X/xmu',
    contents="This is the file 'mu'.\nmod\n")

  expected_status.tweak(wc_rev='3')

  actions.run_and_verify_update(wc_dir, expected_output, expected_disk,
                                expected_status)

  # now perform the WC->WC copy
  # svn cp X X_copy
  expected_stdout = ['A         ' + X_copy + '\n']

  actions.run_and_verify_svn2(expected_stdout, [], 0, 'cp', X,
    X_copy)

  # svn ci
  expected_output = svntest.wc.State(wc_dir, {
    'X_copy'            : Item(verb='Adding'),
  })

  expected_status.add({
    'X_copy'            : Item(status='  ', wc_rev='4'),
  })

  actions.run_and_verify_commit(wc_dir, expected_output, expected_status)

  # verify disk state, also verifying props
  expected_disk.add({
    'X_copy'            : Item(),
  })
  expected_disk.tweak('X', 'X_copy',
    props={'svn:externals' : '\n    ^/iota xiota\n    ^/A/mu xmu\n    \n'})

  actions.verify_disk(wc_dir, expected_disk, True)

  # svn up
  expected_output = svntest.wc.State(wc_dir, {
    'X_copy/xmu'        : Item(status='A '),
    'X_copy/xiota'      : Item(status='A '),
  })

  expected_disk.add({
    'X_copy/xmu'        : Item(contents="This is the file 'mu'.\nmod\n"),
    'X_copy/xiota'      : Item(contents="This is the file 'iota'.\n"),
  })

  expected_status.add({
    'X_copy/xmu'        : Item(status='  ', wc_rev='4', switched='X'),
    'X_copy/xiota'      : Item(status='  ', wc_rev='4', switched='X'),
  })
  expected_status.tweak(wc_rev='4')

  actions.run_and_verify_update(wc_dir, expected_output, expected_disk,
                                expected_status, check_props=True)

def commit_include_externals(sbox):
  "commit --include-externals"
  # svntest.factory.make(sbox, """
  #   mkdir Z
  #   echo 'This is the file zeta.' > Z/zeta
  #   svn add Z
  #   svn mkdir --parents Xpegged X/Y
  #   svn ci
  #   svn up
  #   svn ps svn:externals "^/Z xZ" A/D/H
  #   svn ps svn:externals "^/iota@1 Xpegged/xiota" wc_dir
  #   # ^^^ manually set externals to:
  #   #  ^/iota@1 Xpegged/xiota
  #   #  -r1 ^/A/B/E Xpegged/xE
  #   #  ^/A/mu X/xmu
  #   #  ^/A/B/lambda X/Y/xlambda
  #   #  ^/A/D/G X/xG
  #   #  ^/A/D/H X/Y/xH
  #   """)
  # exit(0)

  sbox.build()
  wc_dir = sbox.wc_dir

  A_D_H = sbox.ospath('A/D/H')
  X = sbox.ospath('X')
  X_Y = sbox.ospath('X/Y')
  Xpegged = sbox.ospath('Xpegged')
  Z = sbox.ospath('Z')
  Z_zeta = sbox.ospath('Z/zeta')

  # mkdir Z
  os.makedirs(Z)

  # echo 'This is the file zeta.' > Z/zeta
  main.file_write(Z_zeta, 'This is the file zeta.\n')

  # svn add Z
  expected_stdout = verify.UnorderedOutput([
    'A         ' + Z + '\n',
    'A         ' + Z_zeta + '\n',
  ])

  actions.run_and_verify_svn2(expected_stdout, [], 0, 'add', Z)

  # svn mkdir --parents Xpegged X/Y
  expected_stdout = verify.UnorderedOutput([
    'A         ' + Xpegged + '\n',
    'A         ' + X + '\n',
    'A         ' + X_Y + '\n',
  ])

  actions.run_and_verify_svn2(expected_stdout, [], 0, 'mkdir',
    '--parents', Xpegged, X_Y)

  # svn ci
  expected_output = svntest.wc.State(wc_dir, {
    'Z'                 : Item(verb='Adding'),
    'Z/zeta'            : Item(verb='Adding'),
    'X'                 : Item(verb='Adding'),
    'X/Y'               : Item(verb='Adding'),
    'Xpegged'           : Item(verb='Adding'),
  })

  expected_status = actions.get_virginal_state(wc_dir, 1)
  expected_status.add({
    'Z'                 : Item(status='  ', wc_rev='2'),
    'Z/zeta'            : Item(status='  ', wc_rev='2'),
    'X'                 : Item(status='  ', wc_rev='2'),
    'X/Y'               : Item(status='  ', wc_rev='2'),
    'Xpegged'           : Item(status='  ', wc_rev='2'),
  })

  actions.run_and_verify_commit(wc_dir, expected_output, expected_status)

  # svn up
  expected_output = svntest.wc.State(wc_dir, {})

  expected_disk = svntest.main.greek_state.copy()
  expected_disk.add({
    'Z'                 : Item(),
    'Z/zeta'            : Item(contents="This is the file zeta.\n"),
    'Xpegged'           : Item(),
    'X'                 : Item(),
    'X/Y'               : Item(),
  })

  expected_status.tweak(wc_rev='2')

  actions.run_and_verify_update(wc_dir, expected_output, expected_disk,
                                expected_status)

  # svn ps svn:externals "^/Z xZ" A/D/H
  expected_stdout = ["property 'svn:externals' set on '" + A_D_H + "'\n"]

  actions.run_and_verify_svn2(expected_stdout, [], 0, 'ps',
    'svn:externals', '^/Z xZ', A_D_H)

  # svn ps svn:externals "^/iota@1 Xpegged/xiota" wc_dir
  expected_stdout = ["property 'svn:externals' set on '" + wc_dir + "'\n"]

  actions.run_and_verify_svn2(expected_stdout, [], 0, 'ps',
    'svn:externals',
    '''
      ^/iota@1 Xpegged/xiota
      -r1 ^/A/B/E Xpegged/xE
      ^/A/mu X/xmu
      ^/A/B/lambda X/Y/xlambda
      ^/A/D/G X/xG
      ^/A/D/H X/Y/xH
    ''', wc_dir)

  # svntest.factory.make(sbox, prev_disk=expected_disk,
  #                      prev_status=expected_status,
  #                      commands = """
  #   svn ci
  #   svn up
  #   echo mod >> Xpegged/xE/alpha
  #   echo mod >> X/xmu
  #   echo mod >> X/Y/xlambda
  #   echo mod >> X/xG/pi
  #   echo mod >> X/Y/xH/chi
  #   echo mod >> X/Y/xH/xZ/zeta
  #   svn status
  #   # Expect no externals to be committed
  #   svn ci
  #   # Expect no externals to be committed, because pegged
  #   svn ci --include-externals Xpegged
  #   # Expect no externals to be committed, because of depth
  #   svn ci --depth=immediates --include-externals
  #   # Expect only unpegged externals to be committed (those in X/)
  #   svn ci --include-externals
  #   # ### Below, manually add:
  #   # expected_status.tweak('A/D/H/xZ', 'Xpegged/xE', 'X/Y/xH', 'X/xG',
  #   #                       wc_rev=None)
  #   svn up
  #   # new mods to check more cases
  #   echo mod >> X/xmu
  #   echo mod >> X/Y/xlambda
  #   echo mod >> X/xG/pi
  #   echo mod >> X/Y/xH/chi
  #   echo mod >> X/Y/xH/xZ/zeta
  #   svn status
  #   # Expect no externals to be committed, because of depth
  #   svn ci --include-externals --depth=empty X
  #   # Expect only file external xmu to be committed, because of depth
  #   svn ci --include-externals --depth=files X
  #   svn status
  #   # ### Below, manually add:
  #   # expected_status.tweak('A/D/H/xZ', 'Xpegged/xE', 'X/Y/xH', 'X/xG',
  #   #                       wc_rev=None)
  #   svn up
  #   echo mod >> X/xG/pi
  #   svn status
  #   # Expect explicit targets to be committed
  #   svn ci X/Y/xlambda X/xG
  #   svn status
  #   """)

  X = sbox.ospath('X')
  X_xG = sbox.ospath('X/xG')
  X_xG_pi = sbox.ospath('X/xG/pi')
  X_xmu = sbox.ospath('X/xmu')
  X_Y_xH_chi = sbox.ospath('X/Y/xH/chi')
  X_Y_xH_xZ_zeta = sbox.ospath('X/Y/xH/xZ/zeta')
  X_Y_xlambda = sbox.ospath('X/Y/xlambda')
  Xpegged = sbox.ospath('Xpegged')
  Xpegged_xE_alpha = sbox.ospath('Xpegged/xE/alpha')

  # svn ci
  expected_output = svntest.wc.State(wc_dir, {
    ''                  : Item(verb='Sending'),
    'A/D/H'             : Item(verb='Sending'),
  })

  expected_status.tweak('', 'A/D/H', wc_rev='3')

  actions.run_and_verify_commit(wc_dir, expected_output, expected_status)

  # svn up
  expected_output = svntest.wc.State(wc_dir, {
    'X/xmu'             : Item(status='A '),
    'X/xG/tau'          : Item(status='A '),
    'X/xG/rho'          : Item(status='A '),
    'X/xG/pi'           : Item(status='A '),
    'X/Y/xH'            : Item(status=' U'),
    'X/Y/xH/psi'        : Item(status='A '),
    'X/Y/xH/xZ/zeta'    : Item(status='A '),
    'X/Y/xH/chi'        : Item(status='A '),
    'X/Y/xH/omega'      : Item(status='A '),
    'X/Y/xlambda'       : Item(status='A '),
    'A/D/H/xZ/zeta'     : Item(status='A '),
    'Xpegged/xiota'     : Item(status='A '),
    'Xpegged/xE/alpha'  : Item(status='A '),
    'Xpegged/xE/beta'   : Item(status='A '),
  })

  expected_disk.add({
    'Xpegged/xE'        : Item(),
    'Xpegged/xE/beta'   : Item(contents="This is the file 'beta'.\n"),
    'Xpegged/xE/alpha'  : Item(contents="This is the file 'alpha'.\n"),
    'Xpegged/xiota'     : Item(contents="This is the file 'iota'.\n"),
    'A/D/H/xZ'          : Item(),
    'A/D/H/xZ/zeta'     : Item(contents="This is the file zeta.\n"),
    'X/Y/xlambda'       : Item(contents="This is the file 'lambda'.\n"),
    'X/Y/xH'            : Item(),
    'X/Y/xH/chi'        : Item(contents="This is the file 'chi'.\n"),
    'X/Y/xH/xZ'         : Item(),
    'X/Y/xH/xZ/zeta'    : Item(contents="This is the file zeta.\n"),
    'X/Y/xH/psi'        : Item(contents="This is the file 'psi'.\n"),
    'X/Y/xH/omega'      : Item(contents="This is the file 'omega'.\n"),
    'X/xmu'             : Item(contents="This is the file 'mu'.\n"),
    'X/xG'              : Item(),
    'X/xG/tau'          : Item(contents="This is the file 'tau'.\n"),
    'X/xG/rho'          : Item(contents="This is the file 'rho'.\n"),
    'X/xG/pi'           : Item(contents="This is the file 'pi'.\n"),
  })

  expected_status.tweak(wc_rev='3')
  expected_status.add({
    'A/D/H/xZ'          : Item(status='  ', prev_status='X ', wc_rev='3'),
    'A/D/H/xZ/zeta'     : Item(status='  ', wc_rev='3'),

    'Xpegged/xiota'     : Item(status='  ', wc_rev='1', switched='X'),
    'Xpegged/xE'        : Item(status='  ', prev_status='X ', wc_rev='1'),
    'Xpegged/xE/alpha'  : Item(status='  ', wc_rev='1'),
    'Xpegged/xE/beta'   : Item(status='  ', wc_rev='1'),

    'X/Y/xH'            : Item(status='  ', prev_status='X ', wc_rev='3'),
    'X/Y/xH/psi'        : Item(status='  ', wc_rev='3'),
    'X/Y/xH/omega'      : Item(status='  ', wc_rev='3'),
    'X/Y/xH/chi'        : Item(status='  ', wc_rev='3'),
    'X/Y/xH/xZ'         : Item(status='  ', prev_status='X ', wc_rev='3'),
    'X/Y/xH/xZ/zeta'    : Item(status='  ', wc_rev='3'),

    'X/Y/xlambda'       : Item(status='  ', wc_rev='3', switched='X'),
    'X/xmu'             : Item(status='  ', wc_rev='3', switched='X'),

    'X/xG'              : Item(status='  ', prev_status='X ', wc_rev='3'),
    'X/xG/rho'          : Item(status='  ', wc_rev='3'),
    'X/xG/tau'          : Item(status='  ', wc_rev='3'),
    'X/xG/pi'           : Item(status='  ', wc_rev='3'),
  })
  expected_status.tweak('Xpegged/xiota', wc_rev='1')

  actions.run_and_verify_update(wc_dir, expected_output, expected_disk,
                                expected_status)

  # echo mod >> Xpegged/xE/alpha
  main.file_append(Xpegged_xE_alpha, 'mod\n')

  # echo mod >> X/xmu
  main.file_append(X_xmu, 'mod\n')

  # echo mod >> X/Y/xlambda
  main.file_append(X_Y_xlambda, 'mod\n')

  # echo mod >> X/xG/pi
  main.file_append(X_xG_pi, 'mod\n')

  # echo mod >> X/Y/xH/chi
  main.file_append(X_Y_xH_chi, 'mod\n')

  # echo mod >> X/Y/xH/xZ/zeta
  main.file_append(X_Y_xH_xZ_zeta, 'mod\n')

  # svn status
  expected_status.tweak('X/Y/xlambda', 'X/xmu', 'X/Y/xH/chi',
                        'X/Y/xH/xZ/zeta', 'Xpegged/xE/alpha',
                        'X/xG/pi', status='M ')

  actions.run_and_verify_unquiet_status(wc_dir, expected_status)

  # Expect no externals to be committed
  # svn ci
  expected_output = svntest.wc.State(wc_dir, {})

  actions.run_and_verify_commit(wc_dir, expected_output, expected_status)

  # Expect no externals to be committed, because pegged
  # svn ci --include-externals Xpegged
  expected_output = svntest.wc.State(wc_dir, {})

  actions.run_and_verify_commit(wc_dir, expected_output, expected_status,
                                [], '--include-externals', Xpegged)

  # Expect no externals to be committed, because of depth
  # svn ci --depth=immediates --include-externals
  expected_output = svntest.wc.State(wc_dir, {})

  actions.run_and_verify_commit(wc_dir, expected_output, expected_status,
    [], '--depth=immediates', '--include-externals', wc_dir)

  # Expect only unpegged externals to be committed (those in X/)
  # svn ci --include-externals
  expected_output = svntest.wc.State(wc_dir, {
    'X/xmu'             : Item(verb='Sending'),
    'X/Y/xlambda'       : Item(verb='Sending'),
    'X/Y/xH/xZ/zeta'    : Item(verb='Sending'),
    'X/Y/xH/chi'        : Item(verb='Sending'),
    'X/xG/pi'           : Item(verb='Sending'),
  })

  expected_status.tweak(status='  ')
  expected_status.tweak('X/xmu', 'X/Y/xlambda', 'X/Y/xH/xZ/zeta',
                        'X/Y/xH/chi', 'X/xG/pi', wc_rev='4')

  expected_status.tweak('Xpegged/xE/alpha', status='M ')

  actions.run_and_verify_commit(wc_dir, expected_output, expected_status,
    [], '--include-externals', wc_dir)

  # svn up
  expected_output = svntest.wc.State(wc_dir, {
    'A/mu'              : Item(status='U '),
    'A/D/H/chi'         : Item(status='U '),
    'A/D/H/xZ/zeta'     : Item(status='U '),
    'A/D/G/pi'          : Item(status='U '),
    'A/B/lambda'        : Item(status='U '),
    'Z/zeta'            : Item(status='U '),
  })

  expected_disk.tweak('Xpegged/xE/alpha',
    contents="This is the file 'alpha'.\nmod\n")
  expected_disk.tweak('A/D/H/chi', 'X/Y/xH/chi',
    contents="This is the file 'chi'.\nmod\n")
  expected_disk.tweak('A/D/H/xZ/zeta', 'X/Y/xH/xZ/zeta', 'Z/zeta',
    contents='This is the file zeta.\nmod\n')
  expected_disk.tweak('A/D/G/pi', 'X/xG/pi',
    contents="This is the file 'pi'.\nmod\n")
  expected_disk.tweak('A/mu', 'X/xmu',
    contents="This is the file 'mu'.\nmod\n")
  expected_disk.tweak('A/B/lambda', 'X/Y/xlambda',
    contents="This is the file 'lambda'.\nmod\n")


  # Assume everything r4, except what is pegged
  expected_status.tweak(wc_rev='4')
  expected_status.tweak('Xpegged/xiota', 'Xpegged/xE', 'Xpegged/xE/alpha',
                        'Xpegged/xE/beta', wc_rev=1)

  actions.run_and_verify_update(wc_dir, expected_output, expected_disk,
                                expected_status)

  # new mods to check more cases
  # echo mod >> X/xmu
  main.file_append(X_xmu, 'mod\n')

  # echo mod >> X/Y/xlambda
  main.file_append(X_Y_xlambda, 'mod\n')

  # echo mod >> X/xG/pi
  main.file_append(X_xG_pi, 'mod\n')

  # echo mod >> X/Y/xH/chi
  main.file_append(X_Y_xH_chi, 'mod\n')

  # echo mod >> X/Y/xH/xZ/zeta
  main.file_append(X_Y_xH_xZ_zeta, 'mod\n')

  # svn status
  expected_status.tweak('X/Y/xlambda', 'X/xmu', 'X/xG/pi',
                        'X/Y/xH/chi', 'X/Y/xH/xZ/zeta', status='M ')

  actions.run_and_verify_unquiet_status(wc_dir, expected_status)

  # Expect no externals to be committed, because of depth
  # svn ci --include-externals --depth=empty X
  expected_output = svntest.wc.State(wc_dir, {})

  actions.run_and_verify_commit(wc_dir, expected_output, expected_status,
    [], '--include-externals', '--depth=empty', X)

  # Expect only file external xmu to be committed, because of depth
  # svn ci --include-externals --depth=files X
  expected_output = svntest.wc.State(wc_dir, {
    'X/xmu'             : Item(verb='Sending'),
  })

  expected_status.tweak(status='  ')
  expected_status.tweak('X/xmu', wc_rev='5')
  expected_status.tweak('X/Y/xlambda', 'X/xG/pi', 'X/Y/xH/chi',
                        'X/Y/xH/xZ/zeta', 'Xpegged/xE/alpha', status='M ')

  actions.run_and_verify_commit(wc_dir, expected_output, expected_status,
    [], '--include-externals', '--depth=files', X)

  # svn status
  actions.run_and_verify_unquiet_status(wc_dir, expected_status)

  # svn up
  expected_output = svntest.wc.State(wc_dir, {
    'A/mu'              : Item(status='U '),
  })

  expected_disk.tweak('A/mu', 'X/xmu',
    contents="This is the file 'mu'.\nmod\nmod\n")
  expected_disk.tweak('X/Y/xlambda',
    contents="This is the file 'lambda'.\nmod\nmod\n")
  expected_disk.tweak('X/Y/xH/chi',
    contents="This is the file 'chi'.\nmod\nmod\n")
  expected_disk.tweak('X/Y/xH/xZ/zeta',
    contents='This is the file zeta.\nmod\nmod\n')
  expected_disk.tweak('X/xG/pi',
    contents="This is the file 'pi'.\nmod\nmod\n")

  expected_status.tweak(wc_rev='5')
  expected_status.tweak('Xpegged/xiota', wc_rev='1')
  expected_status.tweak('Xpegged/xiota', 'Xpegged/xE', 'Xpegged/xE/alpha',
                        'Xpegged/xE/beta', wc_rev=1)

  expected_status.tweak('X/Y/xH/chi', status='M ')

  actions.run_and_verify_update(wc_dir, expected_output, expected_disk,
                                expected_status)

  # echo mod >> X/xG/pi
  main.file_append(X_xG_pi, 'mod\n')

  # svn status
  actions.run_and_verify_unquiet_status(wc_dir, expected_status)

  # Expect explicit targets to be committed
  # svn ci X/Y/xlambda X/xG
  expected_output = svntest.wc.State(wc_dir, {
    'X/Y/xlambda'       : Item(verb='Sending'),
    'X/xG/pi'           : Item(verb='Sending'),
  })

  expected_status.tweak(status='  ')
  expected_status.tweak('X/Y/xlambda', 'X/xG/pi', wc_rev='6')
  expected_status.tweak('X/Y/xH/chi', 'X/Y/xH/xZ/zeta', 'Xpegged/xE/alpha',
                        status='M ')

  actions.run_and_verify_commit(wc_dir, expected_output, expected_status,
    [], X_Y_xlambda, X_xG)

  # svn status
  actions.run_and_verify_unquiet_status(wc_dir, expected_status)


@Issue(4252)
def include_immediate_dir_externals(sbox):
  "commit --include-externals --depth=immediates"
  # See also comment in append_externals_as_explicit_targets() in
  # libsvn_client/commit.c, from r1198765.

  #   svntest.factory.make(sbox,"""
  #     svn mkdir X
  #     svn ci
  #     svn up
  #     svn ps svn:externals "^/A/B/E X/XE" wc_dir
  #     svn ci
  #     svn up
  #
  #     svn ps some change X/XE
  #     echo mod >> X/XE/alpha
  #
  #     svn st X/XE
  #     # Expect only the propset on X/XE to be committed.
  #     # Should be like 'svn commit --include-externals --depth=empty X/XE'.
  #     svn commit --include-externals --depth=immediates X
  #     """)

  sbox.build()
  wc_dir = sbox.wc_dir

  X = sbox.ospath('X')
  X_XE = sbox.ospath('X/XE')
  X_XE_alpha = sbox.ospath('X/XE/alpha')

  # svn mkdir X
  expected_stdout = ['A         ' + X + '\n']

  actions.run_and_verify_svn2(expected_stdout, [], 0, 'mkdir', X)

  # svn ci
  expected_output = svntest.wc.State(wc_dir, {
    'X'                 : Item(verb='Adding'),
  })

  expected_status = actions.get_virginal_state(wc_dir, 1)
  expected_status.add({
    'X'                 : Item(status='  ', wc_rev='2'),
  })

  actions.run_and_verify_commit(wc_dir, expected_output, expected_status)

  # svn up
  expected_output = svntest.wc.State(wc_dir, {})

  expected_disk = svntest.main.greek_state.copy()
  expected_disk.add({
    'X'                 : Item(),
  })

  expected_status.tweak(wc_rev='2')

  actions.run_and_verify_update(wc_dir, expected_output, expected_disk,
                                expected_status)

  # svn ps svn:externals "^/A/B/E X/XE" wc_dir
  expected_stdout = ["property 'svn:externals' set on '" + wc_dir + "'\n"]

  actions.run_and_verify_svn2(expected_stdout, [], 0, 'ps',
    'svn:externals', '^/A/B/E X/XE', wc_dir)

  # svn ci
  expected_output = svntest.wc.State(wc_dir, {
    ''                  : Item(verb='Sending'),
  })

  expected_status.tweak('', wc_rev='3')

  actions.run_and_verify_commit(wc_dir, expected_output, expected_status)

  # svn up
  expected_output = svntest.wc.State(wc_dir, {
    'X/XE/alpha'        : Item(status='A '),
    'X/XE/beta'         : Item(status='A '),
  })

  expected_disk.add({
    'X/XE'              : Item(),
    'X/XE/alpha'        : Item(contents="This is the file 'alpha'.\n"),
    'X/XE/beta'         : Item(contents="This is the file 'beta'.\n"),
  })

  expected_status.tweak(wc_rev='3')
  expected_status.add({
    'X/XE'              : Item(status='  ', prev_status='X ', wc_rev='3'),
    'X/XE/beta'         : Item(status='  ', wc_rev='3'),
    'X/XE/alpha'        : Item(status='  ', wc_rev='3'),
  })

  actions.run_and_verify_update(wc_dir, expected_output, expected_disk,
                                expected_status)

  sbox.simple_propset('some', 'change', 'X/XE')

  # echo mod >> X/XE/alpha
  main.file_append(X_XE_alpha, 'mod\n')

  # svn st X/XE
  expected_status.tweak('X/XE', status=' M')
  expected_status.tweak('X/XE/alpha', status='M ')
  actions.run_and_verify_unquiet_status(wc_dir, expected_status)

  # Expect only the propset on X/XE to be committed.
  # Should be like 'svn commit --include-externals --depth=empty X/XE'.
  # svn commit --include-externals --depth=immediates X
  expected_output = svntest.wc.State(wc_dir, {
    'X/XE'              : Item(verb='Sending'),
  })
  expected_status.tweak('X/XE', status='  ', wc_rev=4)

  # Currently this fails because nothing is committed.
  #
  #   >svn st
  #   X       X\XE
  #
  #   Performing status on external item at 'X\XE':
  #    M      C:\SVN\src-trunk\...\externals_tests-37\X\XE
  #   M       C:\SVN\src-trunk\...\externals_tests-37\X\XE\alpha
  #
  #   >svn ci -m "m" --include-externals --depth immediates X
  #
  #   >
  actions.run_and_verify_commit(wc_dir, expected_output, expected_status,
    [], '--include-externals', '--depth=immediates', X)


@Issue(4085)
def shadowing(sbox):
  "external shadows an existing dir"

  sbox.build()
  wc_dir = sbox.wc_dir

  # Setup external: /A/B/F as 'C' child of /A
  externals_prop = "^/A/B/F C\n"
  change_external(sbox.ospath('A'), externals_prop, commit=False)

  # An update errors out because the external is shadowed by an existing dir
  svntest.main.run_svn("W205011: Error handling externals definition for '%s'"
    % (sbox.wc_dir) + "/A/C", 'update', wc_dir)

  # Remove the shadowed directory to unblock the external
  svntest.main.run_svn(None, 'rm', sbox.repo_url + '/A/C', '-m', 'remove A/C')

  # The next update should fetch the external and not error out
  sbox.simple_update()


# Test for issue #4093 'remapping a file external can segfault due to
# "deleted" props'.
@Issue(4093)
def remap_file_external_with_prop_del(sbox):
  "file external remap segfaults due to deleted props"

  sbox.build()
  wc_dir = sbox.wc_dir

  A_path  = sbox.ospath('A')
  mu_path = sbox.ospath('A/mu')

  # Add a property to A/mu
  svntest.actions.run_and_verify_svn(None, [],
                                     'ps', 'propname', 'propval', mu_path)
  svntest.actions.run_and_verify_svn(None, [],
                                     'commit', '-m', 'New property on a file',
                                     wc_dir)
  svntest.actions.run_and_verify_svn(None, [], 'up', wc_dir)

  # Add a new file external A/external pointing to ^/A/mu
  externals_prop = "^/A/mu external\n"
  change_external(A_path, externals_prop)
  svntest.actions.run_and_verify_svn(None, [], 'up', wc_dir)

  # Change A/external to point to ^/iota
  externals_prop = "^/iota external\n"
  change_external(A_path, externals_prop)

  # Now update to bring the new external down.
  # This previously segfaulted as described in
  # http://subversion.tigris.org/issues/show_bug.cgi?id=4093#desc1
  svntest.actions.run_and_verify_svn(None, [], 'up', wc_dir)


# Test for issue #4053 'svn:externals with explicit rev checks out HEAD'
@Issue(4053)
def dir_external_with_dash_r_only(sbox):
  "whether '-r1 ^/A B' updates properly"
  # svntest.factory.make(sbox,"""
  #   echo 'newer alpha' > A/B/E/alpha
  #   svn ci
  #   svn ps svn:externals ' -r1 ^/A/B/E E_ext' .
  #   svn up
  #   # ^ move the 'status.tweak(wc_rev=2)' above the 'add()' call
  #   svn info E_ext
  #   # ^ change the 'svn info' call to
  #   #  expected_info = { 'Revision': '1' }
  #   #  actions.run_and_verify_info([expected_info], E_ext)
  #   """)

  sbox.build()
  wc_dir = sbox.wc_dir
  url = sbox.repo_url

  A_B_E_alpha = sbox.ospath('A/B/E/alpha')
  E_ext = sbox.ospath('E_ext')

  # echo 'newer alpha' > A/B/E/alpha
  main.file_write(A_B_E_alpha, 'newer alpha\n')

  # svn ci
  expected_output = svntest.wc.State(wc_dir, {
    'A/B/E/alpha'       : Item(verb='Sending'),
  })

  expected_status = actions.get_virginal_state(wc_dir, 1)
  expected_status.tweak('A/B/E/alpha', wc_rev='2')

  actions.run_and_verify_commit(wc_dir, expected_output, expected_status)

  # svn ps svn:externals ' -r1 ^/A/B/E E_ext' .
  expected_stdout = ["property 'svn:externals' set on '" + wc_dir + "'\n"]

  actions.run_and_verify_svn2(expected_stdout, [], 0, 'ps',
    'svn:externals', ' -r1 ^/A/B/E E_ext', wc_dir)

  # svn up
  expected_output = svntest.wc.State(wc_dir, {
    'E_ext/beta'        : Item(status='A '),
    'E_ext/alpha'       : Item(status='A '),
  })

  expected_disk = svntest.main.greek_state.copy()
  expected_disk.add({
    'E_ext'             : Item(),
    'E_ext/alpha'       : Item(contents="This is the file 'alpha'.\n"),
    'E_ext/beta'        : Item(contents="This is the file 'beta'.\n"),
  })
  expected_disk.tweak('A/B/E/alpha', contents='newer alpha\n')

  expected_status.tweak(wc_rev='2')
  expected_status.tweak('', status=' M')
  expected_status.add({
    'E_ext'             : Item(status='  ', prev_status='X ', wc_rev=1),
    'E_ext/beta'        : Item(status='  ', wc_rev='1'),
    'E_ext/alpha'       : Item(status='  ', wc_rev='1'),
  })

  actions.run_and_verify_update(wc_dir, expected_output, expected_disk,
                                expected_status)

  # svn info E_ext/alpha
  expected_info = { 'Revision': '1' }
  actions.run_and_verify_info([expected_info], E_ext)

# Test for issue #4123 'URL-to-WC copy of externals fails on Windows'
@Issue(4123)
def url_to_wc_copy_of_externals(sbox):
  "url-to-wc copy of externals"

  sbox.build()

  wc_dir = sbox.wc_dir
  repo_url = sbox.repo_url

  # Create an external A/C/external pointing to ^/A/D/G.
  svntest.actions.run_and_verify_svn(None, [], 'ps',
                                     'svn:externals', '^/A/D/G external',
                                     sbox.ospath('A/C'))
  svntest.actions.run_and_verify_svn(None, [], 'ci', '-m',
                                     'create an external', wc_dir)
  svntest.actions.run_and_verify_svn(None, [], 'up', wc_dir)

  # Copy ^/A/C to External-WC-to-URL-Copy.
  #
  # Previously this failed with:
  #   >svn copy ^^/A/C External-WC-to-URL-Copy
  #    U   External-WC-to-URL-Copy
  #
  #   Fetching external item into 'External-WC-to-URL-Copy\external':
  #   A    External-WC-to-URL-Copy\external\pi
  #   A    External-WC-to-URL-Copy\external\rho
  #   A    External-WC-to-URL-Copy\external\tau
  #   Checked out external at revision 2.
  #
  #   Checked out revision 2.
  #   ..\..\..\subversion\libsvn_client\copy.c:2249: (apr_err=720005)
  #   ..\..\..\subversion\libsvn_client\copy.c:1857: (apr_err=720005)
  #   ..\..\..\subversion\libsvn_client\copy.c:1857: (apr_err=720005)
  #   ..\..\..\subversion\libsvn_client\copy.c:1737: (apr_err=720005)
  #   ..\..\..\subversion\libsvn_client\copy.c:1737: (apr_err=720005)
  #   ..\..\..\subversion\libsvn_client\copy.c:1537: (apr_err=720005)
  #   ..\..\..\subversion\libsvn_subr\io.c:3416: (apr_err=720005)
  #   svn: E720005: Can't move 'C:\SVN\src-trunk-3\Debug\subversion\tests\
  #   cmdline\svn-test-work\working_copies\externals_tests-41\.svn\tmp\
  #   svn-F9E2C0EC' to 'C:\SVN\src-trunk-3\Debug\subversion\tests\cmdline\
  #   svn-test-work\working_copies\externals_tests-41\External-WC-to-URL-Copy':
  #   Access is denied.
  external_root_path = sbox.ospath('External-WC-to-URL-Copy')
  external_ex_path = os.path.join(wc_dir, "External-WC-to-URL-Copy",
                                  "external")
  external_pi_path = os.path.join(wc_dir, "External-WC-to-URL-Copy",
                                  "external", "pi")
  external_rho_path = os.path.join(wc_dir, "External-WC-to-URL-Copy",
                                   "external", "rho")
  external_tau_path = os.path.join(wc_dir, "External-WC-to-URL-Copy",
                                   "external", "tau")
  expected_stdout = verify.UnorderedOutput([
    " U   " + external_root_path + "\n",
    "\n",
    "Fetching external item into '" + external_ex_path + "':\n",
    "A    " + external_pi_path + "\n",
    "A    " + external_rho_path + "\n",
    "A    " + external_tau_path + "\n",
    "Checked out external at revision 2.\n",
    "\n",
    "Checked out revision 2.\n",
    "A         " + external_root_path + "\n"
  ])
  exit_code, stdout, stderr = svntest.actions.run_and_verify_svn2(
    expected_stdout, [], 0, 'copy', repo_url + '/A/C',
    sbox.ospath('External-WC-to-URL-Copy'))

@Issue(4227)
def duplicate_targets(sbox):
  "local path appears twice in one svn:external prop"

  if False:
    svntest.factory.make(sbox, r"""
      svn ps svn:externals "^/A/B/E barf\n^/A/B/E barf" .
      svn ps svn:externals "^/A/B/E barf\n^/A/D/G barf" .
      svn ps svn:externals "^/A/B/E barf/.\n^/A/D/G ./barf" .
      svn ps svn:externals "^/A/B/E ././barf\n^/A/D/G .//barf" .
      svn pg svn:externals .
      svn ps svn:externals "^/A/B/E ok" .
      svn pg svn:externals .
      """)

  sbox.build()
  wc_dir = sbox.wc_dir
  abs_wc_dir = os.path.abspath(sbox.wc_dir)

  expected_stderr = verify.RegexOutput(
    ".*Invalid svn:externals property on '" + re.escape(abs_wc_dir) +
    "': target 'barf' appears more than once\n",
    match_all=False)

  # svn ps svn:externals "^/A/B/E barf\n^/A/B/E barf" .
  actions.run_and_verify_svn2([], expected_stderr, 1, 'ps',
    'svn:externals', '^/A/B/E barf\n^/A/B/E barf', wc_dir)

  # svn ps svn:externals "^/A/B/E barf\n^/A/D/G barf" .
  actions.run_and_verify_svn2([], expected_stderr, 1, 'ps',
    'svn:externals', '^/A/B/E barf\n^/A/D/G barf', wc_dir)

  # svn ps svn:externals "^/A/B/E barf/.\n^/A/D/G ./barf" .
  actions.run_and_verify_svn2([], expected_stderr, 1, 'ps',
    'svn:externals', '^/A/B/E barf/.\n^/A/D/G ./barf', wc_dir)

  # svn ps svn:externals "^/A/B/E ././barf\n^/A/D/G .//barf" .
  actions.run_and_verify_svn2([], expected_stderr, 1, 'ps',
    'svn:externals', '^/A/B/E ././barf\n^/A/D/G .//barf', wc_dir)

  # svn pg svn:externals .
  expected_stderr = '.*W200017: Property.*not found'

  actions.run_and_verify_svn2([], expected_stderr, 1, 'pg',
    'svn:externals', wc_dir)

  # svn ps svn:externals "^/A/B/E ok" .
  expected_stdout = ["property 'svn:externals' set on '" + wc_dir + "'\n"]

  actions.run_and_verify_svn2(expected_stdout, [], 0, 'ps',
    'svn:externals', '^/A/B/E ok', wc_dir)

  # svn pg svn:externals .
  expected_stdout = verify.UnorderedOutput([
    '^/A/B/E ok\n',
    '\n'
  ])

  actions.run_and_verify_svn2(expected_stdout, [], 0, 'pg',
    'svn:externals', wc_dir)

@Issue(4225)
def list_include_externals(sbox):
  "list with --include-externals"

  externals_test_setup(sbox)

  wc_dir         = sbox.wc_dir
  repo_url       = sbox.repo_url

  svntest.actions.run_and_verify_svn(None, [],
                                     'checkout',
                                     repo_url, wc_dir)

  B_path = sbox.ospath("A/B")
  C_path = sbox.ospath("A/C")

  B_url = repo_url + "/A/B"
  C_url = repo_url + "/A/C"

  def list_external_string(path, url):
    string = "Listing external" + " '" + path + "' " + "defined on" + " '" + \
      url + "'" + ":"
    return string

  expected_stdout = verify.UnorderedOutput([
    "E/" + "\n",
    "F/" + "\n",
    "lambda" + "\n",
    list_external_string("gamma", B_url ) + "\n",
    "gamma" + "\n"])

  exit_code, stdout, stderr = svntest.actions.run_and_verify_svn2(
    expected_stdout, [], 0, 'ls', '--include-externals', B_path)

  exit_code, stdout, stderr = svntest.actions.run_and_verify_svn2(
    expected_stdout, [], 0, 'ls', '--include-externals', B_url)

  expected_stdout = verify.UnorderedOutput([
    list_external_string("exdir_G", C_url)+ "\n",
    "pi" + "\n",
    "rho" + "\n",
    "tau" + "\n",
    list_external_string("exdir_H", C_url) + "\n",
    "chi" + "\n",
    "omega" + "\n",
    "psi" + "\n"])

  exit_code, stdout, stderr = svntest.actions.run_and_verify_svn2(
    expected_stdout, [], 0, 'ls', '--include-externals', C_path)

  exit_code, stdout, stderr = svntest.actions.run_and_verify_svn2(
    expected_stdout, [], 0, 'ls', '--include-externals', C_url)

@Issue(4293)
def move_with_file_externals(sbox):
  "move with file externals"

  sbox.build()
  wc_dir         = sbox.wc_dir
  repo_url       = sbox.repo_url

  sbox.simple_propset('svn:externals', '^/A/mu@1 mu-1\n', 'A/D')
  sbox.simple_commit()

  sbox.simple_update()
  sbox.simple_move('A/D', 'A/D_moved')
  sbox.simple_commit()
  sbox.simple_update()

@Issue(4185,4529)
def pinned_externals(sbox):
  "pinned external"

  sbox.build()
  wc_dir = sbox.wc_dir
  repo_url = sbox.repo_url

  # Create X in r2
  sbox.simple_copy('A', 'X')
  sbox.simple_mkdir('Z')
  sbox.simple_commit('')

  repo_X_C = repo_url + '/X/C'
  repo_X_mu = repo_url + '/X/mu'

  expected_output = verify.RegexOutput(
    '^      1 jrandom            .* mu$'
  )

  svntest.actions.run_and_verify_svn(expected_output, [],
                                     'list', repo_X_mu, '-v')

  # So, we copied A/mu to X/mu in r2, but its last changed revision is
  # still r1. It existed as A/mu at r1.

  # In the old format the -r is interpreted like an @1 on checkout.

  sbox.simple_propset('svn:externals',
                          'old-plain           ' + repo_X_mu + '\n' +
                          'old-rev       -r 1  ' + repo_X_mu + '\n' +
                                    repo_X_mu + ' new-plain\n' +
                          '-r1  ' + repo_X_mu + ' new-rev\n' +
                                    repo_X_mu + '@1 new-peg\n'
                          '-r1  ' + repo_X_C + ' new-dir-rev\n',
                      'Z')

  expected_error = "svn: E205011: Failure.*externals"
  expected_disk = svntest.main.greek_state.copy()
  expected_disk.add({
    # The interesting values
    'Z/old-plain'       : Item(contents="This is the file 'mu'.\n"),
    'Z/new-plain'       : Item(contents="This is the file 'mu'.\n"),
    'Z/new-rev'         : Item(contents="This is the file 'mu'.\n"),
    'Z/new-dir-rev'     : Item(),

    # And verifying X
    'X/D/H/psi'         : Item(contents="This is the file 'psi'.\n"),
    'X/D/H/chi'         : Item(contents="This is the file 'chi'.\n"),
    'X/D/H/omega'       : Item(contents="This is the file 'omega'.\n"),
    'X/D/G/tau'         : Item(contents="This is the file 'tau'.\n"),
    'X/D/G/pi'          : Item(contents="This is the file 'pi'.\n"),
    'X/D/G/rho'         : Item(contents="This is the file 'rho'.\n"),
    'X/D/gamma'         : Item(contents="This is the file 'gamma'.\n"),
    'X/B/E/alpha'       : Item(contents="This is the file 'alpha'.\n"),
    'X/B/E/beta'        : Item(contents="This is the file 'beta'.\n"),
    'X/B/lambda'        : Item(contents="This is the file 'lambda'.\n"),
    'X/B/F'             : Item(),
    'X/C'               : Item(),
    'X/mu'              : Item(contents="This is the file 'mu'.\n"),
  })


  # ### Would be nice if verify update would still verify the result
  # on exiting with an error. Why would you pass it?
  svntest.actions.run_and_verify_update(wc_dir, None, None, None,
                                        expected_error)

  svntest.actions.verify_disk(wc_dir, expected_disk)

# Test for issue #3741 'externals not removed when working copy is made shallow'
@Issue(3741)
def update_dir_external_shallow(sbox):
  "shallow update should remove externals"

  sbox.build()

  # Create an external in r2
  sbox.simple_propset('svn:externals', '^/A/D/H X', 'A/B/E')
  sbox.simple_commit()
  sbox.simple_update()

  # Now make A/B/E shallow by updating with "--set-depth empty"
  expected_output = svntest.wc.State(sbox.wc_dir, {
    'A/B/E/alpha' : Item(status='D '),
    'A/B/E/X'     : Item(verb='Removed external'),
    'A/B/E/beta'  : Item(status='D '),
  })
  svntest.actions.run_and_verify_update(sbox.wc_dir,
                                        expected_output, None, None,
                                        [], False,
                                        '--set-depth=empty',
                                        sbox.ospath('A/B/E'))

  # And bring the external back by updating with "--set-depth infinity"
  expected_output = svntest.wc.State(sbox.wc_dir, {
    'A/B/E/X/psi'   : Item(status='A '),
    'A/B/E/X/chi'   : Item(status='A '),
    'A/B/E/X/omega' : Item(status='A '),
    'A/B/E/alpha'   : Item(status='A '),
    'A/B/E/beta'    : Item(status='A '),
  })
  svntest.actions.run_and_verify_update(sbox.wc_dir,
                                        expected_output, None, None,
                                        [], False,
                                        '--set-depth=infinity',
                                        sbox.ospath('A/B/E'))

@Issue(4411)
def switch_parent_relative_file_external(sbox):
  "switch parent-relative file external"

  sbox.build()

  # Create a parent-relative file external in r2
  sbox.simple_propset('svn:externals', '../D/gamma gamma-ext', 'A/B')
  sbox.simple_commit()
  sbox.simple_update()

  # Create a branch that contains the file external
  sbox.simple_copy('A', 'A_copy')
  sbox.simple_commit()
  sbox.simple_update()

  # Check out A/B_copy to a new working copy
  branch_wc = sbox.add_wc_path("branch")
  branch_url = sbox.repo_url + '/A_copy'
  svntest.actions.run_and_verify_svn(None, [],
                                     'checkout', branch_url,
                                     branch_wc)

  # Rename the branch
  sbox.simple_move('A_copy', 'A_copy2')
  sbox.simple_commit()

  # Switch the branch working copy to the new branch URL
  new_branch_url = sbox.repo_url + '/A_copy2'
  svntest.actions.run_and_verify_svn(None, [],
                                     'switch', new_branch_url,
                                     branch_wc)

  # Bug: The branch working copy can no longer be updated.
  svntest.actions.run_and_verify_svn(None, [],
                                     'update', branch_wc)

@Issue(4420)
def file_external_unversioned_obstruction(sbox):
  """file externals unversioned obstruction"""

  sbox.build()
  wc_dir = sbox.wc_dir

  expected_output = verify.RegexOutput('r2 committed .*')
  svntest.actions.run_and_verify_svnmucc(expected_output, [],
                           '-U', sbox.repo_url, '-m', 'r2: set external',
                           'propset', 'svn:externals', '^/A/mu mu-ext', 'A')

  sbox.simple_append('A/mu-ext', 'unversioned obstruction')

  # Update reports a tree-conflict but status doesn't show any such
  # conflict.  I'm no sure whether this is correct.
  expected_output = svntest.wc.State(wc_dir, {
      'A'        : Item(status=' U'),
      'A/mu-ext' : Item(status='  ', treeconflict='A'),
      })
  expected_disk = svntest.main.greek_state.copy()
  expected_disk.add({
      'A/mu-ext' : Item('unversioned obstruction'),
      })
  expected_status = svntest.actions.get_virginal_state(wc_dir, 2)
  expected_status.add({
      'A/mu-ext' : Item(status='M ', wc_rev='2', switched='X'),
      })
  svntest.actions.run_and_verify_update(wc_dir,
                                        expected_output, expected_disk,
                                        expected_status)

@Issue(4001)
@XFail()
def file_external_versioned_obstruction(sbox):
  """file externals versioned obstruction"""

  sbox.build()
  wc_dir = sbox.wc_dir

  expected_output = verify.RegexOutput('r2 committed .*')
  svntest.actions.run_and_verify_svnmucc(expected_output, [],
                           '-U', sbox.repo_url, '-m', 'r2: set external',
                           'propset', 'svn:externals', '^/A/mu mu-ext', 'A')

  expected_output = svntest.wc.State(wc_dir, {
      'A'        : Item(status=' U'),
      'A/mu-ext' : Item(status='A '),
      })
  expected_disk = svntest.main.greek_state.copy()
  expected_disk.add({
      'A/mu-ext' : Item('This is the file \'mu\'.\n'),
      })
  expected_status = svntest.actions.get_virginal_state(wc_dir, 2)
  expected_status.add({
      'A/mu-ext' : Item(status='  ', wc_rev='2', switched='X'),
      })
  svntest.actions.run_and_verify_update(wc_dir,
                                        expected_output, expected_disk,
                                        expected_status)

  # Update skips adding the versioned node because of the file
  # external obstruction then when the external is deleted the
  # versioned node is missing from disk and wc.db.  Not really sure
  # what should happen, perhaps a not-present node?
  expected_output = verify.RegexOutput('r3 committed .*')
  svntest.actions.run_and_verify_svnmucc(expected_output, [],
                           '-U', sbox.repo_url, '-m', 'r3: copy file',
                           'cp', 'head', 'A/mu', 'A/mu-ext',
                           'propdel', 'svn:externals', 'A')

  expected_output = svntest.wc.State(wc_dir, {
      'A'        : Item(status=' U'),
      'A/mu-ext' : Item(verb='Removed external', prev_verb='Skipped'),
      })
  expected_disk.tweak('A/mu-ext', content='This is the file \'mu\'.\n')
  expected_status.tweak(wc_rev=3)
  expected_status.tweak('A/mu-ext', switched=None)
  svntest.actions.run_and_verify_update(wc_dir,
                                        expected_output, expected_disk,
                                        expected_status)

@Issue(4495)
def update_external_peg_rev(sbox):
  "update external peg rev"

  sbox.build()
  wc_dir = sbox.wc_dir

  sbox.simple_rm('A/B/E/alpha')
  sbox.simple_commit()
  sbox.simple_update()

  sbox.simple_propset('svn:externals', '^/A/B/E@1 xE', 'A/B/F')
  sbox.simple_commit()

  expected_output = svntest.wc.State(wc_dir, {
      'A/B/F/xE/alpha' : Item(status='A '),
      'A/B/F/xE/beta'  : Item(status='A '),
  })
  expected_disk = svntest.main.greek_state.copy()
  expected_disk.remove('A/B/E/alpha')
  expected_disk.add({
      'A/B/F/xE'       : Item(),
      'A/B/F/xE/alpha' : Item('This is the file \'alpha\'.\n'),
      'A/B/F/xE/beta'  : Item('This is the file \'beta\'.\n'),
  })
  expected_status = svntest.actions.get_virginal_state(wc_dir, 3)
  expected_status.remove('A/B/E/alpha')
  expected_status.add({
      'A/B/F/xE'       : Item(status='  ', wc_rev='1', prev_status='X '),
      'A/B/F/xE/alpha' : Item(status='  ', wc_rev='1'),
      'A/B/F/xE/beta'  : Item(status='  ', wc_rev='1'),
  })
  svntest.actions.run_and_verify_update(wc_dir,
                                        expected_output,
                                        expected_disk,
                                        expected_status)

  sbox.simple_propset('svn:externals', '^/A/B/E@2 xE', 'A/B/F')
  sbox.simple_commit()

  expected_output = svntest.wc.State(wc_dir, {
      'A/B/F/xE/alpha' : Item(status='D '),
  })
  expected_disk.remove('A/B/F/xE/alpha')
  expected_status.remove('A/B/F/xE/alpha')
  expected_status.tweak(wc_rev=4)
  expected_status.tweak('A/B/F/xE', 'A/B/F/xE/beta', wc_rev=2)
  svntest.actions.run_and_verify_update(wc_dir,
                                        expected_output,
                                        expected_disk,
                                        expected_status)

  # XFAIL: EXTERNALS.def_revision and EXTERNALS.def_operational_revision
  # are still r1 for 'A/B/F/xE' so status is not against the expected r2.
  # No testsuite support for ood marker so examine status output manually.
  expected_output = [
    "X                    %s\n" % sbox.ospath('A/B/F/xE'),
    "Status against revision:      4\n",
    "\n",
    "Performing status on external item at '%s':\n" % sbox.ospath('A/B/F/xE'),
    "Status against revision:      2\n",
  ]
  svntest.actions.run_and_verify_svn(expected_output, [],
                                     'status', '-u', sbox.wc_dir)

def update_deletes_file_external(sbox):
  "update deletes a file external"

  sbox.build()
  wc_dir = sbox.wc_dir

  sbox.simple_propset('svn:externals', '../D/gamma gamma', 'A/C')
  sbox.simple_commit()
  sbox.simple_update()

  # Create a branch
  svntest.actions.run_and_verify_svn(None, [],
                                     'copy',
                                     '-m', 'create branch',
                                     sbox.repo_url + '/A',
                                     sbox.repo_url + '/A_copy')

  # Update the working copy
  sbox.simple_update()

  # Remove the branch
  svntest.actions.run_and_verify_svn(None, [],
                                     'rm',
                                     '-m', 'remove branch',
                                     sbox.repo_url + '/A_copy')

  # As of r1448345, this update fails:
  # E000002: Can't remove directory '.../A_copy/C': No such file or directory
  sbox.simple_update()


@Issue(4519)
def switch_relative_externals(sbox):
  "switch relative externals"

  sbox.build(create_wc=False)

  svntest.actions.run_and_verify_svnmucc(None, [],
                                         '-U', sbox.repo_url, '-m', 'Q',
                                         'mkdir', 'branches',
                                         'cp', '1', 'A', 'trunk',
                                         'cp', '1', 'A', 'branches/A',
                                         'propset', 'svn:externals',
                                            '../C dirExC\n ../mu fileExMu',
                                            'trunk/B',
                                         'propset', 'svn:externals',
                                            '../C dirExC\n ../mu fileExMu',
                                            'branches/A/B')

  wc = sbox.add_wc_path('wc')

  svntest.actions.run_and_verify_svn(None, [],
                                     'co', sbox.repo_url + '/trunk', wc)

  # This forgets to update some externals data
  svntest.actions.run_and_verify_svn(None, [],
                                     'switch', sbox.repo_url + '/branches/A', wc)

  # This upgrade makes the following update fail
  svntest.actions.run_and_verify_svn(None, [],
                                     'upgrade', wc)

  svntest.actions.run_and_verify_svn(None, [],
                                     'up', wc)


def copy_file_external_to_repo(sbox):
  "explicitly copy file external to repo"

  sbox.build()
  wc_dir = sbox.wc_dir

  change_external(sbox.ospath('A'), '^/A/mu ext')
  sbox.simple_update()

  svntest.actions.run_and_verify_svn(None, [], 'cp',
                                     '--message', 'external copy',
                                     sbox.ospath('A/ext'),
                                     sbox.repo_url + '/ext_copy')

  expected_output = svntest.wc.State(wc_dir, {
      'ext_copy' : Item(status='A '),
  })
  expected_disk = svntest.main.greek_state.copy()
  expected_disk.add({
      'A/ext'    : Item('This is the file \'mu\'.\n'),
      'ext_copy' : Item('This is the file \'mu\'.\n'),
      })
  svntest.actions.run_and_verify_update(wc_dir,
                                        expected_output, expected_disk, None)

@Issue(4550)
def replace_tree_with_foreign_external(sbox):
  "replace tree with foreign external"

  sbox.build()
  wc_dir = sbox.wc_dir
  repo_dir = sbox.repo_dir

  other_repo_dir, other_repo_url = sbox.add_repo_path('other')
  svntest.main.copy_repos(repo_dir, other_repo_dir, 1)

  sbox.simple_propset('svn:externals', other_repo_url + '/A/B X', 'A')
  sbox.simple_commit()
  sbox.simple_propdel('svn:externals', 'A')
  sbox.simple_mkdir('A/X')
  sbox.simple_mkdir('A/X/E')
  sbox.simple_commit()
  sbox.simple_update()

  expected_output = svntest.wc.State(wc_dir, {
      'A/X'         : Item(status='D '),
      'A'           : Item(status=' U'),
      'A/X/lambda'  : Item(status='A '),
      'A/X/E'       : Item(status='A '),
      'A/X/E/alpha' : Item(status='A '),
      'A/X/E/beta'  : Item(status='A '),
      'A/X/F'       : Item(status='A '),
      })
  expected_status = svntest.actions.get_virginal_state(wc_dir, 2)
  expected_status.add({
    'A/X'         : Item(status='  ', wc_rev=1, prev_status='X '),
    'A/X/E'       : Item(status='  ', wc_rev=1, prev_status='  '),
    'A/X/E/alpha' : Item(status='  ', wc_rev=1),
    'A/X/E/beta'  : Item(status='  ', wc_rev=1),
    'A/X/F'       : Item(status='  ', wc_rev=1),
    'A/X/lambda'  : Item(status='  ', wc_rev=1),
    })
  svntest.actions.run_and_verify_update(wc_dir,
                                        expected_output, None, expected_status,
                                        [], True,
                                        '-r', '2', wc_dir)


def verify_pinned_externals(sbox, external_url_for, base_path_or_url,
                            external_youngest_rev, other_external_youngest_rev):
  "helper for pin-externals tests"

  expected_output = [
    '%s@%d gamma\n' % (external_url_for["A/B/gamma"],
                       external_youngest_rev),
    '\n',
  ]
  if svntest.sandbox.is_url(base_path_or_url):
    target = base_path_or_url + '/A_copy/B'
  else:
    target = sbox.ospath('A_copy/B')
  svntest.actions.run_and_verify_svn(expected_output, [],
                                     'propget', 'svn:externals',
                                     target)
  expected_output = [
    'exdir_G -r%d %s\n' % (other_external_youngest_rev,
                           external_url_for["A/C/exdir_G"]),
    '%s exdir_H\n' % external_url_for["A/C/exdir_H"],
    '\n',
  ]
  if svntest.sandbox.is_url(base_path_or_url):
    target = base_path_or_url + '/A_copy/C'
  else:
    target = sbox.ospath('A_copy/C')
  svntest.actions.run_and_verify_svn(expected_output, [],
                                     'propget', 'svn:externals',
                                     target)
  expected_output = [
    '%s@%d exdir_A\n' % (external_url_for["A/D/exdir_A"],
                         other_external_youngest_rev),
    '%s@%d exdir_A/G\n' % (external_url_for["A/D/exdir_A/G/"],
                           other_external_youngest_rev),
    'exdir_A/H -r1 %s\n' % external_url_for["A/D/exdir_A/H"],
    '%s@%d x/y/z/blah\n' % (external_url_for["A/D/x/y/z/blah"],
                            other_external_youngest_rev),
    '\n',
  ]
  if svntest.sandbox.is_url(base_path_or_url):
    target = base_path_or_url + '/A_copy/D'
  else:
    target = sbox.ospath('A_copy/D')
  svntest.actions.run_and_verify_svn(expected_output, [],
                                     'propget', 'svn:externals',
                                     target)


def copy_pin_externals_repos_repos(sbox):
  "svn copy --pin-externals repos->repos"

  external_url_for = externals_test_setup(sbox)

  repo_url       = sbox.repo_url
  repo_dir       = sbox.repo_dir
  other_repo_dir = repo_dir + ".other"

  external_youngest_rev = svntest.main.youngest(repo_dir)
  other_external_youngest_rev = svntest.main.youngest(other_repo_dir)

  # Perform a repos->repos copy, pinning externals
  svntest.actions.run_and_verify_svn(None, [],
                                     'copy',
                                     repo_url + '/A',
                                     repo_url + '/A_copy',
                                     '-m', 'copy',
                                     '--pin-externals')
  verify_pinned_externals(sbox, external_url_for, repo_url,
                          external_youngest_rev, other_external_youngest_rev)


def copy_pin_externals_repos_wc(sbox):
  "svn copy --pin-externals repos->wc"

  external_url_for = externals_test_setup(sbox)

  wc_dir         = sbox.wc_dir
  repo_url       = sbox.repo_url
  repo_dir       = sbox.repo_dir
  other_repo_dir = repo_dir + ".other"

  external_youngest_rev = svntest.main.youngest(repo_dir)
  other_external_youngest_rev = svntest.main.youngest(other_repo_dir)

  # Create a working copy.
  svntest.actions.run_and_verify_svn(None, [],
                                     'checkout',
                                     repo_url, wc_dir)

  # Perform a repos->wc copy, pinning externals
  external_youngest_rev = svntest.main.youngest(repo_dir)
  svntest.actions.run_and_verify_svn(None, [],
                                     'copy',
                                     repo_url + '/A',
                                     os.path.join(wc_dir, 'A_copy'),
                                     '--pin-externals')
  verify_pinned_externals(sbox, external_url_for, wc_dir,
                          external_youngest_rev, other_external_youngest_rev)


def copy_pin_externals_wc_repos(sbox):
  "svn copy --pin-externals wc->repos"

  external_url_for = externals_test_setup(sbox)

  wc_dir         = sbox.wc_dir
  repo_url       = sbox.repo_url
  repo_dir       = sbox.repo_dir
  other_repo_dir = repo_dir + ".other"

  external_youngest_rev = svntest.main.youngest(repo_dir)
  other_external_youngest_rev = svntest.main.youngest(other_repo_dir)

  # Create a working copy.
  svntest.actions.run_and_verify_svn(None, [],
                                     'checkout',
                                     repo_url, wc_dir)

  # Perform a wc->repos copy, pinning externals
  svntest.actions.run_and_verify_svn(None, [],
                                     'copy',
                                     os.path.join(wc_dir, 'A'),
                                     repo_url + '/A_copy',
                                     '-m', 'copy',
                                     '--pin-externals')
  verify_pinned_externals(sbox, external_url_for, repo_url,
                          external_youngest_rev, other_external_youngest_rev)


def copy_pin_externals_wc_wc(sbox):
  "svn copy --pin-externals wc->wc"

  external_url_for = externals_test_setup(sbox)

  wc_dir         = sbox.wc_dir
  repo_url       = sbox.repo_url
  repo_dir       = sbox.repo_dir
  other_repo_dir = repo_dir + ".other"

  external_youngest_rev = svntest.main.youngest(repo_dir)
  other_external_youngest_rev = svntest.main.youngest(other_repo_dir)

  # Create a working copy.
  svntest.actions.run_and_verify_svn(None, [],
                                     'checkout',
                                     repo_url, wc_dir)

  # Perform a wc->wc copy, pinning externals
  svntest.actions.run_and_verify_svn(None, [],
                                     'copy',
                                     os.path.join(wc_dir, 'A'),
                                     os.path.join(wc_dir, 'A_copy'),
                                     '--pin-externals')
  verify_pinned_externals(sbox, external_url_for, wc_dir,
                          external_youngest_rev, other_external_youngest_rev)


def copy_pin_externals_moved_external(sbox):
  "pin externals which were moved since last changed"

  external_url_for = externals_test_setup(sbox)

  wc_dir         = sbox.wc_dir
  repo_url       = sbox.repo_url
  repo_dir       = sbox.repo_dir
  other_repo_dir = repo_dir + ".other"

  external_youngest_rev = svntest.main.youngest(repo_dir)
  other_external_youngest_rev = svntest.main.youngest(other_repo_dir)

  # Create a working copy.
  svntest.actions.run_and_verify_svn(None, [],
                                     'checkout',
                                     repo_url, wc_dir)

  # Test behaviour for external URLs which were moved since
  # their last-changed revision.
  sbox.simple_move('A/D/gamma', 'A/D/gamma-moved')
  sbox.simple_commit()
  change_external(sbox.ospath('A/B'), '^/A/D/gamma-moved gamma', commit=True)
  sbox.simple_update()
  external_youngest_rev = svntest.main.youngest(repo_dir)
  svntest.actions.run_and_verify_svn(None, [],
                                     'copy',
                                     os.path.join(wc_dir, 'A'),
                                     os.path.join(wc_dir, 'A_copy'),
                                     '--pin-externals')
  external_url_for["A/B/gamma"] = '^/A/D/gamma-moved'
  verify_pinned_externals(sbox, external_url_for, wc_dir,
                          external_youngest_rev, other_external_youngest_rev)


def copy_pin_externals_removed_in_head(sbox):
  "already pinned external which was removed in HEAD"

  external_url_for = externals_test_setup(sbox)

  wc_dir         = sbox.wc_dir
  repo_url       = sbox.repo_url
  repo_dir       = sbox.repo_dir
  other_repo_url = repo_url + ".other"
  other_repo_dir = repo_dir + ".other"

  # Create a working copy.
  svntest.actions.run_and_verify_svn(None, [],
                                     'checkout',
                                     repo_url, wc_dir)

  # Test an already pinned external which was removed in HEAD.
  svntest.actions.run_and_verify_svn(None, [],
                                     'rm',
                                     other_repo_url + '/A/D/H',
                                     '-m', 'remove A/D/H')
  sbox.simple_update()
  external_youngest_rev = svntest.main.youngest(repo_dir)
  other_external_youngest_rev = svntest.main.youngest(other_repo_dir)
  svntest.actions.run_and_verify_svn(None, [],
                                     'copy',
                                     os.path.join(wc_dir, 'A'),
                                     os.path.join(wc_dir, 'A_copy'),
                                     '--pin-externals')
  verify_pinned_externals(sbox, external_url_for, wc_dir,
                          external_youngest_rev, other_external_youngest_rev)


def copy_pin_externals_from_old_rev(sbox):
  "copy from an old revision with pinning"

  external_url_for = externals_test_setup(sbox)

  wc_dir         = sbox.wc_dir
  repo_url       = sbox.repo_url
  repo_dir       = sbox.repo_dir
  other_repo_url = repo_url + ".other"
  other_repo_dir = repo_dir + ".other"

  # Create a working copy.
  svntest.actions.run_and_verify_svn(None, [],
                                     'checkout',
                                     repo_url, wc_dir)
  # Create a couple of revisions affecting 'A'.
  for i in range(5):
    svntest.main.file_append(sbox.ospath('A/mu'), 'a new line')
    sbox.simple_commit()
  sbox.simple_update()

  # Test a copy from an old revision with pinning.
  external_youngest_rev = svntest.main.youngest(repo_dir)
  other_external_youngest_rev = svntest.main.youngest(other_repo_dir)
  svntest.actions.run_and_verify_svn(None, [],
                                     'copy',
                                     os.path.join(wc_dir, 'A@6'),
                                     os.path.join(wc_dir, 'A_copy'),
                                     '--pin-externals')
  external_url_for["A/B/gamma"] = '^/A/D/gamma'
  verify_pinned_externals(sbox, external_url_for, wc_dir,
                          external_youngest_rev, other_external_youngest_rev)


def copy_pin_externals_wc_local_mods(sbox):
  "cannot pin WC externals with local mods"

  external_url_for = externals_test_setup(sbox)

  wc_dir         = sbox.wc_dir
  repo_url       = sbox.repo_url

  # Create a working copy.
  svntest.actions.run_and_verify_svn(None, [],
                                     'checkout',
                                     repo_url, wc_dir)

  svntest.main.file_append(sbox.ospath('A/C/exdir_G/pi'), 'this file changed')
  expected_stderr = verify.RegexOutput(".*Cannot pin.*local modifications.*",
                                       match_all=False)
  svntest.actions.run_and_verify_svn(None, expected_stderr,
                                     'copy',
                                     os.path.join(wc_dir, 'A'),
                                     os.path.join(wc_dir, 'A_copy'),
                                     '--pin-externals')


def copy_pin_externals_wc_switched_subtrees(sbox):
  "cannot pin WC externals with switched subtrees"

  external_url_for = externals_test_setup(sbox)

  wc_dir         = sbox.wc_dir
  repo_url       = sbox.repo_url

  # Create a working copy.
  svntest.actions.run_and_verify_svn(None, [],
                                     'checkout',
                                     repo_url, wc_dir)

  svntest.actions.run_and_verify_svn(None, [],
                                     'switch', '--ignore-ancestry', '^/A/B',
                                     sbox.ospath('A/D/exdir_A/C'))
  expected_stderr = verify.RegexOutput(".*Cannot pin.*switched subtree.*",
                                       match_all=False)
  svntest.actions.run_and_verify_svn(None, expected_stderr,
                                     'copy',
                                     os.path.join(wc_dir, 'A'),
                                     os.path.join(wc_dir, 'A_copy'),
                                     '--pin-externals')


def copy_pin_externals_wc_mixed_revisions(sbox):
  "cannot pin WC externals with mixed revisions"

  external_url_for = externals_test_setup(sbox)

  wc_dir         = sbox.wc_dir
  repo_url       = sbox.repo_url

  # Create a working copy.
  svntest.actions.run_and_verify_svn(None, [],
                                     'checkout',
                                     repo_url, wc_dir)

  svntest.actions.run_and_verify_svn(None, [],
                                     'update', '-r1',
                                     sbox.ospath('A/D/exdir_A/mu'))
  expected_stderr = verify.RegexOutput(".*Cannot pin.*mixed-revision.*",
                                       match_all=False)
  svntest.actions.run_and_verify_svn(None, expected_stderr,
                                     'copy',
                                     os.path.join(wc_dir, 'A'),
                                     os.path.join(wc_dir, 'A_copy'),
                                     '--pin-externals')

@Issue(4558)
def copy_pin_externals_whitepace_dir(sbox):
  "copy --pin-externals with whitepace dir"

  sbox.build(empty=True)
  repo_url = sbox.repo_url
  wc_dir = sbox.wc_dir
  ss_path = repo_url[repo_url.find('//'):]

  extdef = sbox.get_tempname('extdef')
  info = sbox.get_tempname('info')

  open(extdef, 'w').write(
      '"' + ss_path +'/deps/sqlite"  ext/sqlite\n' +
      '"^/deps/A P R" \'ext/A P R\'\n' +
      '^/deps/B\ D\ B\' ext/B\ D\ B\'\n' +
      repo_url + '/deps/wors%23+t ext/wors#+t')
  open(info, 'w').write('info\n')

  svntest.actions.run_and_verify_svnmucc(None, [], '-U', repo_url,
                                         'mkdir', 'trunk',
                                         'mkdir', 'branches',
                                         'mkdir', 'deps',
                                         'mkdir', 'deps/sqlite',
                                         'put', info, 'deps/sqlite/readme',
                                         'mkdir', 'deps/A P R',
                                         'put', info, 'deps/A P R/about',
                                         'mkdir', 'deps/B D B\'',
                                         'put', info, 'deps/B D B\'/copying',
                                         'mkdir', 'deps/wors#+t',
                                         'put', info, 'deps/wors#+t/brood',
                                         'propsetf', 'svn:externals', extdef,
                                                    'trunk',
                                         '-mm'
                                         )

  svntest.actions.run_and_verify_svn(None, [], 'update', sbox.ospath('trunk'),
                                     '--ignore-externals')
  sbox.simple_update('branches')

  expected_status = svntest.wc.State(wc_dir, {
    ''                          : Item(status='  ', wc_rev='0'),
    'trunk'                     : Item(status='  ', wc_rev='1'),
    'branches'                  : Item(status='  ', wc_rev='1'),
  })

  svntest.actions.run_and_verify_status(wc_dir, expected_status)

  trunk_url = repo_url + '/trunk'
  branches_url = repo_url + '/branches'
  trunk_wc = sbox.ospath('trunk')

  # Create a new revision to creat interesting pinning revisions
  sbox.simple_propset('A', 'B', 'trunk')
  sbox.simple_commit('trunk')

  # And let's copy/pin
  svntest.actions.run_and_verify_svn(None, [],
                                     'copy', '--pin-externals',
                                     trunk_url, branches_url + '/url-url', '-mm')

  svntest.actions.run_and_verify_svn(None, [],
                                     'copy', '--pin-externals',
                                     trunk_url, sbox.ospath('branches/url-wc'))
  sbox.simple_commit('branches/url-wc')

  # Now try to copy without externals in the WC
  expected_err = '.*E155035: Cannot pin external.*'
  svntest.actions.run_and_verify_svn(None, expected_err,
                                     'copy', '--pin-externals',
                                     trunk_wc, branches_url + '/wc-url', '-mm')

  svntest.actions.run_and_verify_svn(None, expected_err,
                                     'copy', '--pin-externals',
                                     trunk_wc, sbox.ospath('branches/wc-wc'))

  # Bring in the externals on trunk
  svntest.actions.run_and_verify_svn(None, [], 'update', sbox.ospath('trunk'))
  expected_status = svntest.wc.State(wc_dir, {
    'trunk'                     : Item(status='  ', wc_rev='4'),
    'trunk/ext'                 : Item(status='X '),
    'trunk/ext/sqlite'          : Item(status='  ', wc_rev='4'),
    'trunk/ext/sqlite/readme'   : Item(status='  ', wc_rev='4'),
    'trunk/ext/A P R'           : Item(status='  ', wc_rev='4'),
    'trunk/ext/A P R/about'     : Item(status='  ', wc_rev='4'),
    'trunk/ext/B D B\''         : Item(status='  ', wc_rev='4'),
    'trunk/ext/B D B\'/copying' : Item(status='  ', wc_rev='4'),
    'trunk/ext/wors#+t'         : Item(status='  ', wc_rev='4'),
    'trunk/ext/wors#+t/brood'   : Item(status='  ', wc_rev='4'),
  })
  svntest.actions.run_and_verify_status(sbox.ospath('trunk'), expected_status)

  # And copy again
  svntest.actions.run_and_verify_svn(None, [],
                                     'copy', '--pin-externals',
                                     trunk_wc, branches_url + '/wc-url', '-mm')

  svntest.actions.run_and_verify_svn(None, [],
                                     'copy', '--pin-externals',
                                     trunk_wc, sbox.ospath('branches/wc-wc'))
  sbox.simple_commit('branches/wc-wc')


  expected_output = svntest.wc.State(wc_dir, {
    'branches/url-url'                      : Item(status='A '),
    'branches/url-url/ext/A P R/about'      : Item(status='A '),
    'branches/url-url/ext/B D B\'/copying'  : Item(status='A '),
    'branches/url-url/ext/wors#+t/brood'    : Item(status='A '),
    'branches/url-url/ext/sqlite/readme'    : Item(status='A '),

    # url-wc is already up to date

    'branches/wc-url'                       : Item(status='A '),
    'branches/wc-url/ext/wors#+t/brood'     : Item(status='A '),
    'branches/wc-url/ext/sqlite/readme'     : Item(status='A '),
    'branches/wc-url/ext/B D B\'/copying'   : Item(status='A '),
    'branches/wc-url/ext/A P R/about'       : Item(status='A '),

    ## branches/wc-wc should checkout its externals here
  })
  expected_status = svntest.wc.State(wc_dir, {
    'branches'                              : Item(status='  ', wc_rev='6'),

    'branches/url-url'                      : Item(status='  ', wc_rev='6'),
    'branches/url-url/ext'                  : Item(status='X '),
    'branches/url-url/ext/A P R'            : Item(status='  ', wc_rev='2'),
    'branches/url-url/ext/A P R/about'      : Item(status='  ', wc_rev='2'),
    'branches/url-url/ext/sqlite'           : Item(status='  ', wc_rev='2'),
    'branches/url-url/ext/sqlite/readme'    : Item(status='  ', wc_rev='2'),
    'branches/url-url/ext/wors#+t'          : Item(status='  ', wc_rev='2'),
    'branches/url-url/ext/wors#+t/brood'    : Item(status='  ', wc_rev='2'),
    'branches/url-url/ext/B D B\''          : Item(status='  ', wc_rev='2'),
    'branches/url-url/ext/B D B\'/copying'  : Item(status='  ', wc_rev='2'),

    'branches/url-wc'                       : Item(status='  ', wc_rev='6'),
    'branches/url-wc/ext'                   : Item(status='X '),
    'branches/url-wc/ext/wors#+t'           : Item(status='  ', wc_rev='3'),
    'branches/url-wc/ext/wors#+t/brood'     : Item(status='  ', wc_rev='3'),
    'branches/url-wc/ext/B D B\''           : Item(status='  ', wc_rev='3'),
    'branches/url-wc/ext/B D B\'/copying'   : Item(status='  ', wc_rev='3'),
    'branches/url-wc/ext/sqlite'            : Item(status='  ', wc_rev='3'),
    'branches/url-wc/ext/sqlite/readme'     : Item(status='  ', wc_rev='3'),
    'branches/url-wc/ext/A P R'             : Item(status='  ', wc_rev='3'),
    'branches/url-wc/ext/A P R/about'       : Item(status='  ', wc_rev='3'),

    'branches/wc-url'                       : Item(status='  ', wc_rev='6'),
    'branches/wc-url/ext'                   : Item(status='X '),
    'branches/wc-url/ext/wors#+t'           : Item(status='  ', wc_rev='4'),
    'branches/wc-url/ext/wors#+t/brood'     : Item(status='  ', wc_rev='4'),
    'branches/wc-url/ext/sqlite'            : Item(status='  ', wc_rev='4'),
    'branches/wc-url/ext/sqlite/readme'     : Item(status='  ', wc_rev='4'),
    'branches/wc-url/ext/B D B\''           : Item(status='  ', wc_rev='4'),
    'branches/wc-url/ext/B D B\'/copying'   : Item(status='  ', wc_rev='4'),
    'branches/wc-url/ext/A P R'             : Item(status='  ', wc_rev='4'),
    'branches/wc-url/ext/A P R/about'       : Item(status='  ', wc_rev='4'),

    'branches/wc-wc'                        : Item(status='  ', wc_rev='6'),
    'branches/wc-wc/ext'                    : Item(status='X '),
    'branches/wc-wc/ext/wors#+t'            : Item(status='  ', wc_rev='4'),
    'branches/wc-wc/ext/wors#+t/brood'      : Item(status='  ', wc_rev='4'),
    'branches/wc-wc/ext/sqlite'             : Item(status='  ', wc_rev='4'),
    'branches/wc-wc/ext/sqlite/readme'      : Item(status='  ', wc_rev='4'),
    'branches/wc-wc/ext/B D B\''            : Item(status='  ', wc_rev='4'),
    'branches/wc-wc/ext/B D B\'/copying'    : Item(status='  ', wc_rev='4'),
    'branches/wc-wc/ext/A P R'              : Item(status='  ', wc_rev='4'),
    'branches/wc-wc/ext/A P R/about'        : Item(status='  ', wc_rev='4'),
  })
  svntest.actions.run_and_verify_update(wc_dir + '/branches', expected_output,
                                        None, expected_status)

  # Now let's use our existing setup to perform some copies with dynamic
  # destinations
  svntest.actions.run_and_verify_svn(None, [],
                                     'copy', '--parents', '--pin-externals',
                                     repo_url + '/branches/wc-url',
                                     repo_url + '/branches/url-url',
                                     trunk_url,
                                     branches_url + '/3x-url-url',
                                     '-mm')

  svntest.actions.run_and_verify_svn(None, [],
                                     'copy', '--parents', '--pin-externals',
                                     repo_url + '/branches/wc-url',
                                     repo_url + '/branches/url-url',
                                     trunk_url,
                                     sbox.ospath('branches/3x-url-wc'))

  svntest.actions.run_and_verify_svn(None, [],
                                     'copy', '--parents', '--pin-externals',
                                     sbox.ospath('branches/wc-url'),
                                     sbox.ospath('branches/url-url'),
                                     sbox.ospath('trunk'),
                                     branches_url + '/3x-wc-url',
                                     '-mm')

  svntest.actions.run_and_verify_svn(None, [],
                                     'copy', '--parents', '--pin-externals',
                                     sbox.ospath('branches/wc-url'),
                                     sbox.ospath('branches/url-url'),
                                     sbox.ospath('trunk'),
                                     sbox.ospath('branches/3x-wc-wc'))

def nested_notification(sbox):
  "notification for nested externals"

  sbox.build()
  wc_dir = sbox.wc_dir
  repo_dir = sbox.repo_dir

  sbox.simple_mkdir('D1')
  sbox.simple_mkdir('D2')
  sbox.simple_mkdir('D3')
  sbox.simple_mkdir('D4')
  sbox.simple_propset('svn:externals', '^/D2 X', 'D1')
  sbox.simple_propset('svn:externals', '^/D3 X', 'D2')
  sbox.simple_propset('svn:externals', '^/D4 X', 'D3')
  sbox.simple_commit()
  expected_output = [
    'Updating \'' + sbox.ospath('D1') + '\':\n',
    '\n',
    'Fetching external item into \'' + sbox.ospath('D1/X') + '\':\n',
    ' U   ' + sbox.ospath('D1/X') + '\n',
    '\n',
    'Fetching external item into \'' + sbox.ospath('D1/X/X') + '\':\n',
    ' U   ' + sbox.ospath('D1/X/X') + '\n',
    '\n',
    'Fetching external item into \'' + sbox.ospath('D1/X/X/X') + '\':\n',
    'Updated external to revision 2.\n',
    '\n',
    'External at revision 2.\n',
    '\n',
    'External at revision 2.\n',
    '\n',
    'At revision 2.\n'
    ]
  svntest.actions.run_and_verify_svn(expected_output, [],
                                     'update', sbox.ospath('D1'))

def file_external_to_normal_file(sbox):
  "change a file external to a normal file"

  sbox.build()
  wc_dir = sbox.wc_dir
  sbox.simple_propset('svn:externals', '^/iota iota', 'A')
  sbox.simple_commit()

  expected_status = svntest.actions.get_virginal_state(wc_dir, 2)
  expected_status.add({
    'A/iota'            : Item(status='  ', wc_rev='2', switched='X'),
  })
  expected_output = svntest.wc.State(wc_dir, {
    'A/iota'            : Item(status='A '),
  })

  svntest.actions.run_and_verify_update(wc_dir, expected_output, None,
                                        expected_status)

  # Create second working copy in this state
  sbox2 = sbox.clone_dependent(copy_wc=True)

  sbox.simple_propdel('svn:externals', 'A')

  expected_output = svntest.wc.State(wc_dir, {
      'A/iota'            : Item(verb='Removed external'),
  })
  expected_status.remove('A/iota')
  expected_status.tweak('A', status=' M')
  svntest.actions.run_and_verify_update(wc_dir, expected_output, None,
                                        expected_status)

  sbox.simple_copy('iota', 'A/iota')
  sbox.simple_commit()

  expected_output = svntest.wc.State(wc_dir, {
  })
  expected_status.tweak(wc_rev=3)
  expected_status.tweak('A', status='  ')
  expected_status.add({
    # This case used to triggered a switched status in 1.8.x before this
    # test (and the fix for this problem) where added.
    'A/iota'            : Item(status='  ', wc_rev='3'),
  })
  svntest.actions.run_and_verify_update(wc_dir, expected_output, None,
                                        expected_status)


  wc_dir = sbox2.wc_dir

  expected_status = svntest.actions.get_virginal_state(wc_dir, 3)
  expected_output = svntest.wc.State(wc_dir, {
    'A'                 : Item(status=' U'),
    'A/iota'            : Item(verb='Removed external', prev_verb='Skipped'),
  })
  # This reports an obstruction and removes the file external
  svntest.actions.run_and_verify_update(wc_dir, expected_output, None,
                                        expected_status)

  expected_status.add({
    'A/iota'            : Item(status='  ', wc_rev='3'),
  })
  expected_output = svntest.wc.State(wc_dir, {
    'A/iota'            : Item(status='A '),
  })
  # This should bring in the new file
  svntest.actions.run_and_verify_update(wc_dir, expected_output, None,
                                        expected_status)

@Issue(4580)
def file_external_recorded_info(sbox):
  "check file external recorded info"

  sbox.build()
  wc_dir = sbox.wc_dir

  # r2 - Create file external
  svntest.actions.run_and_verify_svnmucc(None, [],
                                         '-U', sbox.repo_url,
                                         '-m', '',
                                         'propset', 'svn:externals',
                                         '^/iota i', '')

  expected_output = svntest.wc.State(wc_dir, {
    ''                  : Item(status=' U'),
    'i'                 : Item(status='A '),
  })
  expected_status = svntest.actions.get_virginal_state(wc_dir, 2)
  expected_status.add({
    'i'                 : Item(status='  ', wc_rev='2', switched='X')
  })
  svntest.actions.run_and_verify_update(wc_dir, expected_output, None,
                                        expected_status, [], False,
                                        '-r', 2, wc_dir)

  expected_infos = [{
    'Path': re.escape(sbox.ospath('i')),
    'Relative URL': re.escape('^/iota'),
    'Revision': '2',
    'Last Changed Rev': '1',
    'Last Changed Author': 'jrandom'
  }]
  svntest.actions.run_and_verify_info(expected_infos, sbox.ospath('i'))

  # r3 - No-op change
  svntest.actions.run_and_verify_svnmucc(None, [],
                                         '-U', sbox.repo_url,
                                         '-m', '',
                                         'cp', '1', 'iota', 'iotb')

  expected_output = svntest.wc.State(wc_dir, {
    'iotb'              : Item(status='A '),
  })
  expected_status = svntest.actions.get_virginal_state(wc_dir, 3)
  expected_status.add({
    'i'                 : Item(status='  ', wc_rev='3', switched='X'),
    'iotb'              : Item(status='  ', wc_rev='3')
  })
  svntest.actions.run_and_verify_update(wc_dir, expected_output, None,
                                        expected_status, [], False,
                                        '-r', 3, wc_dir)

  expected_infos = [{
    'Path': re.escape(sbox.ospath('i')),
    'Relative URL': re.escape('^/iota'),
    'Revision': '3',
    'Last Changed Rev': '1',
    'Last Changed Author': 'jrandom'
  }]
  svntest.actions.run_and_verify_info(expected_infos, sbox.ospath('i'))

  # r4 - Update url
  svntest.actions.run_and_verify_svnmucc(None, [],
                                         '-U', sbox.repo_url,
                                         '-m', '',
                                         'propset', 'svn:externals',
                                         '^/iotb i', '')


  expected_output = svntest.wc.State(wc_dir, {
    ''                  : Item(status=' U'),
  })
  expected_status = svntest.actions.get_virginal_state(wc_dir, 4)
  expected_status.add({
    'i'                 : Item(status='  ', wc_rev='4', switched='X'),
    'iotb'              : Item(status='  ', wc_rev='4')
  })
  svntest.actions.run_and_verify_update(wc_dir, expected_output, None,
                                        expected_status, [], False,
                                        '-r', 4, wc_dir)

  expected_infos = [{
    'Path': re.escape(sbox.ospath('i')),
    'Relative URL': re.escape('^/iotb'),
    'Revision': '4',
    'Last Changed Rev': '3',
    'Last Changed Author': 'jrandom'
  }]
  svntest.actions.run_and_verify_info(expected_infos, sbox.ospath('i'))

  # r5 - Replace file
  svntest.actions.run_and_verify_svnmucc(None, [],
                                         '-U', sbox.repo_url,
                                         '-m', '',
                                         'rm', 'iotb',
                                         'cp', '3', 'A/mu', 'iotb')

  expected_output = svntest.wc.State(wc_dir, {
    'i'                 : Item(status='U '),
    'iotb'              : Item(status='A ', prev_status='D '),
  })
  expected_status = svntest.actions.get_virginal_state(wc_dir, 5)
  expected_status.add({
    'i'                 : Item(status='  ', wc_rev='5', switched='X'),
    'iotb'              : Item(status='  ', wc_rev='5')
  })
  svntest.actions.run_and_verify_update(wc_dir, expected_output, None,
                                        expected_status, [], False,
                                        '-r', 5, wc_dir)

  expected_infos = [{
    'Path': re.escape(sbox.ospath('i')),
    'Relative URL': re.escape('^/iotb'),
    'Revision': '5',
    'Last Changed Rev': '5',
    'Last Changed Author': 'jrandom'
  }]
  svntest.actions.run_and_verify_info(expected_infos, sbox.ospath('i'))

  # Back to r2. But with a conflict
  sbox.simple_append('i', 'i')
  expected_output = svntest.wc.State(wc_dir, {
    ''                  : Item(status=' U'),
    'iotb'              : Item(status='D '),
    'i'                 : Item(status='C '),
  })
  expected_status = svntest.actions.get_virginal_state(wc_dir, 2)
  expected_status.add({
    'i'                 : Item(status='C ', wc_rev='5', switched='X'),
  })
  svntest.actions.run_and_verify_update(wc_dir, expected_output, None,
                                        expected_status, [], False,
                                        '-r', 2, wc_dir)

  expected_infos = [{
    'Path': re.escape(sbox.ospath('i')),
    'Relative URL': re.escape('^/iota'),
    'Revision': '5',
    'Last Changed Rev': '1',
    'Last Changed Author': 'jrandom',
    'Conflict Details': re.escape('incoming file edit upon switch'
                                  ' Source  left: (file) ^/iotb@5'
                                  ' Source right: (file) ^/iota@5')
  }]
  svntest.actions.run_and_verify_info(expected_infos, sbox.ospath('i'))

def external_externally_removed(sbox):
  "external externally removed"

  sbox.build(read_only = True)

  sbox.simple_propset('svn:externals', '^/A/B B', '')

  # Try fetching the external with a versioned obstruction
  sbox.simple_mkdir('B')
  expected_err = ".*W155035: The external.*B' is already a versioned path"
  svntest.actions.run_and_verify_svn(None, expected_err,
                                     'up', sbox.wc_dir)
  sbox.simple_rm('B')


  os.makedirs(sbox.ospath('B'))
  expected_err2 = "svn: warning: W155007:.*B'"
  svntest.actions.run_and_verify_svn(None, expected_err2,
                                     'up', sbox.wc_dir)
  os.rmdir(sbox.ospath('B'))

  # Fetch the external
  sbox.simple_update()

  svntest.main.safe_rmtree(sbox.ospath('B'))
  sbox.simple_update() # Fetched again
  if not os.path.isdir(sbox.ospath('B')):
    raise svntest.Failure("B not recreated")

  svntest.main.safe_rmtree(sbox.ospath('B'))
  sbox.simple_propdel('svn:externals', '')

  expected_output = [
    "Updating '%s':\n" % sbox.wc_dir,
    "Removed external '%s'\n" % sbox.ospath('B'),
    "Updated to revision 1.\n"
  ]
  svntest.actions.run_and_verify_svn(expected_output, [],
                                     'up', sbox.wc_dir)


  sbox.simple_propset('svn:externals', '^/A/B B', '')
  sbox.simple_update()
  svntest.main.safe_rmtree(sbox.ospath('B'))
  sbox.simple_mkdir('B')

  svntest.actions.run_and_verify_svn(None, expected_err,
                                     'up', sbox.wc_dir)

  sbox.simple_propdel('svn:externals', '')
  sbox.simple_update() # Should succeed

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


# list all tests here, starting with None:
test_list = [ None,
              checkout_with_externals,
              update_receive_new_external,
              update_lose_external,
              update_change_pristine_external,
              update_change_modified_external,
              update_receive_change_under_external,
              modify_and_update_receive_new_external,
              disallow_dot_or_dotdot_directory_reference,
              export_with_externals,
              export_wc_with_externals,
              external_with_peg_and_op_revision,
              new_style_externals,
              disallow_propset_invalid_formatted_externals,
              old_style_externals_ignore_peg_reg,
              cannot_move_or_remove_file_externals,
              cant_place_file_external_into_dir_external,
              external_into_path_with_spaces,
              binary_file_externals,
              update_lose_file_external,
              switch_relative_external,
              export_sparse_wc_with_externals,
              relegate_external,
              wc_repos_file_externals,
              merge_target_with_externals,
              update_modify_file_external,
              update_external_on_locally_added_dir,
              switch_external_on_locally_added_dir,
              file_external_in_sibling,
              file_external_update_without_commit,
              incoming_file_on_file_external,
              incoming_file_external_on_file,
              exclude_externals,
              file_externals_different_url,
              file_external_in_unversioned,
              copy_file_externals,
              commit_include_externals,
              include_immediate_dir_externals,
              shadowing,
              remap_file_external_with_prop_del,
              dir_external_with_dash_r_only,
              url_to_wc_copy_of_externals,
              duplicate_targets,
              list_include_externals,
              move_with_file_externals,
              pinned_externals,
              update_dir_external_shallow,
              switch_parent_relative_file_external,
              file_external_unversioned_obstruction,
              file_external_versioned_obstruction,
              update_external_peg_rev,
              update_deletes_file_external,
              switch_relative_externals,
              copy_file_external_to_repo,
              replace_tree_with_foreign_external,
              copy_pin_externals_repos_repos,
              copy_pin_externals_repos_wc,
              copy_pin_externals_wc_repos,
              copy_pin_externals_wc_wc,
              copy_pin_externals_moved_external,
              copy_pin_externals_removed_in_head,
              copy_pin_externals_from_old_rev,
              copy_pin_externals_wc_local_mods,
              copy_pin_externals_wc_switched_subtrees,
              copy_pin_externals_wc_mixed_revisions,
              copy_pin_externals_whitepace_dir,
              nested_notification,
              file_external_to_normal_file,
              file_external_recorded_info,
              external_externally_removed,
             ]

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


### End of file.