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
|
#!/bin/sh
#
# Copyright (c) 2012-2020 Felipe Contreras
#
test_description='test bash completion'
# The Bash completion scripts must not print anything to either stdout or
# stderr, which we try to verify. When tracing is enabled without support for
# BASH_XTRACEFD this assertion will fail, so we have to mark the test as
# untraceable with such ancient Bash versions.
test_untraceable=UnfortunatelyYes
# Override environment and always use master for the default initial branch
# name for these tests, so that rev completion candidates are as expected.
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
. ./lib-bash.sh
complete ()
{
# do nothing
return 0
}
# Be careful when updating these lists:
#
# (1) The build tree may have build artifact from different branch, or
# the user's $PATH may have a random executable that may begin
# with "git-check" that are not part of the subcommands this build
# will ship, e.g. "check-ignore". The tests for completion for
# subcommand names tests how "check" is expanded; we limit the
# possible candidates to "checkout" and "check-attr" to make sure
# "check-attr", which is known by the filter function as a
# subcommand to be thrown out, while excluding other random files
# that happen to begin with "check" to avoid letting them get in
# the way.
#
# (2) A test makes sure that common subcommands are included in the
# completion for "git <TAB>", and a plumbing is excluded. "add",
# "rebase" and "ls-files" are listed for this.
GIT_TESTING_ALL_COMMAND_LIST='add checkout check-attr rebase ls-files'
GIT_TESTING_PORCELAIN_COMMAND_LIST='add checkout rebase'
. "$GIT_BUILD_DIR/contrib/completion/git-completion.bash"
# We don't need this function to actually join words or do anything special.
# Also, it's cleaner to avoid touching bash's internal completion variables.
# So let's override it with a minimal version for testing purposes.
_get_comp_words_by_ref ()
{
while [ $# -gt 0 ]; do
case "$1" in
cur)
cur=${_words[_cword]}
;;
prev)
prev=${_words[_cword-1]}
;;
words)
words=("${_words[@]}")
;;
cword)
cword=$_cword
;;
esac
shift
done
}
print_comp ()
{
local IFS=$'\n'
printf '%s\n' "${COMPREPLY[*]}" > out
}
run_completion ()
{
local -a COMPREPLY _words
local _cword
_words=( $1 )
test "${1: -1}" = ' ' && _words[${#_words[@]}+1]=''
(( _cword = ${#_words[@]} - 1 ))
__git_wrap__git_main && print_comp
}
# Test high-level completion
# Arguments are:
# 1: typed text so far (cur)
# 2: expected completion
test_completion ()
{
if test $# -gt 1
then
printf '%s\n' "$2" >expected
else
sed -e 's/Z$//' |sort >expected
fi &&
run_completion "$1" >"$TRASH_DIRECTORY"/bash-completion-output 2>&1 &&
sort out >out_sorted &&
test_cmp expected out_sorted &&
test_must_be_empty "$TRASH_DIRECTORY"/bash-completion-output &&
rm "$TRASH_DIRECTORY"/bash-completion-output
}
# Test __gitcomp.
# The first argument is the typed text so far (cur); the rest are
# passed to __gitcomp. Expected output comes is read from the
# standard input, like test_completion().
test_gitcomp ()
{
local -a COMPREPLY &&
sed -e 's/Z$//' >expected &&
local cur="$1" &&
shift &&
__gitcomp "$@" &&
print_comp &&
test_cmp expected out
}
# Test __gitcomp_nl
# Arguments are:
# 1: current word (cur)
# -: the rest are passed to __gitcomp_nl
test_gitcomp_nl ()
{
local -a COMPREPLY &&
sed -e 's/Z$//' >expected &&
local cur="$1" &&
shift &&
__gitcomp_nl "$@" &&
print_comp &&
test_cmp expected out
}
invalid_variable_name='${foo.bar}'
actual="$TRASH_DIRECTORY/actual"
if test_have_prereq MINGW
then
ROOT="$(pwd -W)"
else
ROOT="$(pwd)"
fi
test_expect_success 'setup for __git_find_repo_path/__gitdir tests' '
mkdir -p subdir/subsubdir &&
mkdir -p non-repo &&
git init -b main otherrepo &&
git init -b main slashrepo
'
test_expect_success '__git_find_repo_path - from command line (through $__git_dir)' '
echo "$ROOT/otherrepo/.git" >expected &&
(
__git_dir="$ROOT/otherrepo/.git" &&
__git_find_repo_path &&
echo "$__git_repo_path" >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success '__git_find_repo_path - .git directory in cwd' '
echo ".git" >expected &&
(
__git_find_repo_path &&
echo "$__git_repo_path" >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success '__git_find_repo_path - .git directory in parent' '
echo "$ROOT/.git" >expected &&
(
cd subdir/subsubdir &&
__git_find_repo_path &&
echo "$__git_repo_path" >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success '__git_find_repo_path - cwd is a .git directory' '
echo "." >expected &&
(
cd .git &&
__git_find_repo_path &&
echo "$__git_repo_path" >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success '__git_find_repo_path - parent is a .git directory' '
echo "$ROOT/.git" >expected &&
(
cd .git/objects &&
__git_find_repo_path &&
echo "$__git_repo_path" >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success '__git_find_repo_path - $GIT_DIR set while .git directory in cwd' '
echo "$ROOT/otherrepo/.git" >expected &&
(
GIT_DIR="$ROOT/otherrepo/.git" &&
export GIT_DIR &&
__git_find_repo_path &&
echo "$__git_repo_path" >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success '__git_find_repo_path - $GIT_DIR set while .git directory in parent' '
echo "$ROOT/otherrepo/.git" >expected &&
(
GIT_DIR="$ROOT/otherrepo/.git" &&
export GIT_DIR &&
cd subdir &&
__git_find_repo_path &&
echo "$__git_repo_path" >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success '__git_find_repo_path - from command line while "git -C"' '
echo "$ROOT/.git" >expected &&
(
__git_dir="$ROOT/.git" &&
__git_C_args=(-C otherrepo) &&
__git_find_repo_path &&
echo "$__git_repo_path" >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success '__git_find_repo_path - relative dir from command line and "git -C"' '
echo "$ROOT/otherrepo/.git" >expected &&
(
cd subdir &&
__git_dir="otherrepo/.git" &&
__git_C_args=(-C ..) &&
__git_find_repo_path &&
echo "$__git_repo_path" >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success '__git_find_repo_path - $GIT_DIR set while "git -C"' '
echo "$ROOT/.git" >expected &&
(
GIT_DIR="$ROOT/.git" &&
export GIT_DIR &&
__git_C_args=(-C otherrepo) &&
__git_find_repo_path &&
echo "$__git_repo_path" >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success '__git_find_repo_path - relative dir in $GIT_DIR and "git -C"' '
echo "$ROOT/otherrepo/.git" >expected &&
(
cd subdir &&
GIT_DIR="otherrepo/.git" &&
export GIT_DIR &&
__git_C_args=(-C ..) &&
__git_find_repo_path &&
echo "$__git_repo_path" >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success '__git_find_repo_path - "git -C" while .git directory in cwd' '
echo "$ROOT/otherrepo/.git" >expected &&
(
__git_C_args=(-C otherrepo) &&
__git_find_repo_path &&
echo "$__git_repo_path" >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success '__git_find_repo_path - "git -C" while cwd is a .git directory' '
echo "$ROOT/otherrepo/.git" >expected &&
(
cd .git &&
__git_C_args=(-C .. -C otherrepo) &&
__git_find_repo_path &&
echo "$__git_repo_path" >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success '__git_find_repo_path - "git -C" while .git directory in parent' '
echo "$ROOT/otherrepo/.git" >expected &&
(
cd subdir &&
__git_C_args=(-C .. -C otherrepo) &&
__git_find_repo_path &&
echo "$__git_repo_path" >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success '__git_find_repo_path - non-existing path in "git -C"' '
(
__git_C_args=(-C non-existing) &&
test_must_fail __git_find_repo_path &&
printf "$__git_repo_path" >"$actual"
) &&
test_must_be_empty "$actual"
'
test_expect_success '__git_find_repo_path - non-existing path in $__git_dir' '
(
__git_dir="non-existing" &&
test_must_fail __git_find_repo_path &&
printf "$__git_repo_path" >"$actual"
) &&
test_must_be_empty "$actual"
'
test_expect_success '__git_find_repo_path - non-existing $GIT_DIR' '
(
GIT_DIR="$ROOT/non-existing" &&
export GIT_DIR &&
test_must_fail __git_find_repo_path &&
printf "$__git_repo_path" >"$actual"
) &&
test_must_be_empty "$actual"
'
test_expect_success '__git_find_repo_path - gitfile in cwd' '
echo "$ROOT/otherrepo/.git" >expected &&
echo "gitdir: $ROOT/otherrepo/.git" >subdir/.git &&
test_when_finished "rm -f subdir/.git" &&
(
cd subdir &&
__git_find_repo_path &&
echo "$__git_repo_path" >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success '__git_find_repo_path - gitfile in parent' '
echo "$ROOT/otherrepo/.git" >expected &&
echo "gitdir: $ROOT/otherrepo/.git" >subdir/.git &&
test_when_finished "rm -f subdir/.git" &&
(
cd subdir/subsubdir &&
__git_find_repo_path &&
echo "$__git_repo_path" >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success SYMLINKS '__git_find_repo_path - resulting path avoids symlinks' '
echo "$ROOT/otherrepo/.git" >expected &&
mkdir otherrepo/dir &&
test_when_finished "rm -rf otherrepo/dir" &&
ln -s otherrepo/dir link &&
test_when_finished "rm -f link" &&
(
cd link &&
__git_find_repo_path &&
echo "$__git_repo_path" >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success '__git_find_repo_path - not a git repository' '
(
cd non-repo &&
GIT_CEILING_DIRECTORIES="$ROOT" &&
export GIT_CEILING_DIRECTORIES &&
test_must_fail __git_find_repo_path &&
printf "$__git_repo_path" >"$actual"
) &&
test_must_be_empty "$actual"
'
test_expect_success '__gitdir - finds repo' '
echo "$ROOT/.git" >expected &&
(
cd subdir/subsubdir &&
__gitdir >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success '__gitdir - returns error when cannot find repo' '
(
__git_dir="non-existing" &&
test_must_fail __gitdir >"$actual"
) &&
test_must_be_empty "$actual"
'
test_expect_success '__gitdir - repo as argument' '
echo "otherrepo/.git" >expected &&
(
__gitdir "otherrepo" >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success '__gitdir - remote as argument' '
echo "remote" >expected &&
(
__gitdir "remote" >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success '__git_dequote - plain unquoted word' '
__git_dequote unquoted-word &&
test unquoted-word = "$dequoted_word"
'
# input: b\a\c\k\'\\\"s\l\a\s\h\es
# expected: back'\"slashes
test_expect_success '__git_dequote - backslash escaped' '
__git_dequote "b\a\c\k\\'\''\\\\\\\"s\l\a\s\h\es" &&
test "back'\''\\\"slashes" = "$dequoted_word"
'
# input: sin'gle\' '"quo'ted
# expected: single\ "quoted
test_expect_success '__git_dequote - single quoted' '
__git_dequote "'"sin'gle\\\\' '\\\"quo'ted"'" &&
test '\''single\ "quoted'\'' = "$dequoted_word"
'
# input: dou"ble\\" "\"\quot"ed
# expected: double\ "\quoted
test_expect_success '__git_dequote - double quoted' '
__git_dequote '\''dou"ble\\" "\"\quot"ed'\'' &&
test '\''double\ "\quoted'\'' = "$dequoted_word"
'
# input: 'open single quote
test_expect_success '__git_dequote - open single quote' '
__git_dequote "'\''open single quote" &&
test "open single quote" = "$dequoted_word"
'
# input: "open double quote
test_expect_success '__git_dequote - open double quote' '
__git_dequote "\"open double quote" &&
test "open double quote" = "$dequoted_word"
'
test_expect_success '__git_count_path_components - no slashes' '
echo 1 >expected &&
__git_count_path_components a >"$actual" &&
test_cmp expected "$actual"
'
test_expect_success '__git_count_path_components - relative' '
echo 3 >expected &&
__git_count_path_components a/b/c >"$actual" &&
test_cmp expected "$actual"
'
test_expect_success '__git_count_path_components - absolute' '
echo 3 >expected &&
__git_count_path_components /a/b/c >"$actual" &&
test_cmp expected "$actual"
'
test_expect_success '__git_count_path_components - trailing slash' '
echo 3 >expected &&
__git_count_path_components a/b/c/ >"$actual" &&
test_cmp expected "$actual"
'
test_expect_success '__gitcomp_direct - puts everything into COMPREPLY as-is' '
sed -e "s/Z$//g" >expected <<-EOF &&
with-trailing-space Z
without-trailing-spaceZ
--option Z
--option=Z
$invalid_variable_name Z
EOF
(
cur=should_be_ignored &&
__gitcomp_direct "$(cat expected)" &&
print_comp
) &&
test_cmp expected out
'
test_expect_success '__gitcomp - trailing space - options' '
test_gitcomp "--re" "--dry-run --reuse-message= --reedit-message=
--reset-author" <<-EOF
--reuse-message=Z
--reedit-message=Z
--reset-author Z
EOF
'
test_expect_success '__gitcomp - trailing space - config keys' '
test_gitcomp "br" "branch. branch.autosetupmerge
branch.autosetuprebase browser." <<-\EOF
branch.Z
branch.autosetupmerge Z
branch.autosetuprebase Z
browser.Z
EOF
'
test_expect_success '__gitcomp - option parameter' '
test_gitcomp "--strategy=re" "octopus ours recursive resolve subtree" \
"" "re" <<-\EOF
recursive Z
resolve Z
EOF
'
test_expect_success '__gitcomp - prefix' '
test_gitcomp "branch.me" "remote merge mergeoptions rebase" \
"branch.maint." "me" <<-\EOF
branch.maint.merge Z
branch.maint.mergeoptions Z
EOF
'
test_expect_success '__gitcomp - suffix' '
test_gitcomp "branch.me" "master maint next seen" "branch." \
"ma" "." <<-\EOF
branch.master.Z
branch.maint.Z
EOF
'
test_expect_success '__gitcomp - ignore optional negative options' '
test_gitcomp "--" "--abc --def --no-one -- --no-two" <<-\EOF
--abc Z
--def Z
--no-one Z
--no-... Z
EOF
'
test_expect_success '__gitcomp - ignore/narrow optional negative options' '
test_gitcomp "--a" "--abc --abcdef --no-one -- --no-two" <<-\EOF
--abc Z
--abcdef Z
EOF
'
test_expect_success '__gitcomp - ignore/narrow optional negative options' '
test_gitcomp "--n" "--abc --def --no-one -- --no-two" <<-\EOF
--no-one Z
--no-... Z
EOF
'
test_expect_success '__gitcomp - expand all negative options' '
test_gitcomp "--no-" "--abc --def --no-one -- --no-two" <<-\EOF
--no-one Z
--no-two Z
EOF
'
test_expect_success '__gitcomp - expand/narrow all negative options' '
test_gitcomp "--no-o" "--abc --def --no-one -- --no-two" <<-\EOF
--no-one Z
EOF
'
test_expect_success '__gitcomp - equal skip' '
test_gitcomp "--option=" "--option=" <<-\EOF &&
EOF
test_gitcomp "option=" "option=" <<-\EOF
EOF
'
test_expect_success '__gitcomp - doesnt fail because of invalid variable name' '
__gitcomp "$invalid_variable_name"
'
read -r -d "" refs <<-\EOF
main
maint
next
seen
EOF
test_expect_success '__gitcomp_nl - trailing space' '
test_gitcomp_nl "m" "$refs" <<-EOF
main Z
maint Z
EOF
'
test_expect_success '__gitcomp_nl - prefix' '
test_gitcomp_nl "--fixup=m" "$refs" "--fixup=" "m" <<-EOF
--fixup=main Z
--fixup=maint Z
EOF
'
test_expect_success '__gitcomp_nl - suffix' '
test_gitcomp_nl "branch.ma" "$refs" "branch." "ma" "." <<-\EOF
branch.main.Z
branch.maint.Z
EOF
'
test_expect_success '__gitcomp_nl - no suffix' '
test_gitcomp_nl "ma" "$refs" "" "ma" "" <<-\EOF
mainZ
maintZ
EOF
'
test_expect_success '__gitcomp_nl - doesnt fail because of invalid variable name' '
__gitcomp_nl "$invalid_variable_name"
'
test_expect_success '__git_remotes - list remotes from $GIT_DIR/remotes and from config file' '
cat >expect <<-EOF &&
remote_from_file_1
remote_from_file_2
remote_in_config_1
remote_in_config_2
EOF
test_when_finished "rm -rf .git/remotes" &&
mkdir -p .git/remotes &&
>.git/remotes/remote_from_file_1 &&
>.git/remotes/remote_from_file_2 &&
test_when_finished "git remote remove remote_in_config_1" &&
git remote add remote_in_config_1 git://remote_1 &&
test_when_finished "git remote remove remote_in_config_2" &&
git remote add remote_in_config_2 git://remote_2 &&
(
__git_remotes >actual
) &&
test_cmp expect actual
'
test_expect_success '__git_is_configured_remote' '
test_when_finished "git remote remove remote_1" &&
git remote add remote_1 git://remote_1 &&
test_when_finished "git remote remove remote_2" &&
git remote add remote_2 git://remote_2 &&
(
__git_is_configured_remote remote_2 &&
test_must_fail __git_is_configured_remote non-existent
)
'
test_expect_success 'setup for ref completion' '
git commit --allow-empty -m initial &&
git branch -M main &&
git branch matching-branch &&
git tag matching-tag &&
(
cd otherrepo &&
git commit --allow-empty -m initial &&
git branch -m main main-in-other &&
git branch branch-in-other &&
git tag tag-in-other
) &&
git remote add other "$ROOT/otherrepo/.git" &&
git fetch --no-tags other &&
(
cd slashrepo &&
git commit --allow-empty -m initial &&
git branch -m main branch/with/slash
) &&
git remote add remote/with/slash "$ROOT/slashrepo/.git" &&
git fetch --no-tags remote/with/slash &&
rm -f .git/FETCH_HEAD &&
git init thirdrepo
'
test_expect_success '__git_refs - simple' '
cat >expected <<-EOF &&
HEAD
main
matching-branch
other/HEAD
other/branch-in-other
other/main-in-other
remote/with/slash/HEAD
remote/with/slash/branch/with/slash
matching-tag
EOF
(
cur= &&
__git_refs >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success '__git_refs - full refs' '
cat >expected <<-EOF &&
refs/heads/main
refs/heads/matching-branch
refs/remotes/other/HEAD
refs/remotes/other/branch-in-other
refs/remotes/other/main-in-other
refs/remotes/remote/with/slash/HEAD
refs/remotes/remote/with/slash/branch/with/slash
refs/tags/matching-tag
EOF
(
cur=refs/heads/ &&
__git_refs >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success '__git_refs - repo given on the command line' '
cat >expected <<-EOF &&
HEAD
branch-in-other
main-in-other
tag-in-other
EOF
(
__git_dir="$ROOT/otherrepo/.git" &&
cur= &&
__git_refs >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success '__git_refs - remote on local file system' '
cat >expected <<-EOF &&
HEAD
branch-in-other
main-in-other
tag-in-other
EOF
(
cur= &&
__git_refs otherrepo >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success '__git_refs - remote on local file system - full refs' '
cat >expected <<-EOF &&
refs/heads/branch-in-other
refs/heads/main-in-other
refs/tags/tag-in-other
EOF
(
cur=refs/ &&
__git_refs otherrepo >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success '__git_refs - configured remote' '
cat >expected <<-EOF &&
HEAD
HEAD
branch-in-other
main-in-other
EOF
(
cur= &&
__git_refs other >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success '__git_refs - configured remote - with slash' '
cat >expected <<-EOF &&
HEAD
HEAD
branch/with/slash
EOF
(
cur= &&
__git_refs remote/with/slash >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success '__git_refs - configured remote - full refs' '
cat >expected <<-EOF &&
HEAD
refs/heads/branch-in-other
refs/heads/main-in-other
refs/tags/tag-in-other
EOF
(
cur=refs/ &&
__git_refs other >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success '__git_refs - configured remote - repo given on the command line' '
cat >expected <<-EOF &&
HEAD
HEAD
branch-in-other
main-in-other
EOF
(
cd thirdrepo &&
__git_dir="$ROOT/.git" &&
cur= &&
__git_refs other >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success '__git_refs - configured remote - full refs - repo given on the command line' '
cat >expected <<-EOF &&
HEAD
refs/heads/branch-in-other
refs/heads/main-in-other
refs/tags/tag-in-other
EOF
(
cd thirdrepo &&
__git_dir="$ROOT/.git" &&
cur=refs/ &&
__git_refs other >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success '__git_refs - configured remote - remote name matches a directory' '
cat >expected <<-EOF &&
HEAD
HEAD
branch-in-other
main-in-other
EOF
mkdir other &&
test_when_finished "rm -rf other" &&
(
cur= &&
__git_refs other >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success '__git_refs - URL remote' '
cat >expected <<-EOF &&
HEAD
branch-in-other
main-in-other
tag-in-other
EOF
(
cur= &&
__git_refs "file://$ROOT/otherrepo/.git" >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success '__git_refs - URL remote - full refs' '
cat >expected <<-EOF &&
HEAD
refs/heads/branch-in-other
refs/heads/main-in-other
refs/tags/tag-in-other
EOF
(
cur=refs/ &&
__git_refs "file://$ROOT/otherrepo/.git" >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success '__git_refs - non-existing remote' '
(
cur= &&
__git_refs non-existing >"$actual"
) &&
test_must_be_empty "$actual"
'
test_expect_success '__git_refs - non-existing remote - full refs' '
(
cur=refs/ &&
__git_refs non-existing >"$actual"
) &&
test_must_be_empty "$actual"
'
test_expect_success '__git_refs - non-existing URL remote' '
(
cur= &&
__git_refs "file://$ROOT/non-existing" >"$actual"
) &&
test_must_be_empty "$actual"
'
test_expect_success '__git_refs - non-existing URL remote - full refs' '
(
cur=refs/ &&
__git_refs "file://$ROOT/non-existing" >"$actual"
) &&
test_must_be_empty "$actual"
'
test_expect_success '__git_refs - not in a git repository' '
(
GIT_CEILING_DIRECTORIES="$ROOT" &&
export GIT_CEILING_DIRECTORIES &&
cd subdir &&
cur= &&
__git_refs >"$actual"
) &&
test_must_be_empty "$actual"
'
test_expect_success '__git_refs - unique remote branches for git checkout DWIMery' '
cat >expected <<-EOF &&
HEAD
main
matching-branch
other/HEAD
other/ambiguous
other/branch-in-other
other/main-in-other
remote/with/slash/HEAD
remote/with/slash/ambiguous
remote/with/slash/branch-in-remote
remote/with/slash/branch/with/slash
matching-tag
branch-in-other
branch-in-remote
branch/with/slash
main-in-other
EOF
for remote_ref in refs/remotes/other/ambiguous \
refs/remotes/remote/with/slash/ambiguous \
refs/remotes/remote/with/slash/branch-in-remote
do
git update-ref $remote_ref main &&
test_when_finished "git update-ref -d $remote_ref" || return 1
done &&
(
cur= &&
__git_refs "" 1 >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success '__git_refs - after --opt=' '
cat >expected <<-EOF &&
HEAD
main
matching-branch
other/HEAD
other/branch-in-other
other/main-in-other
remote/with/slash/HEAD
remote/with/slash/branch/with/slash
matching-tag
EOF
(
cur="--opt=" &&
__git_refs "" "" "" "" >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success '__git_refs - after --opt= - full refs' '
cat >expected <<-EOF &&
refs/heads/main
refs/heads/matching-branch
refs/remotes/other/HEAD
refs/remotes/other/branch-in-other
refs/remotes/other/main-in-other
refs/remotes/remote/with/slash/HEAD
refs/remotes/remote/with/slash/branch/with/slash
refs/tags/matching-tag
EOF
(
cur="--opt=refs/" &&
__git_refs "" "" "" refs/ >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success '__git refs - excluding refs' '
cat >expected <<-EOF &&
^HEAD
^main
^matching-branch
^other/HEAD
^other/branch-in-other
^other/main-in-other
^remote/with/slash/HEAD
^remote/with/slash/branch/with/slash
^matching-tag
EOF
(
cur=^ &&
__git_refs >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success '__git refs - excluding full refs' '
cat >expected <<-EOF &&
^refs/heads/main
^refs/heads/matching-branch
^refs/remotes/other/HEAD
^refs/remotes/other/branch-in-other
^refs/remotes/other/main-in-other
^refs/remotes/remote/with/slash/HEAD
^refs/remotes/remote/with/slash/branch/with/slash
^refs/tags/matching-tag
EOF
(
cur=^refs/ &&
__git_refs >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success 'setup for filtering matching refs' '
git branch matching/branch &&
git tag matching/tag &&
git -C otherrepo branch matching/branch-in-other &&
git fetch --no-tags other &&
rm -f .git/FETCH_HEAD
'
test_expect_success '__git_refs - do not filter refs unless told so' '
cat >expected <<-EOF &&
HEAD
main
matching-branch
matching/branch
other/HEAD
other/branch-in-other
other/main-in-other
other/matching/branch-in-other
remote/with/slash/HEAD
remote/with/slash/branch/with/slash
matching-tag
matching/tag
EOF
(
cur=main &&
__git_refs >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success '__git_refs - only matching refs' '
cat >expected <<-EOF &&
matching-branch
matching/branch
matching-tag
matching/tag
EOF
(
cur=mat &&
__git_refs "" "" "" "$cur" >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success '__git_refs - only matching refs - full refs' '
cat >expected <<-EOF &&
refs/heads/matching-branch
refs/heads/matching/branch
EOF
(
cur=refs/heads/mat &&
__git_refs "" "" "" "$cur" >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success '__git_refs - only matching refs - remote on local file system' '
cat >expected <<-EOF &&
main-in-other
matching/branch-in-other
EOF
(
cur=ma &&
__git_refs otherrepo "" "" "$cur" >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success '__git_refs - only matching refs - configured remote' '
cat >expected <<-EOF &&
main-in-other
matching/branch-in-other
EOF
(
cur=ma &&
__git_refs other "" "" "$cur" >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success '__git_refs - only matching refs - remote - full refs' '
cat >expected <<-EOF &&
refs/heads/main-in-other
refs/heads/matching/branch-in-other
EOF
(
cur=refs/heads/ma &&
__git_refs other "" "" "$cur" >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success '__git_refs - only matching refs - checkout DWIMery' '
cat >expected <<-EOF &&
matching-branch
matching/branch
matching-tag
matching/tag
matching/branch-in-other
EOF
for remote_ref in refs/remotes/other/ambiguous \
refs/remotes/remote/ambiguous \
refs/remotes/remote/branch-in-remote
do
git update-ref $remote_ref main &&
test_when_finished "git update-ref -d $remote_ref" || return 1
done &&
(
cur=mat &&
__git_refs "" 1 "" "$cur" >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success 'teardown after filtering matching refs' '
git branch -d matching/branch &&
git tag -d matching/tag &&
git update-ref -d refs/remotes/other/matching/branch-in-other &&
git -C otherrepo branch -D matching/branch-in-other
'
test_expect_success '__git_refs - for-each-ref format specifiers in prefix' '
cat >expected <<-EOF &&
evil-%%-%42-%(refname)..main
EOF
(
cur="evil-%%-%42-%(refname)..mai" &&
__git_refs "" "" "evil-%%-%42-%(refname).." mai >"$actual"
) &&
test_cmp expected "$actual"
'
test_expect_success '__git_complete_refs - simple' '
sed -e "s/Z$//" >expected <<-EOF &&
HEAD Z
main Z
matching-branch Z
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
remote/with/slash/HEAD Z
remote/with/slash/branch/with/slash Z
matching-tag Z
EOF
(
cur= &&
__git_complete_refs &&
print_comp
) &&
test_cmp expected out
'
test_expect_success '__git_complete_refs - matching' '
sed -e "s/Z$//" >expected <<-EOF &&
matching-branch Z
matching-tag Z
EOF
(
cur=mat &&
__git_complete_refs &&
print_comp
) &&
test_cmp expected out
'
test_expect_success '__git_complete_refs - remote' '
sed -e "s/Z$//" >expected <<-EOF &&
HEAD Z
HEAD Z
branch-in-other Z
main-in-other Z
EOF
(
cur= &&
__git_complete_refs --remote=other &&
print_comp
) &&
test_cmp expected out
'
test_expect_success '__git_complete_refs - remote - with slash' '
sed -e "s/Z$//" >expected <<-EOF &&
HEAD Z
HEAD Z
branch/with/slash Z
EOF
(
cur= &&
__git_complete_refs --remote=remote/with/slash &&
print_comp
) &&
test_cmp expected out
'
test_expect_success '__git_complete_refs - track' '
sed -e "s/Z$//" >expected <<-EOF &&
HEAD Z
main Z
matching-branch Z
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
remote/with/slash/HEAD Z
remote/with/slash/branch/with/slash Z
matching-tag Z
branch-in-other Z
branch/with/slash Z
main-in-other Z
EOF
(
cur= &&
__git_complete_refs --track &&
print_comp
) &&
test_cmp expected out
'
test_expect_success '__git_complete_refs - current word' '
sed -e "s/Z$//" >expected <<-EOF &&
matching-branch Z
matching-tag Z
EOF
(
cur="--option=mat" &&
__git_complete_refs --cur="${cur#*=}" &&
print_comp
) &&
test_cmp expected out
'
test_expect_success '__git_complete_refs - prefix' '
sed -e "s/Z$//" >expected <<-EOF &&
v1.0..matching-branch Z
v1.0..matching-tag Z
EOF
(
cur=v1.0..mat &&
__git_complete_refs --pfx=v1.0.. --cur=mat &&
print_comp
) &&
test_cmp expected out
'
test_expect_success '__git_complete_refs - suffix' '
cat >expected <<-EOF &&
HEAD.
main.
matching-branch.
other/HEAD.
other/branch-in-other.
other/main-in-other.
remote/with/slash/HEAD.
remote/with/slash/branch/with/slash.
matching-tag.
EOF
(
cur= &&
__git_complete_refs --sfx=. &&
print_comp
) &&
test_cmp expected out
'
test_expect_success '__git_complete_fetch_refspecs - simple' '
sed -e "s/Z$//" >expected <<-EOF &&
HEAD:HEAD Z
HEAD:HEAD Z
branch-in-other:branch-in-other Z
main-in-other:main-in-other Z
EOF
(
cur= &&
__git_complete_fetch_refspecs other &&
print_comp
) &&
test_cmp expected out
'
test_expect_success '__git_complete_fetch_refspecs - with slash' '
sed -e "s/Z$//" >expected <<-EOF &&
HEAD:HEAD Z
HEAD:HEAD Z
branch/with/slash:branch/with/slash Z
EOF
(
cur= &&
__git_complete_fetch_refspecs remote/with/slash &&
print_comp
) &&
test_cmp expected out
'
test_expect_success '__git_complete_fetch_refspecs - matching' '
sed -e "s/Z$//" >expected <<-EOF &&
branch-in-other:branch-in-other Z
EOF
(
cur=br &&
__git_complete_fetch_refspecs other "" br &&
print_comp
) &&
test_cmp expected out
'
test_expect_success '__git_complete_fetch_refspecs - prefix' '
sed -e "s/Z$//" >expected <<-EOF &&
+HEAD:HEAD Z
+HEAD:HEAD Z
+branch-in-other:branch-in-other Z
+main-in-other:main-in-other Z
EOF
(
cur="+" &&
__git_complete_fetch_refspecs other "+" "" &&
print_comp
) &&
test_cmp expected out
'
test_expect_success '__git_complete_fetch_refspecs - fully qualified' '
sed -e "s/Z$//" >expected <<-EOF &&
refs/heads/branch-in-other:refs/heads/branch-in-other Z
refs/heads/main-in-other:refs/heads/main-in-other Z
refs/tags/tag-in-other:refs/tags/tag-in-other Z
EOF
(
cur=refs/ &&
__git_complete_fetch_refspecs other "" refs/ &&
print_comp
) &&
test_cmp expected out
'
test_expect_success '__git_complete_fetch_refspecs - fully qualified & prefix' '
sed -e "s/Z$//" >expected <<-EOF &&
+refs/heads/branch-in-other:refs/heads/branch-in-other Z
+refs/heads/main-in-other:refs/heads/main-in-other Z
+refs/tags/tag-in-other:refs/tags/tag-in-other Z
EOF
(
cur=+refs/ &&
__git_complete_fetch_refspecs other + refs/ &&
print_comp
) &&
test_cmp expected out
'
test_expect_success '__git_complete_worktree_paths' '
test_when_finished "git worktree remove other_wt" &&
git worktree add --orphan other_wt &&
run_completion "git worktree remove " &&
grep other_wt out
'
test_expect_success '__git_complete_worktree_paths - not a git repository' '
(
cd non-repo &&
GIT_CEILING_DIRECTORIES="$ROOT" &&
export GIT_CEILING_DIRECTORIES &&
test_completion "git worktree remove " ""
)
'
test_expect_success '__git_complete_worktree_paths with -C' '
test_when_finished "git -C otherrepo worktree remove otherrepo_wt" &&
git -C otherrepo worktree add --orphan otherrepo_wt &&
run_completion "git -C otherrepo worktree remove " &&
grep otherrepo_wt out
'
test_expect_success 'git switch - with no options, complete local branches and unique remote branch names for DWIM logic' '
test_completion "git switch " <<-\EOF
branch-in-other Z
branch/with/slash Z
main Z
main-in-other Z
matching-branch Z
EOF
'
test_expect_success 'git bisect - when not bisecting, complete only replay and start subcommands' '
test_completion "git bisect " <<-\EOF
replay Z
start Z
EOF
'
test_expect_success 'git bisect - complete options to start subcommand' '
test_completion "git bisect start --" <<-\EOF
--term-new Z
--term-bad Z
--term-old Z
--term-good Z
--no-checkout Z
--first-parent Z
EOF
'
test_expect_success 'setup for git-bisect tests requiring a repo' '
git init git-bisect &&
(
cd git-bisect &&
echo "initial contents" >file &&
git add file &&
git commit -am "Initial commit" &&
git tag initial &&
echo "new line" >>file &&
git commit -am "First change" &&
echo "another new line" >>file &&
git commit -am "Second change" &&
git tag final
)
'
test_expect_success 'git bisect - start subcommand arguments before double-dash are completed as revs' '
(
cd git-bisect &&
test_completion "git bisect start " <<-\EOF
HEAD Z
final Z
initial Z
master Z
EOF
)
'
# Note that these arguments are <pathspec>s, which in practice the fallback
# completion (not the git completion) later ends up completing as paths.
test_expect_success 'git bisect - start subcommand arguments after double-dash are not completed' '
(
cd git-bisect &&
test_completion "git bisect start final initial -- " ""
)
'
test_expect_success 'setup for git-bisect tests requiring ongoing bisection' '
(
cd git-bisect &&
git bisect start --term-new=custom_new --term-old=custom_old final initial
)
'
test_expect_success 'git-bisect - when bisecting all subcommands are candidates' '
(
cd git-bisect &&
test_completion "git bisect " <<-\EOF
start Z
bad Z
custom_new Z
custom_old Z
new Z
good Z
old Z
terms Z
skip Z
reset Z
visualize Z
replay Z
log Z
run Z
help Z
EOF
)
'
test_expect_success 'git-bisect - options to terms subcommand are candidates' '
(
cd git-bisect &&
test_completion "git bisect terms --" <<-\EOF
--term-bad Z
--term-good Z
--term-new Z
--term-old Z
EOF
)
'
test_expect_success 'git-bisect - git-log options to visualize subcommand are candidates' '
(
cd git-bisect &&
# The completion used for git-log and here does not complete
# every git-log option, so rather than hope to stay in sync
# with exactly what it does we will just spot-test here.
test_completion "git bisect visualize --sta" <<-\EOF &&
--stat Z
EOF
test_completion "git bisect visualize --summar" <<-\EOF
--summary Z
EOF
)
'
test_expect_success 'git-bisect - view subcommand is not a candidate' '
(
cd git-bisect &&
test_completion "git bisect vi" <<-\EOF
visualize Z
EOF
)
'
test_expect_success 'git-bisect - existing view subcommand is recognized and enables completion of git-log options' '
(
cd git-bisect &&
# The completion used for git-log and here does not complete
# every git-log option, so rather than hope to stay in sync
# with exactly what it does we will just spot-test here.
test_completion "git bisect view --sta" <<-\EOF &&
--stat Z
EOF
test_completion "git bisect view --summar" <<-\EOF
--summary Z
EOF
)
'
test_expect_success 'git checkout - completes refs and unique remote branches for DWIM' '
test_completion "git checkout " <<-\EOF
HEAD Z
branch-in-other Z
branch/with/slash Z
main Z
main-in-other Z
matching-branch Z
matching-tag Z
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
remote/with/slash/HEAD Z
remote/with/slash/branch/with/slash Z
EOF
'
test_expect_success 'git switch - with --no-guess, complete only local branches' '
test_completion "git switch --no-guess " <<-\EOF
main Z
matching-branch Z
EOF
'
test_expect_success 'git switch - with GIT_COMPLETION_CHECKOUT_NO_GUESS=1, complete only local branches' '
GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git switch " <<-\EOF
main Z
matching-branch Z
EOF
'
test_expect_success 'git switch - --guess overrides GIT_COMPLETION_CHECKOUT_NO_GUESS=1, complete local branches and unique remote names for DWIM logic' '
GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git switch --guess " <<-\EOF
branch-in-other Z
branch/with/slash Z
main Z
main-in-other Z
matching-branch Z
EOF
'
test_expect_success 'git switch - a later --guess overrides previous --no-guess, complete local and remote unique branches for DWIM' '
test_completion "git switch --no-guess --guess " <<-\EOF
branch-in-other Z
branch/with/slash Z
main Z
main-in-other Z
matching-branch Z
EOF
'
test_expect_success 'git switch - a later --no-guess overrides previous --guess, complete only local branches' '
test_completion "git switch --guess --no-guess " <<-\EOF
main Z
matching-branch Z
EOF
'
test_expect_success 'git checkout - with GIT_COMPLETION_NO_GUESS=1 only completes refs' '
GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git checkout " <<-\EOF
HEAD Z
main Z
matching-branch Z
matching-tag Z
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
remote/with/slash/HEAD Z
remote/with/slash/branch/with/slash Z
EOF
'
test_expect_success 'git checkout - --guess overrides GIT_COMPLETION_NO_GUESS=1, complete refs and unique remote branches for DWIM' '
GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git checkout --guess " <<-\EOF
HEAD Z
branch-in-other Z
branch/with/slash Z
main Z
main-in-other Z
matching-branch Z
matching-tag Z
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
remote/with/slash/HEAD Z
remote/with/slash/branch/with/slash Z
EOF
'
test_expect_success 'git checkout - with --no-guess, only completes refs' '
test_completion "git checkout --no-guess " <<-\EOF
HEAD Z
main Z
matching-branch Z
matching-tag Z
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
remote/with/slash/HEAD Z
remote/with/slash/branch/with/slash Z
EOF
'
test_expect_success 'git checkout - a later --guess overrides previous --no-guess, complete refs and unique remote branches for DWIM' '
test_completion "git checkout --no-guess --guess " <<-\EOF
HEAD Z
branch-in-other Z
branch/with/slash Z
main Z
main-in-other Z
matching-branch Z
matching-tag Z
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
remote/with/slash/HEAD Z
remote/with/slash/branch/with/slash Z
EOF
'
test_expect_success 'git checkout - a later --no-guess overrides previous --guess, complete only refs' '
test_completion "git checkout --guess --no-guess " <<-\EOF
HEAD Z
main Z
matching-branch Z
matching-tag Z
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
remote/with/slash/HEAD Z
remote/with/slash/branch/with/slash Z
EOF
'
test_expect_success 'git checkout - with checkout.guess = false, only completes refs' '
test_config checkout.guess false &&
test_completion "git checkout " <<-\EOF
HEAD Z
main Z
matching-branch Z
matching-tag Z
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
remote/with/slash/HEAD Z
remote/with/slash/branch/with/slash Z
EOF
'
test_expect_success 'git checkout - with checkout.guess = true, completes refs and unique remote branches for DWIM' '
test_config checkout.guess true &&
test_completion "git checkout " <<-\EOF
HEAD Z
branch-in-other Z
branch/with/slash Z
main Z
main-in-other Z
matching-branch Z
matching-tag Z
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
remote/with/slash/HEAD Z
remote/with/slash/branch/with/slash Z
EOF
'
test_expect_success 'git checkout - a later --guess overrides previous checkout.guess = false, complete refs and unique remote branches for DWIM' '
test_config checkout.guess false &&
test_completion "git checkout --guess " <<-\EOF
HEAD Z
branch-in-other Z
branch/with/slash Z
main Z
main-in-other Z
matching-branch Z
matching-tag Z
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
remote/with/slash/HEAD Z
remote/with/slash/branch/with/slash Z
EOF
'
test_expect_success 'git checkout - a later --no-guess overrides previous checkout.guess = true, complete only refs' '
test_config checkout.guess true &&
test_completion "git checkout --no-guess " <<-\EOF
HEAD Z
main Z
matching-branch Z
matching-tag Z
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
remote/with/slash/HEAD Z
remote/with/slash/branch/with/slash Z
EOF
'
test_expect_success 'git switch - with --detach, complete all references' '
test_completion "git switch --detach " <<-\EOF
HEAD Z
main Z
matching-branch Z
matching-tag Z
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
remote/with/slash/HEAD Z
remote/with/slash/branch/with/slash Z
EOF
'
test_expect_success 'git checkout - with --detach, complete only references' '
test_completion "git checkout --detach " <<-\EOF
HEAD Z
main Z
matching-branch Z
matching-tag Z
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
remote/with/slash/HEAD Z
remote/with/slash/branch/with/slash Z
EOF
'
test_expect_success 'setup sparse-checkout tests' '
# set up sparse-checkout repo
git init sparse-checkout &&
(
cd sparse-checkout &&
mkdir -p folder1/0/1 folder2/0 folder3 &&
touch folder1/0/1/t.txt &&
touch folder2/0/t.txt &&
touch folder3/t.txt &&
git add . &&
git commit -am "Initial commit"
)
'
test_expect_success 'sparse-checkout completes subcommands' '
test_completion "git sparse-checkout " <<-\EOF
list Z
init Z
set Z
add Z
reapply Z
disable Z
EOF
'
test_expect_success 'cone mode sparse-checkout completes directory names' '
# initialize sparse-checkout definitions
git -C sparse-checkout sparse-checkout set --cone folder1/0 folder3 &&
# test tab completion
(
cd sparse-checkout &&
test_completion "git sparse-checkout set f" <<-\EOF
folder1/
folder2/
folder3/
EOF
) &&
(
cd sparse-checkout &&
test_completion "git sparse-checkout set folder1/" <<-\EOF
folder1/0/
EOF
) &&
(
cd sparse-checkout &&
test_completion "git sparse-checkout set folder1/0/" <<-\EOF
folder1/0/1/
EOF
) &&
(
cd sparse-checkout/folder1 &&
test_completion "git sparse-checkout add 0" <<-\EOF
0/
EOF
)
'
test_expect_success 'cone mode sparse-checkout completes directory names with spaces and accents' '
# reset sparse-checkout
git -C sparse-checkout sparse-checkout disable &&
(
cd sparse-checkout &&
mkdir "directory with spaces" &&
mkdir "directory-with-áccent" &&
>"directory with spaces/randomfile" &&
>"directory-with-áccent/randomfile" &&
git add . &&
git commit -m "Add directory with spaces and directory with accent" &&
git sparse-checkout set --cone "directory with spaces" \
"directory-with-áccent" &&
test_completion "git sparse-checkout add dir" <<-\EOF &&
directory with spaces/
directory-with-áccent/
EOF
rm -rf "directory with spaces" &&
rm -rf "directory-with-áccent" &&
git add . &&
git commit -m "Remove directory with spaces and directory with accent"
)
'
# use FUNNYNAMES to avoid running on Windows, which doesn't permit tabs in paths
test_expect_success FUNNYNAMES 'cone mode sparse-checkout completes directory names with tabs' '
# reset sparse-checkout
git -C sparse-checkout sparse-checkout disable &&
(
cd sparse-checkout &&
mkdir "$(printf "directory\twith\ttabs")" &&
>"$(printf "directory\twith\ttabs")/randomfile" &&
git add . &&
git commit -m "Add directory with tabs" &&
git sparse-checkout set --cone \
"$(printf "directory\twith\ttabs")" &&
test_completion "git sparse-checkout add dir" <<-\EOF &&
directory with tabs/
EOF
rm -rf "$(printf "directory\twith\ttabs")" &&
git add . &&
git commit -m "Remove directory with tabs"
)
'
# use FUNNYNAMES to avoid running on Windows, and !CYGWIN for Cygwin, as neither permit backslashes in paths
test_expect_success FUNNYNAMES,!CYGWIN 'cone mode sparse-checkout completes directory names with backslashes' '
# reset sparse-checkout
git -C sparse-checkout sparse-checkout disable &&
(
cd sparse-checkout &&
mkdir "directory\with\backslashes" &&
>"directory\with\backslashes/randomfile" &&
git add . &&
git commit -m "Add directory with backslashes" &&
git sparse-checkout set --cone \
"directory\with\backslashes" &&
test_completion "git sparse-checkout add dir" <<-\EOF &&
directory\with\backslashes/
EOF
rm -rf "directory\with\backslashes" &&
git add . &&
git commit -m "Remove directory with backslashes"
)
'
test_expect_success 'non-cone mode sparse-checkout gives rooted paths' '
# reset sparse-checkout repo to non-cone mode
git -C sparse-checkout sparse-checkout disable &&
git -C sparse-checkout sparse-checkout set --no-cone &&
(
cd sparse-checkout &&
# expected to be empty since we have not configured
# custom completion for non-cone mode
test_completion "git sparse-checkout set f" <<-\EOF
/folder1/0/1/t.txt Z
/folder1/expected Z
/folder1/out Z
/folder1/out_sorted Z
/folder2/0/t.txt Z
/folder3/t.txt Z
EOF
)
'
test_expect_success 'git sparse-checkout set --cone completes directory names' '
git -C sparse-checkout sparse-checkout disable &&
(
cd sparse-checkout &&
test_completion "git sparse-checkout set --cone f" <<-\EOF
folder1/
folder2/
folder3/
EOF
)
'
test_expect_success 'git switch - with -d, complete all references' '
test_completion "git switch -d " <<-\EOF
HEAD Z
main Z
matching-branch Z
matching-tag Z
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
remote/with/slash/HEAD Z
remote/with/slash/branch/with/slash Z
EOF
'
test_expect_success 'git checkout - with -d, complete only references' '
test_completion "git checkout -d " <<-\EOF
HEAD Z
main Z
matching-branch Z
matching-tag Z
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
remote/with/slash/HEAD Z
remote/with/slash/branch/with/slash Z
EOF
'
test_expect_success 'git switch - with --track, complete only remote branches' '
test_completion "git switch --track " <<-\EOF &&
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
remote/with/slash/HEAD Z
remote/with/slash/branch/with/slash Z
EOF
test_completion "git switch -t " <<-\EOF
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
remote/with/slash/HEAD Z
remote/with/slash/branch/with/slash Z
EOF
'
test_expect_success 'git checkout - with --track, complete only remote branches' '
test_completion "git checkout --track " <<-\EOF &&
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
remote/with/slash/HEAD Z
remote/with/slash/branch/with/slash Z
EOF
test_completion "git checkout -t " <<-\EOF
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
remote/with/slash/HEAD Z
remote/with/slash/branch/with/slash Z
EOF
'
test_expect_success 'git switch - with --no-track, complete only local branch names' '
test_completion "git switch --no-track " <<-\EOF
main Z
matching-branch Z
EOF
'
test_expect_success 'git checkout - with --no-track, complete only local references' '
test_completion "git checkout --no-track " <<-\EOF
HEAD Z
main Z
matching-branch Z
matching-tag Z
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
remote/with/slash/HEAD Z
remote/with/slash/branch/with/slash Z
EOF
'
test_expect_success 'git switch - with -c, complete all references' '
test_completion "git switch -c new-branch " <<-\EOF
HEAD Z
main Z
matching-branch Z
matching-tag Z
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
remote/with/slash/HEAD Z
remote/with/slash/branch/with/slash Z
EOF
'
test_expect_success 'git switch - with -C, complete all references' '
test_completion "git switch -C new-branch " <<-\EOF
HEAD Z
main Z
matching-branch Z
matching-tag Z
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
remote/with/slash/HEAD Z
remote/with/slash/branch/with/slash Z
EOF
'
test_expect_success 'git switch - with -c and --track, complete all references' '
test_completion "git switch -c new-branch --track " <<-EOF
HEAD Z
main Z
matching-branch Z
matching-tag Z
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
remote/with/slash/HEAD Z
remote/with/slash/branch/with/slash Z
EOF
'
test_expect_success 'git switch - with -C and --track, complete all references' '
test_completion "git switch -C new-branch --track " <<-EOF
HEAD Z
main Z
matching-branch Z
matching-tag Z
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
remote/with/slash/HEAD Z
remote/with/slash/branch/with/slash Z
EOF
'
test_expect_success 'git switch - with -c and --no-track, complete all references' '
test_completion "git switch -c new-branch --no-track " <<-\EOF
HEAD Z
main Z
matching-branch Z
matching-tag Z
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
remote/with/slash/HEAD Z
remote/with/slash/branch/with/slash Z
EOF
'
test_expect_success 'git switch - with -C and --no-track, complete all references' '
test_completion "git switch -C new-branch --no-track " <<-\EOF
HEAD Z
main Z
matching-branch Z
matching-tag Z
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
remote/with/slash/HEAD Z
remote/with/slash/branch/with/slash Z
EOF
'
test_expect_success 'git checkout - with -b, complete all references' '
test_completion "git checkout -b new-branch " <<-\EOF
HEAD Z
main Z
matching-branch Z
matching-tag Z
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
remote/with/slash/HEAD Z
remote/with/slash/branch/with/slash Z
EOF
'
test_expect_success 'git checkout - with -B, complete all references' '
test_completion "git checkout -B new-branch " <<-\EOF
HEAD Z
main Z
matching-branch Z
matching-tag Z
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
remote/with/slash/HEAD Z
remote/with/slash/branch/with/slash Z
EOF
'
test_expect_success 'git checkout - with -b and --track, complete all references' '
test_completion "git checkout -b new-branch --track " <<-EOF
HEAD Z
main Z
matching-branch Z
matching-tag Z
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
remote/with/slash/HEAD Z
remote/with/slash/branch/with/slash Z
EOF
'
test_expect_success 'git checkout - with -B and --track, complete all references' '
test_completion "git checkout -B new-branch --track " <<-EOF
HEAD Z
main Z
matching-branch Z
matching-tag Z
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
remote/with/slash/HEAD Z
remote/with/slash/branch/with/slash Z
EOF
'
test_expect_success 'git checkout - with -b and --no-track, complete all references' '
test_completion "git checkout -b new-branch --no-track " <<-\EOF
HEAD Z
main Z
matching-branch Z
matching-tag Z
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
remote/with/slash/HEAD Z
remote/with/slash/branch/with/slash Z
EOF
'
test_expect_success 'git checkout - with -B and --no-track, complete all references' '
test_completion "git checkout -B new-branch --no-track " <<-\EOF
HEAD Z
main Z
matching-branch Z
matching-tag Z
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
remote/with/slash/HEAD Z
remote/with/slash/branch/with/slash Z
EOF
'
test_expect_success 'git switch - for -c, complete local branches and unique remote branches' '
test_completion "git switch -c " <<-\EOF
branch-in-other Z
branch/with/slash Z
main Z
main-in-other Z
matching-branch Z
EOF
'
test_expect_success 'git switch - for -C, complete local branches and unique remote branches' '
test_completion "git switch -C " <<-\EOF
branch-in-other Z
branch/with/slash Z
main Z
main-in-other Z
matching-branch Z
EOF
'
test_expect_success 'git switch - for -c with --no-guess, complete local branches only' '
test_completion "git switch --no-guess -c " <<-\EOF
main Z
matching-branch Z
EOF
'
test_expect_success 'git switch - for -C with --no-guess, complete local branches only' '
test_completion "git switch --no-guess -C " <<-\EOF
main Z
matching-branch Z
EOF
'
test_expect_success 'git switch - for -c with --no-track, complete local branches only' '
test_completion "git switch --no-track -c " <<-\EOF
main Z
matching-branch Z
EOF
'
test_expect_success 'git switch - for -C with --no-track, complete local branches only' '
test_completion "git switch --no-track -C " <<-\EOF
main Z
matching-branch Z
EOF
'
test_expect_success 'git checkout - for -b, complete local branches and unique remote branches' '
test_completion "git checkout -b " <<-\EOF
branch-in-other Z
branch/with/slash Z
main Z
main-in-other Z
matching-branch Z
EOF
'
test_expect_success 'git checkout - for -B, complete local branches and unique remote branches' '
test_completion "git checkout -B " <<-\EOF
branch-in-other Z
branch/with/slash Z
main Z
main-in-other Z
matching-branch Z
EOF
'
test_expect_success 'git checkout - for -b with --no-guess, complete local branches only' '
test_completion "git checkout --no-guess -b " <<-\EOF
main Z
matching-branch Z
EOF
'
test_expect_success 'git checkout - for -B with --no-guess, complete local branches only' '
test_completion "git checkout --no-guess -B " <<-\EOF
main Z
matching-branch Z
EOF
'
test_expect_success 'git checkout - for -b with --no-track, complete local branches only' '
test_completion "git checkout --no-track -b " <<-\EOF
main Z
matching-branch Z
EOF
'
test_expect_success 'git checkout - for -B with --no-track, complete local branches only' '
test_completion "git checkout --no-track -B " <<-\EOF
main Z
matching-branch Z
EOF
'
test_expect_success 'git switch - with --orphan completes local branch names and unique remote branch names' '
test_completion "git switch --orphan " <<-\EOF
branch-in-other Z
branch/with/slash Z
main Z
main-in-other Z
matching-branch Z
EOF
'
test_expect_success 'git switch - --orphan with branch already provided completes nothing else' '
test_completion "git switch --orphan main " <<-\EOF
EOF
'
test_expect_success 'git checkout - with --orphan completes local branch names and unique remote branch names' '
test_completion "git checkout --orphan " <<-\EOF
branch-in-other Z
branch/with/slash Z
main Z
main-in-other Z
matching-branch Z
EOF
'
test_expect_success 'git checkout - --orphan with branch already provided completes local refs for a start-point' '
test_completion "git checkout --orphan main " <<-\EOF
HEAD Z
main Z
matching-branch Z
matching-tag Z
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
remote/with/slash/HEAD Z
remote/with/slash/branch/with/slash Z
EOF
'
test_expect_success 'git restore completes modified files' '
test_commit A a.file &&
echo B >a.file &&
test_completion "git restore a." <<-\EOF
a.file
EOF
'
test_expect_success 'teardown after ref completion' '
git branch -d matching-branch &&
git tag -d matching-tag &&
git remote remove other &&
git remote remove remote/with/slash
'
test_path_completion ()
{
test $# = 2 || BUG "not 2 parameters to test_path_completion"
local cur="$1" expected="$2"
echo "$expected" >expected &&
(
# In the following tests calling this function we only
# care about how __git_complete_index_file() deals with
# unusual characters in path names. By requesting only
# untracked files we do not have to bother adding any
# paths to the index in those tests.
__git_complete_index_file --others &&
print_comp
) &&
test_cmp expected out
}
test_expect_success 'setup for path completion tests' '
mkdir simple-dir \
"spaces in dir" \
árvíztűrő &&
touch simple-dir/simple-file \
"spaces in dir/spaces in file" \
"árvíztűrő/Сайн яваарай" &&
if test_have_prereq !MINGW &&
mkdir BS\\dir \
'$'separators\034in\035dir'' &&
touch BS\\dir/DQ\"file \
'$'separators\034in\035dir/sep\036in\037file''
then
test_set_prereq FUNNIERNAMES
else
rm -rf BS\\dir '$'separators\034in\035dir''
fi
'
test_expect_success '__git_complete_index_file - simple' '
test_path_completion simple simple-dir && # Bash is supposed to
# add the trailing /.
test_path_completion simple-dir/simple simple-dir/simple-file
'
test_expect_success \
'__git_complete_index_file - escaped characters on cmdline' '
test_path_completion spac "spaces in dir" && # Bash will turn this
# into "spaces\ in\ dir"
test_path_completion "spaces\\ i" \
"spaces in dir" &&
test_path_completion "spaces\\ in\\ dir/s" \
"spaces in dir/spaces in file" &&
test_path_completion "spaces\\ in\\ dir/spaces\\ i" \
"spaces in dir/spaces in file"
'
test_expect_success \
'__git_complete_index_file - quoted characters on cmdline' '
# Testing with an opening but without a corresponding closing
# double quote is important.
test_path_completion \"spac "spaces in dir" &&
test_path_completion "\"spaces i" \
"spaces in dir" &&
test_path_completion "\"spaces in dir/s" \
"spaces in dir/spaces in file" &&
test_path_completion "\"spaces in dir/spaces i" \
"spaces in dir/spaces in file"
'
test_expect_success '__git_complete_index_file - UTF-8 in ls-files output' '
test_path_completion á árvíztűrő &&
test_path_completion árvíztűrő/С "árvíztűrő/Сайн яваарай"
'
test_expect_success FUNNIERNAMES \
'__git_complete_index_file - C-style escapes in ls-files output' '
test_path_completion BS \
BS\\dir &&
test_path_completion BS\\\\d \
BS\\dir &&
test_path_completion BS\\\\dir/DQ \
BS\\dir/DQ\"file &&
test_path_completion BS\\\\dir/DQ\\\"f \
BS\\dir/DQ\"file
'
test_expect_success FUNNIERNAMES \
'__git_complete_index_file - \nnn-escaped characters in ls-files output' '
test_path_completion sep '$'separators\034in\035dir'' &&
test_path_completion '$'separators\034i'' \
'$'separators\034in\035dir'' &&
test_path_completion '$'separators\034in\035dir/sep'' \
'$'separators\034in\035dir/sep\036in\037file'' &&
test_path_completion '$'separators\034in\035dir/sep\036i'' \
'$'separators\034in\035dir/sep\036in\037file''
'
test_expect_success FUNNYNAMES \
'__git_complete_index_file - removing repeated quoted path components' '
test_when_finished rm -r repeated-quoted &&
mkdir repeated-quoted && # A directory whose name in itself
# would not be quoted ...
>repeated-quoted/0-file &&
>repeated-quoted/1\"file && # ... but here the file makes the
# dirname quoted ...
>repeated-quoted/2-file &&
>repeated-quoted/3\"file && # ... and here, too.
# Still, we shold only list the directory name only once.
test_path_completion repeated repeated-quoted
'
test_expect_success 'teardown after path completion tests' '
rm -rf simple-dir "spaces in dir" árvíztűrő \
BS\\dir '$'separators\034in\035dir''
'
test_expect_success '__git_find_on_cmdline - single match' '
echo list >expect &&
(
words=(git command --opt list) &&
cword=${#words[@]} &&
__git_cmd_idx=1 &&
__git_find_on_cmdline "add list remove" >actual
) &&
test_cmp expect actual
'
test_expect_success '__git_find_on_cmdline - multiple matches' '
echo remove >expect &&
(
words=(git command -o --opt remove list add) &&
cword=${#words[@]} &&
__git_cmd_idx=1 &&
__git_find_on_cmdline "add list remove" >actual
) &&
test_cmp expect actual
'
test_expect_success '__git_find_on_cmdline - no match' '
(
words=(git command --opt branch) &&
cword=${#words[@]} &&
__git_cmd_idx=1 &&
__git_find_on_cmdline "add list remove" >actual
) &&
test_must_be_empty actual
'
test_expect_success '__git_find_on_cmdline - single match with index' '
echo "3 list" >expect &&
(
words=(git command --opt list) &&
cword=${#words[@]} &&
__git_cmd_idx=1 &&
__git_find_on_cmdline --show-idx "add list remove" >actual
) &&
test_cmp expect actual
'
test_expect_success '__git_find_on_cmdline - multiple matches with index' '
echo "4 remove" >expect &&
(
words=(git command -o --opt remove list add) &&
cword=${#words[@]} &&
__git_cmd_idx=1 &&
__git_find_on_cmdline --show-idx "add list remove" >actual
) &&
test_cmp expect actual
'
test_expect_success '__git_find_on_cmdline - no match with index' '
(
words=(git command --opt branch) &&
cword=${#words[@]} &&
__git_cmd_idx=1 &&
__git_find_on_cmdline --show-idx "add list remove" >actual
) &&
test_must_be_empty actual
'
test_expect_success '__git_find_on_cmdline - ignores matches before command with index' '
echo "6 remove" >expect &&
(
words=(git -C remove command -o --opt remove list add) &&
cword=${#words[@]} &&
__git_cmd_idx=3 &&
__git_find_on_cmdline --show-idx "add list remove" >actual
) &&
test_cmp expect actual
'
test_expect_success '__git_get_config_variables' '
cat >expect <<-EOF &&
name-1
name-2
EOF
test_config interesting.name-1 good &&
test_config interesting.name-2 good &&
test_config subsection.interesting.name-3 bad &&
__git_get_config_variables interesting >actual &&
test_cmp expect actual
'
test_expect_success '__git_pretty_aliases' '
cat >expect <<-EOF &&
author
hash
EOF
test_config pretty.author "%an %ae" &&
test_config pretty.hash %H &&
__git_pretty_aliases >actual &&
test_cmp expect actual
'
test_expect_success 'basic' '
run_completion "git " &&
# built-in
grep -q "^add \$" out &&
# script
grep -q "^rebase \$" out &&
# plumbing
! grep -q "^ls-files \$" out &&
run_completion "git r" &&
! grep -q -v "^r" out
'
test_expect_success 'double dash "git" itself' '
test_completion "git --" <<-\EOF
--paginate Z
--no-pager Z
--git-dir=
--bare Z
--version Z
--exec-path Z
--exec-path=
--html-path Z
--man-path Z
--info-path Z
--work-tree=
--namespace=
--no-replace-objects Z
--help Z
EOF
'
test_expect_success 'double dash "git checkout"' '
test_completion "git checkout --" <<-\EOF
--quiet Z
--detach Z
--track Z
--orphan=Z
--ours Z
--theirs Z
--merge Z
--conflict=Z
--patch Z
--ignore-skip-worktree-bits Z
--ignore-other-worktrees Z
--recurse-submodules Z
--progress Z
--guess Z
--no-guess Z
--no-... Z
--overlay Z
--pathspec-file-nul Z
--pathspec-from-file=Z
EOF
'
test_expect_success 'general options' '
test_completion "git --ver" "--version " &&
test_completion "git --hel" "--help " &&
test_completion "git --exe" <<-\EOF &&
--exec-path Z
--exec-path=
EOF
test_completion "git --htm" "--html-path " &&
test_completion "git --pag" "--paginate " &&
test_completion "git --no-p" "--no-pager " &&
test_completion "git --git" "--git-dir=" &&
test_completion "git --wor" "--work-tree=" &&
test_completion "git --nam" "--namespace=" &&
test_completion "git --bar" "--bare " &&
test_completion "git --inf" "--info-path " &&
test_completion "git --no-r" "--no-replace-objects "
'
test_expect_success 'general options plus command' '
test_completion "git --version check" "checkout " &&
test_completion "git --paginate check" "checkout " &&
test_completion "git --git-dir=foo check" "checkout " &&
test_completion "git --bare check" "checkout " &&
test_completion "git --exec-path=foo check" "checkout " &&
test_completion "git --html-path check" "checkout " &&
test_completion "git --no-pager check" "checkout " &&
test_completion "git --work-tree=foo check" "checkout " &&
test_completion "git --namespace=foo check" "checkout " &&
test_completion "git --paginate check" "checkout " &&
test_completion "git --info-path check" "checkout " &&
test_completion "git --no-replace-objects check" "checkout " &&
test_completion "git --git-dir some/path check" "checkout " &&
test_completion "git -c conf.var=value check" "checkout " &&
test_completion "git -C some/path check" "checkout " &&
test_completion "git --work-tree some/path check" "checkout " &&
test_completion "git --namespace name/space check" "checkout "
'
test_expect_success 'git --help completion' '
test_completion "git --help ad" "add " &&
test_completion "git --help core" "core-tutorial "
'
test_expect_success 'completion.commands removes multiple commands' '
test_config completion.commands "-cherry -mergetool" &&
git --list-cmds=list-mainporcelain,list-complete,config >out &&
! grep -E "^(cherry|mergetool)$" out
'
test_expect_success 'setup for integration tests' '
echo content >file1 &&
echo more >file2 &&
git add file1 file2 &&
git commit -m one &&
git branch mybranch &&
git tag mytag
'
test_expect_success 'checkout completes ref names' '
test_completion "git checkout m" <<-\EOF
main Z
mybranch Z
mytag Z
EOF
'
test_expect_success 'checkout does not match ref names of a different case' '
test_completion "git checkout M" ""
'
test_expect_success 'checkout matches case insensitively with GIT_COMPLETION_IGNORE_CASE' '
(
GIT_COMPLETION_IGNORE_CASE=1 &&
test_completion "git checkout M" <<-\EOF
main Z
mybranch Z
mytag Z
EOF
)
'
test_expect_success 'checkout completes pseudo refs' '
test_completion "git checkout H" <<-\EOF
HEAD Z
EOF
'
test_expect_success 'checkout completes pseudo refs case insensitively with GIT_COMPLETION_IGNORE_CASE' '
(
GIT_COMPLETION_IGNORE_CASE=1 &&
test_completion "git checkout h" <<-\EOF
HEAD Z
EOF
)
'
test_expect_success 'git -C <path> checkout uses the right repo' '
test_completion "git -C subdir -C subsubdir -C .. -C ../otherrepo checkout b" <<-\EOF
branch-in-other Z
EOF
'
test_expect_success 'show completes all refs' '
test_completion "git show m" <<-\EOF
main Z
mybranch Z
mytag Z
EOF
'
test_expect_success '<ref>: completes paths' '
test_completion "git show mytag:f" <<-\EOF
file1Z
file2Z
EOF
'
test_expect_success 'complete tree filename with spaces' '
echo content >"name with spaces" &&
git add "name with spaces" &&
git commit -m spaces &&
test_completion "git show HEAD:nam" <<-\EOF
name with spacesZ
EOF
'
test_expect_success 'complete tree filename with metacharacters' '
echo content >"name with \${meta}" &&
git add "name with \${meta}" &&
git commit -m meta &&
test_completion "git show HEAD:nam" <<-\EOF
name with ${meta}Z
name with spacesZ
EOF
'
test_expect_success 'symbolic-ref completes builtin options' '
test_completion "git symbolic-ref --d" <<-\EOF
--delete Z
EOF
'
test_expect_success 'symbolic-ref completes short ref names' '
test_completion "git symbolic-ref foo m" <<-\EOF
main Z
mybranch Z
mytag Z
EOF
'
test_expect_success 'symbolic-ref completes full ref names' '
test_completion "git symbolic-ref foo refs/" <<-\EOF
refs/heads/main Z
refs/heads/mybranch Z
refs/tags/mytag Z
refs/tags/A Z
EOF
'
test_expect_success PERL 'send-email' '
test_completion "git send-email --cov" <<-\EOF &&
--cover-from-description=Z
--cover-letter Z
EOF
test_completion "git send-email --val" <<-\EOF &&
--validate Z
EOF
test_completion "git send-email ma" "main "
'
test_expect_success 'complete files' '
git init tmp && cd tmp &&
test_when_finished "cd .. && rm -rf tmp" &&
echo "expected" > .gitignore &&
echo "out" >> .gitignore &&
echo "out_sorted" >> .gitignore &&
git add .gitignore &&
test_completion "git commit " ".gitignore" &&
git commit -m ignore &&
touch new &&
test_completion "git add " "new" &&
git add new &&
git commit -a -m new &&
test_completion "git add " "" &&
git mv new modified &&
echo modify > modified &&
test_completion "git add " "modified" &&
mkdir -p some/deep &&
touch some/deep/path &&
test_completion "git add some/" "some/deep" &&
git clean -f some &&
touch untracked &&
: TODO .gitignore should not be here &&
test_completion "git rm " <<-\EOF &&
.gitignore
modified
EOF
test_completion "git clean " "untracked" &&
: TODO .gitignore should not be here &&
test_completion "git mv " <<-\EOF &&
.gitignore
modified
EOF
mkdir dir &&
touch dir/file-in-dir &&
git add dir/file-in-dir &&
git commit -m dir &&
mkdir untracked-dir &&
: TODO .gitignore should not be here &&
test_completion "git mv modified " <<-\EOF &&
.gitignore
dir
modified
untracked
untracked-dir
EOF
test_completion "git commit " "modified" &&
: TODO .gitignore should not be here &&
test_completion "git ls-files " <<-\EOF &&
.gitignore
dir
modified
EOF
touch momified &&
test_completion "git add mom" "momified"
'
test_expect_success "simple alias" '
test_config alias.co checkout &&
test_completion "git co m" <<-\EOF
main Z
mybranch Z
mytag Z
EOF
'
test_expect_success "recursive alias" '
test_config alias.co checkout &&
test_config alias.cod "co --detached" &&
test_completion "git cod m" <<-\EOF
main Z
mybranch Z
mytag Z
EOF
'
test_expect_success "completion uses <cmd> completion for alias: !sh -c 'git <cmd> ...'" '
test_config alias.co "!sh -c '"'"'git checkout ...'"'"'" &&
test_completion "git co m" <<-\EOF
main Z
mybranch Z
mytag Z
EOF
'
test_expect_success 'completion uses <cmd> completion for alias: !f () { VAR=val git <cmd> ... }' '
test_config alias.co "!f () { VAR=val git checkout ... ; } f" &&
test_completion "git co m" <<-\EOF
main Z
mybranch Z
mytag Z
EOF
'
test_expect_success 'completion used <cmd> completion for alias: !f() { : git <cmd> ; ... }' '
test_config alias.co "!f() { : git checkout ; if ... } f" &&
test_completion "git co m" <<-\EOF
main Z
mybranch Z
mytag Z
EOF
'
test_expect_success 'completion used <cmd> completion for alias: !f() { : <cmd> ; ... }' '
test_config alias.co "!f() { : checkout ; if ... } f" &&
test_completion "git co m" <<-\EOF
main Z
mybranch Z
mytag Z
EOF
'
test_expect_success 'completion used <cmd> completion for alias: !f() { : <cmd>; ... }' '
test_config alias.co "!f() { : checkout; if ... } f" &&
test_completion "git co m" <<-\EOF
main Z
mybranch Z
mytag Z
EOF
'
test_expect_success 'completion without explicit _git_xxx function' '
test_completion "git version --" <<-\EOF
--build-options Z
--no-build-options Z
EOF
'
test_expect_failure 'complete with tilde expansion' '
git init tmp && cd tmp &&
test_when_finished "cd .. && rm -rf tmp" &&
touch ~/tmp/file &&
test_completion "git add ~/tmp/" "~/tmp/file"
'
test_expect_success 'setup other remote for remote reference completion' '
git remote add other otherrepo &&
git fetch other
'
for flag in -d --delete
do
test_expect_success "__git_complete_remote_or_refspec - push $flag other" '
sed -e "s/Z$//" >expected <<-EOF &&
main-in-other Z
EOF
(
words=(git push '$flag' other ma) &&
cword=${#words[@]} cur=${words[cword-1]} &&
__git_cmd_idx=1 &&
__git_complete_remote_or_refspec &&
print_comp
) &&
test_cmp expected out
'
test_expect_failure "__git_complete_remote_or_refspec - push other $flag" '
sed -e "s/Z$//" >expected <<-EOF &&
main-in-other Z
EOF
(
words=(git push other '$flag' ma) &&
cword=${#words[@]} cur=${words[cword-1]} &&
__git_cmd_idx=1 &&
__git_complete_remote_or_refspec &&
print_comp
) &&
test_cmp expected out
'
done
test_expect_success 'git config subcommand' '
test_completion "git config " <<-\EOF
edit Z
get Z
list Z
remove-section Z
rename-section Z
set Z
unset Z
EOF
'
test_expect_success 'git config subcommand options' '
test_completion "git config get --show-" <<-\EOF
--show-names Z
--show-origin Z
--show-scope Z
EOF
'
test_expect_success 'git config get' '
test_when_finished "rm -f cfgfile" &&
git config set --file cfgfile foo.bar baz &&
test_completion "git config get --file cfgfile foo." <<-\EOF
foo.bar Z
EOF
'
test_expect_success 'git config set - section' '
test_completion "git config set br" <<-\EOF
branch.Z
browser.Z
EOF
'
test_expect_success 'git config set - section include, includeIf' '
test_completion "git config set inclu" <<-\EOF
include.Z
includeIf.Z
EOF
'
test_expect_success 'git config set - variable name' '
test_completion "git config set log.d" <<-\EOF
log.date Z
log.decorate Z
log.diffMerges Z
EOF
'
test_expect_success 'git config set - variable name include' '
test_completion "git config set include.p" <<-\EOF
include.path Z
EOF
'
test_expect_success 'setup for git config submodule tests' '
test_create_repo sub &&
test_commit -C sub initial &&
git submodule add ./sub
'
test_expect_success 'git config set - variable name - submodule and __git_compute_first_level_config_vars_for_section' '
test_completion "git config set submodule." <<-\EOF
submodule.active Z
submodule.alternateErrorStrategy Z
submodule.alternateLocation Z
submodule.fetchJobs Z
submodule.propagateBranches Z
submodule.recurse Z
submodule.sub.Z
EOF
'
test_expect_success 'git config set - variable name - __git_compute_second_level_config_vars_for_section' '
test_completion "git config set submodule.sub." <<-\EOF
submodule.sub.url Z
submodule.sub.update Z
submodule.sub.branch Z
submodule.sub.fetchRecurseSubmodules Z
submodule.sub.ignore Z
submodule.sub.active Z
EOF
'
test_expect_success 'git config set - value' '
test_completion "git config set color.pager " <<-\EOF
false Z
true Z
EOF
'
test_expect_success 'git -c - section' '
test_completion "git -c br" <<-\EOF
branch.Z
browser.Z
EOF
'
test_expect_success 'git -c - variable name' '
test_completion "git -c log.d" <<-\EOF
log.date=Z
log.decorate=Z
log.diffMerges=Z
EOF
'
test_expect_success 'git -c - value' '
test_completion "git -c color.pager=" <<-\EOF
false Z
true Z
EOF
'
test_expect_success 'git clone --config= - section' '
test_completion "git clone --config=br" <<-\EOF
branch.Z
browser.Z
EOF
'
test_expect_success 'git clone --config= - variable name' '
test_completion "git clone --config=log.d" <<-\EOF
log.date=Z
log.decorate=Z
log.diffMerges=Z
EOF
'
test_expect_success 'git clone --config= - value' '
test_completion "git clone --config=color.pager=" <<-\EOF
false Z
true Z
EOF
'
test_expect_success 'git reflog show' '
test_when_finished "git checkout - && git branch -d shown" &&
git checkout -b shown &&
test_completion "git reflog sho" <<-\EOF &&
show Z
shown Z
EOF
test_completion "git reflog show sho" "shown " &&
test_completion "git reflog shown sho" "shown " &&
test_completion "git reflog --unt" "--until=" &&
test_completion "git reflog show --unt" "--until=" &&
test_completion "git reflog shown --unt" "--until="
'
test_expect_success 'options with value' '
test_completion "git merge -X diff-algorithm=" <<-\EOF
EOF
'
test_expect_success 'sourcing the completion script clears cached commands' '
(
__git_compute_all_commands &&
test -n "$__git_all_commands" &&
. "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
test -z "$__git_all_commands"
)
'
test_expect_success 'sourcing the completion script clears cached merge strategies' '
(
__git_compute_merge_strategies &&
test -n "$__git_merge_strategies" &&
. "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
test -z "$__git_merge_strategies"
)
'
test_expect_success 'sourcing the completion script clears cached --options' '
(
__gitcomp_builtin checkout &&
test -n "$__gitcomp_builtin_checkout" &&
__gitcomp_builtin notes_edit &&
test -n "$__gitcomp_builtin_notes_edit" &&
. "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
test -z "$__gitcomp_builtin_checkout" &&
test -z "$__gitcomp_builtin_notes_edit"
)
'
test_expect_success 'option aliases are not shown by default' '
test_completion "git clone --recurs" "--recurse-submodules "
'
test_expect_success 'option aliases are shown with GIT_COMPLETION_SHOW_ALL' '
(
. "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
GIT_COMPLETION_SHOW_ALL=1 && export GIT_COMPLETION_SHOW_ALL &&
test_completion "git clone --recurs" <<-\EOF
--recurse-submodules Z
--recursive Z
EOF
)
'
test_expect_success 'plumbing commands are excluded without GIT_COMPLETION_SHOW_ALL_COMMANDS' '
(
. "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
sane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&
# Just mainporcelain, not plumbing commands
run_completion "git c" &&
grep checkout out &&
! grep cat-file out
)
'
test_expect_success 'all commands are shown with GIT_COMPLETION_SHOW_ALL_COMMANDS (also main non-builtin)' '
(
. "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
GIT_COMPLETION_SHOW_ALL_COMMANDS=1 &&
export GIT_COMPLETION_SHOW_ALL_COMMANDS &&
sane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&
# Both mainporcelain and plumbing commands
run_completion "git c" &&
grep checkout out &&
grep cat-file out &&
# Check "gitk", a "main" command, but not a built-in + more plumbing
run_completion "git g" &&
grep gitk out &&
grep get-tar-commit-id out
)
'
test_expect_success '__git_complete' '
unset -f __git_wrap__git_main &&
__git_complete foo __git_main &&
__git_have_func __git_wrap__git_main &&
unset -f __git_wrap__git_main &&
__git_complete gf _git_fetch &&
__git_have_func __git_wrap_git_fetch &&
__git_complete foo git &&
__git_have_func __git_wrap__git_main &&
unset -f __git_wrap__git_main &&
__git_complete gd git_diff &&
__git_have_func __git_wrap_git_diff &&
test_must_fail __git_complete ga missing
'
test_expect_success '__git_pseudoref_exists' '
test_when_finished "rm -rf repo" &&
git init repo &&
(
cd repo &&
sane_unset __git_repo_path &&
# HEAD should exist, even if it points to an unborn branch.
__git_pseudoref_exists HEAD >output 2>&1 &&
test_must_be_empty output &&
# HEAD points to an existing branch, so it should exist.
test_commit A &&
__git_pseudoref_exists HEAD >output 2>&1 &&
test_must_be_empty output &&
# CHERRY_PICK_HEAD does not exist, so the existence check should fail.
! __git_pseudoref_exists CHERRY_PICK_HEAD >output 2>&1 &&
test_must_be_empty output &&
# CHERRY_PICK_HEAD points to a commit, so it should exist.
git update-ref CHERRY_PICK_HEAD A &&
__git_pseudoref_exists CHERRY_PICK_HEAD >output 2>&1 &&
test_must_be_empty output
)
'
test_done
|