Merge pull request #2183 from ethomson/merge_refactor Refactor the `git_merge` API
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
diff --git a/include/git2/merge.h b/include/git2/merge.h
index cfec32f..21159d8 100644
--- a/include/git2/merge.h
+++ b/include/git2/merge.h
@@ -23,6 +23,43 @@
GIT_BEGIN_DECL
/**
+ * The file inputs to `git_merge_file`. Callers should populate the
+ * `git_merge_file_input` structure with descriptions of the files in
+ * each side of the conflict for use in producing the merge file.
+ */
+typedef struct {
+ unsigned int version;
+
+ /** Pointer to the contents of the file. */
+ const char *ptr;
+
+ /** Size of the contents pointed to in `ptr`. */
+ size_t size;
+
+ /** File name of the conflicted file, or `NULL` to not merge the path. */
+ const char *path;
+
+ /** File mode of the conflicted file, or `0` to not merge the mode. */
+ unsigned int mode;
+} git_merge_file_input;
+
+#define GIT_MERGE_FILE_INPUT_VERSION 1
+#define GIT_MERGE_FILE_INPUT_INIT {GIT_MERGE_FILE_INPUT_VERSION}
+
+/**
+ * Initializes a `git_merge_file_input` with default values. Equivalent to
+ * creating an instance with GIT_MERGE_FILE_INPUT_INIT.
+ *
+ * @param opts the `git_merge_file_input` instance to initialize.
+ * @param version the version of the struct; you should pass
+ * `GIT_MERGE_FILE_INPUT_VERSION` here.
+ * @return Zero on success; -1 on failure.
+ */
+GIT_EXTERN(int) git_merge_file_init_input(
+ git_merge_file_input *opts,
+ int version);
+
+/**
* Flags for `git_merge_tree` options. A combination of these flags can be
* passed in via the `flags` value in the `git_merge_tree_opts`.
*/
@@ -71,6 +108,86 @@ typedef enum {
GIT_MERGE_FILE_FAVOR_UNION = 3,
} git_merge_file_favor_t;
+typedef enum {
+ /* Defaults */
+ GIT_MERGE_FILE_DEFAULT = 0,
+
+ /* Create standard conflicted merge files */
+ GIT_MERGE_FILE_STYLE_MERGE = (1 << 0),
+
+ /* Create diff3-style files */
+ GIT_MERGE_FILE_STYLE_DIFF3 = (1 << 1),
+
+ /* Condense non-alphanumeric regions for simplified diff file */
+ GIT_MERGE_FILE_SIMPLIFY_ALNUM = (1 << 2),
+} git_merge_file_flags_t;
+
+typedef struct {
+ unsigned int version;
+
+ /**
+ * Label for the ancestor file side of the conflict which will be prepended
+ * to labels in diff3-format merge files.
+ */
+ const char *ancestor_label;
+
+ /**
+ * Label for our file side of the conflict which will be prepended
+ * to labels in merge files.
+ */
+ const char *our_label;
+
+ /**
+ * Label for their file side of the conflict which will be prepended
+ * to labels in merge files.
+ */
+ const char *their_label;
+
+ /** The file to favor in region conflicts. */
+ git_merge_file_favor_t favor;
+
+ /** Merge file flags. */
+ git_merge_file_flags_t flags;
+} git_merge_file_options;
+
+#define GIT_MERGE_FILE_OPTIONS_VERSION 1
+#define GIT_MERGE_FILE_OPTIONS_INIT {GIT_MERGE_FILE_OPTIONS_VERSION}
+
+/**
+ * Initializes a `git_merge_file_options` with default values. Equivalent to
+ * creating an instance with GIT_MERGE_FILE_OPTIONS_INIT.
+ *
+ * @param opts the `git_merge_file_options` instance to initialize.
+ * @param version the version of the struct; you should pass
+ * `GIT_MERGE_FILE_OPTIONS_VERSION` here.
+ * @return Zero on success; -1 on failure.
+ */
+GIT_EXTERN(int) git_merge_file_init_options(
+ git_merge_file_options *opts,
+ int version);
+
+typedef struct {
+ /**
+ * True if the output was automerged, false if the output contains
+ * conflict markers.
+ */
+ unsigned int automergeable;
+
+ /**
+ * The path that the resultant merge file should use, or NULL if a
+ * filename conflict would occur.
+ */
+ char *path;
+
+ /** The mode that the resultant merge file should use. */
+ unsigned int mode;
+
+ /** The contents of the merge. */
+ unsigned char *ptr;
+
+ /** The length of the merge contents. */
+ size_t len;
+} git_merge_file_result;
typedef struct {
unsigned int version;
@@ -99,75 +216,73 @@ typedef struct {
/** Flags for handling conflicting content. */
git_merge_file_favor_t file_favor;
-} git_merge_tree_opts;
+} git_merge_options;
-#define GIT_MERGE_TREE_OPTS_VERSION 1
-#define GIT_MERGE_TREE_OPTS_INIT {GIT_MERGE_TREE_OPTS_VERSION}
+#define GIT_MERGE_OPTIONS_VERSION 1
+#define GIT_MERGE_OPTIONS_INIT {GIT_MERGE_OPTIONS_VERSION}
/**
- * Initializes a `git_merge_tree_opts` with default values. Equivalent to
- * creating an instance with GIT_MERGE_TREE_OPTS_INIT.
+ * Initializes a `git_merge_options` with default values. Equivalent to
+ * creating an instance with GIT_MERGE_OPTIONS_INIT.
*
- * @param opts the `git_merge_tree_opts` instance to initialize.
+ * @param opts the `git_merge_options` instance to initialize.
* @param version the version of the struct; you should pass
- * `GIT_MERGE_TREE_OPTS_VERSION` here.
+ * `GIT_MERGE_OPTIONS_VERSION` here.
* @return Zero on success; -1 on failure.
*/
-GIT_EXTERN(int) git_merge_tree_init_opts(
- git_merge_tree_opts* opts,
+GIT_EXTERN(int) git_merge_init_options(
+ git_merge_options *opts,
int version);
/**
- * Option flags for `git_merge`.
+ * The results of `git_merge_analysis` indicate the merge opportunities.
*/
typedef enum {
+ /** No merge is possible. (Unused.) */
+ GIT_MERGE_ANALYSIS_NONE = 0,
+
/**
- * The default behavior is to allow fast-forwards, returning
- * immediately with the commit ID to fast-forward to.
+ * A "normal" merge; both HEAD and the given merge input have diverged
+ * from their common ancestor. The divergent commits must be merged.
*/
- GIT_MERGE_DEFAULT = 0,
+ GIT_MERGE_ANALYSIS_NORMAL = (1 << 0),
/**
- * Do not fast-forward; perform a merge and prepare a merge result even
- * if the inputs are eligible for fast-forwarding.
+ * All given merge inputs are reachable from HEAD, meaning the
+ * repository is up-to-date and no merge needs to be performed.
*/
- GIT_MERGE_NO_FASTFORWARD = 1,
+ GIT_MERGE_ANALYSIS_UP_TO_DATE = (1 << 1),
/**
- * Ensure that the inputs are eligible for fast-forwarding, error if
- * a merge needs to be performed.
+ * The given merge input is a fast-forward from HEAD and no merge
+ * needs to be performed. Instead, the client can check out the
+ * given merge input.
*/
- GIT_MERGE_FASTFORWARD_ONLY = 2,
-} git_merge_flags_t;
-
-typedef struct {
- unsigned int version;
-
- /** Options for handling the commit-level merge. */
- git_merge_flags_t merge_flags;
-
- /** Options for handling the merges of individual files. */
- git_merge_tree_opts merge_tree_opts;
-
- /** Options for writing the merge result to the working directory. */
- git_checkout_options checkout_opts;
-} git_merge_opts;
+ GIT_MERGE_ANALYSIS_FASTFORWARD = (1 << 2),
-#define GIT_MERGE_OPTS_VERSION 1
-#define GIT_MERGE_OPTS_INIT {GIT_MERGE_OPTS_VERSION, 0, GIT_MERGE_TREE_OPTS_INIT, GIT_CHECKOUT_OPTIONS_INIT}
+ /**
+ * The HEAD of the current repository is "unborn" and does not point to
+ * a valid commit. No merge can be performed, but the caller may wish
+ * to simply set HEAD to the target commit(s).
+ */
+ GIT_MERGE_ANALYSIS_UNBORN = (1 << 3),
+} git_merge_analysis_t;
/**
- * Initializes a `git_merge_opts` with default values. Equivalent to creating
- * an instance with GIT_MERGE_OPTS_INIT.
+ * Analyzes the given branch(es) and determines the opportunities for
+ * merging them into the HEAD of the repository.
*
- * @param opts the `git_merge_opts` instance to initialize.
- * @param version the version of the struct; you should pass
- * `GIT_MERGE_OPTS_VERSION` here.
- * @return Zero on success; -1 on failure.
+ * @param analysis_out analysis enumeration that the result is written into
+ * @param repo the repository to merge
+ * @param their_heads the heads to merge into
+ * @param their_heads_len the number of heads to merge
+ * @return 0 on success or error code
*/
-GIT_EXTERN(int) git_merge_init_opts(
- git_merge_opts* opts,
- int version);
+GIT_EXTERN(int) git_merge_analysis(
+ git_merge_analysis_t *analysis_out,
+ git_repository *repo,
+ const git_merge_head **their_heads,
+ size_t their_heads_len);
/**
* Find a merge base between two commits
@@ -269,6 +384,58 @@ GIT_EXTERN(void) git_merge_head_free(
git_merge_head *head);
/**
+ * Merge two files as they exist in the in-memory data structures, using
+ * the given common ancestor as the baseline, producing a
+ * `git_merge_file_result` that reflects the merge result. The
+ * `git_merge_file_result` must be freed with `git_merge_file_result_free`.
+ *
+ * Note that this function does not reference a repository and any
+ * configuration must be passed as `git_merge_file_options`.
+ *
+ * @param out The git_merge_file_result to be filled in
+ * @param ancestor The contents of the ancestor file
+ * @param ours The contents of the file in "our" side
+ * @param theirs The contents of the file in "their" side
+ * @param opts The merge file options or `NULL` for defaults
+ * @return 0 on success or error code
+ */
+GIT_EXTERN(int) git_merge_file(
+ git_merge_file_result *out,
+ const git_merge_file_input *ancestor,
+ const git_merge_file_input *ours,
+ const git_merge_file_input *theirs,
+ const git_merge_file_options *opts);
+
+/**
+ * Merge two files as they exist in the index, using the given common
+ * ancestor as the baseline, producing a `git_merge_file_result` that
+ * reflects the merge result. The `git_merge_file_result` must be freed with
+ * `git_merge_file_result_free`.
+ *
+ * @param out The git_merge_file_result to be filled in
+ * @param repo The repository
+ * @param ancestor The index entry for the ancestor file (stage level 1)
+ * @param our_path The index entry for our file (stage level 2)
+ * @param their_path The index entry for their file (stage level 3)
+ * @param opts The merge file options or NULL
+ * @return 0 on success or error code
+ */
+GIT_EXTERN(int) git_merge_file_from_index(
+ git_merge_file_result *out,
+ git_repository *repo,
+ const git_index_entry *ancestor,
+ const git_index_entry *ours,
+ const git_index_entry *theirs,
+ const git_merge_file_options *opts);
+
+/**
+ * Frees a `git_merge_file_result`.
+ *
+ * @param result The result to free or `NULL`
+ */
+GIT_EXTERN(void) git_merge_file_result_free(git_merge_file_result *result);
+
+/**
* Merge two trees, producing a `git_index` that reflects the result of
* the merge. The index may be written as-is to the working directory
* or checked out. If the index is to be converted to a tree, the caller
@@ -290,7 +457,7 @@ GIT_EXTERN(int) git_merge_trees(
const git_tree *ancestor_tree,
const git_tree *our_tree,
const git_tree *their_tree,
- const git_merge_tree_opts *opts);
+ const git_merge_options *opts);
/**
* Merge two commits, producing a `git_index` that reflects the result of
@@ -312,81 +479,27 @@ GIT_EXTERN(int) git_merge_commits(
git_repository *repo,
const git_commit *our_commit,
const git_commit *their_commit,
- const git_merge_tree_opts *opts);
+ const git_merge_options *opts);
/**
- * Merges the given commit(s) into HEAD and either returns immediately
- * if there was no merge to perform (the specified commits have already
- * been merged or would produce a fast-forward) or performs the merge
- * and writes the results into the working directory.
- *
- * Callers should inspect the `git_merge_result`:
- *
- * If `git_merge_result_is_uptodate` is true, there is no work to perform.
+ * Merges the given commit(s) into HEAD, writing the results into the working
+ * directory. Any changes are staged for commit and any conflicts are written
+ * to the index. Callers should inspect the repository's index after this
+ * completes, resolve any conflicts and prepare a commit.
*
- * If `git_merge_result_is_fastforward` is true, the caller should update
- * any necessary references to the commit ID returned by
- * `git_merge_result_fastforward_id` and check that out in order to complete
- * the fast-forward.
- *
- * Otherwise, callers should inspect the resulting index, resolve any
- * conflicts and prepare a commit.
- *
- * The resultant `git_merge_result` should be free with
- * `git_merge_result_free`.
- *
- * @param out the results of the merge
* @param repo the repository to merge
* @param merge_heads the heads to merge into
* @param merge_heads_len the number of heads to merge
- * @param opts merge options
+ * @param merge_opts merge options
+ * @param checkout_opts checkout options
* @return 0 on success or error code
*/
GIT_EXTERN(int) git_merge(
- git_merge_result **out,
git_repository *repo,
const git_merge_head **their_heads,
size_t their_heads_len,
- const git_merge_opts *opts);
-
-/**
- * Returns true if a merge is "up-to-date", meaning that the commit(s)
- * that were provided to `git_merge` are already included in `HEAD`
- * and there is no work to do.
- *
- * @return true if the merge is up-to-date, false otherwise
- */
-GIT_EXTERN(int) git_merge_result_is_uptodate(git_merge_result *merge_result);
-
-/**
- * Returns true if a merge is eligible to be "fast-forwarded", meaning that
- * the commit that was provided to `git_merge` need not be merged, it can
- * simply be checked out, because the current `HEAD` is the merge base of
- * itself and the given commit. To perform the fast-forward, the caller
- * should check out the results of `git_merge_result_fastforward_id`.
- *
- * This will never be true if `GIT_MERGE_NO_FASTFORWARD` is supplied as
- * a merge option.
- *
- * @return true if the merge is fast-forwardable, false otherwise
- */
-GIT_EXTERN(int) git_merge_result_is_fastforward(git_merge_result *merge_result);
-
-/**
- * Gets the fast-forward OID if the merge was a fastforward.
- *
- * @param out pointer to populate with the OID of the fast-forward
- * @param merge_result the results of the merge
- * @return 0 on success or error code
- */
-GIT_EXTERN(int) git_merge_result_fastforward_id(git_oid *out, git_merge_result *merge_result);
-
-/**
- * Frees a `git_merge_result`.
- *
- * @param result merge result to free
- */
-GIT_EXTERN(void) git_merge_result_free(git_merge_result *merge_result);
+ const git_merge_options *merge_opts,
+ const git_checkout_options *checkout_opts);
/** @} */
GIT_END_DECL
diff --git a/include/git2/revert.h b/include/git2/revert.h
index 3f48c4e..3a6beb6 100644
--- a/include/git2/revert.h
+++ b/include/git2/revert.h
@@ -26,12 +26,12 @@ typedef struct {
/** For merge commits, the "mainline" is treated as the parent. */
unsigned int mainline;
- git_merge_tree_opts merge_tree_opts;
+ git_merge_options merge_opts;
git_checkout_options checkout_opts;
} git_revert_options;
#define GIT_REVERT_OPTIONS_VERSION 1
-#define GIT_REVERT_OPTIONS_INIT {GIT_REVERT_OPTIONS_VERSION, 0, GIT_MERGE_TREE_OPTS_INIT, GIT_CHECKOUT_OPTIONS_INIT}
+#define GIT_REVERT_OPTIONS_INIT {GIT_REVERT_OPTIONS_VERSION, 0, GIT_MERGE_OPTIONS_INIT, GIT_CHECKOUT_OPTIONS_INIT}
/**
* Initializes a `git_revert_options` with default values. Equivalent to
@@ -66,7 +66,7 @@ int git_revert_commit(
git_commit *revert_commit,
git_commit *our_commit,
unsigned int mainline,
- const git_merge_tree_opts *merge_tree_opts);
+ const git_merge_options *merge_options);
/**
* Reverts the given commit, producing changes in the working directory.
diff --git a/src/checkout.c b/src/checkout.c
index 5dd4ec7..f882f35 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -1681,29 +1681,20 @@ static int checkout_write_merge(
{
git_buf our_label = GIT_BUF_INIT, their_label = GIT_BUF_INIT,
path_suffixed = GIT_BUF_INIT, path_workdir = GIT_BUF_INIT;
- git_merge_file_options merge_file_opts = GIT_MERGE_FILE_OPTIONS_INIT;
- git_merge_file_input ancestor = GIT_MERGE_FILE_INPUT_INIT,
- ours = GIT_MERGE_FILE_INPUT_INIT,
- theirs = GIT_MERGE_FILE_INPUT_INIT;
- git_merge_file_result result = GIT_MERGE_FILE_RESULT_INIT;
+ git_merge_file_options opts = GIT_MERGE_FILE_OPTIONS_INIT;
+ git_merge_file_result result = {0};
git_filebuf output = GIT_FILEBUF_INIT;
int error = 0;
if (data->opts.checkout_strategy & GIT_CHECKOUT_CONFLICT_STYLE_DIFF3)
- merge_file_opts.style = GIT_MERGE_FILE_STYLE_DIFF3;
-
- if ((conflict->ancestor &&
- (error = git_merge_file_input_from_index_entry(
- &ancestor, data->repo, conflict->ancestor)) < 0) ||
- (error = git_merge_file_input_from_index_entry(
- &ours, data->repo, conflict->ours)) < 0 ||
- (error = git_merge_file_input_from_index_entry(
- &theirs, data->repo, conflict->theirs)) < 0)
- goto done;
+ opts.flags |= GIT_MERGE_FILE_STYLE_DIFF3;
- ancestor.label = data->opts.ancestor_label ? data->opts.ancestor_label : "ancestor";
- ours.label = data->opts.our_label ? data->opts.our_label : "ours";
- theirs.label = data->opts.their_label ? data->opts.their_label : "theirs";
+ opts.ancestor_label = data->opts.ancestor_label ?
+ data->opts.ancestor_label : "ancestor";
+ opts.our_label = data->opts.our_label ?
+ data->opts.our_label : "ours";
+ opts.their_label = data->opts.their_label ?
+ data->opts.their_label : "theirs";
/* If all the paths are identical, decorate the diff3 file with the branch
* names. Otherwise, append branch_name:path.
@@ -1712,16 +1703,17 @@ static int checkout_write_merge(
strcmp(conflict->ours->path, conflict->theirs->path) != 0) {
if ((error = conflict_entry_name(
- &our_label, ours.label, conflict->ours->path)) < 0 ||
+ &our_label, opts.our_label, conflict->ours->path)) < 0 ||
(error = conflict_entry_name(
- &their_label, theirs.label, conflict->theirs->path)) < 0)
+ &their_label, opts.their_label, conflict->theirs->path)) < 0)
goto done;
- ours.label = git_buf_cstr(&our_label);
- theirs.label = git_buf_cstr(&their_label);
+ opts.our_label = git_buf_cstr(&our_label);
+ opts.their_label = git_buf_cstr(&their_label);
}
- if ((error = git_merge_files(&result, &ancestor, &ours, &theirs, &merge_file_opts)) < 0)
+ if ((error = git_merge_file_from_index(&result, data->repo,
+ conflict->ancestor, conflict->ours, conflict->theirs, &opts)) < 0)
goto done;
if (result.path == NULL || result.mode == 0) {
@@ -1739,7 +1731,7 @@ static int checkout_write_merge(
if ((error = git_futils_mkpath2file(path_workdir.ptr, 0755)) < 0 ||
(error = git_filebuf_open(&output, path_workdir.ptr, GIT_FILEBUF_DO_NOT_BUFFER, result.mode)) < 0 ||
- (error = git_filebuf_write(&output, result.data, result.len)) < 0 ||
+ (error = git_filebuf_write(&output, result.ptr, result.len)) < 0 ||
(error = git_filebuf_commit(&output)) < 0)
goto done;
@@ -1747,9 +1739,6 @@ done:
git_buf_free(&our_label);
git_buf_free(&their_label);
- git_merge_file_input_free(&ancestor);
- git_merge_file_input_free(&ours);
- git_merge_file_input_free(&theirs);
git_merge_file_result_free(&result);
git_buf_free(&path_workdir);
git_buf_free(&path_suffixed);
diff --git a/src/index.c b/src/index.c
index 0d7d506..ea0815e 100644
--- a/src/index.c
+++ b/src/index.c
@@ -300,7 +300,7 @@ static void index_entry_free(git_index_entry *entry)
git__free(entry);
}
-static unsigned int index_create_mode(unsigned int mode)
+unsigned int git_index__create_mode(unsigned int mode)
{
if (S_ISLNK(mode))
return S_IFLNK;
@@ -320,9 +320,9 @@ static unsigned int index_merge_mode(
if (index->distrust_filemode && S_ISREG(mode))
return (existing && S_ISREG(existing->mode)) ?
- existing->mode : index_create_mode(0666);
+ existing->mode : git_index__create_mode(0666);
- return index_create_mode(mode);
+ return git_index__create_mode(mode);
}
void git_index__set_ignore_case(git_index *index, bool ignore_case)
@@ -619,7 +619,7 @@ void git_index_entry__init_from_stat(
entry->dev = st->st_rdev;
entry->ino = st->st_ino;
entry->mode = (!trust_mode && S_ISREG(st->st_mode)) ?
- index_create_mode(0666) : index_create_mode(st->st_mode);
+ git_index__create_mode(0666) : git_index__create_mode(st->st_mode);
entry->uid = st->st_uid;
entry->gid = st->st_gid;
entry->file_size = st->st_size;
diff --git a/src/index.h b/src/index.h
index f88d110..259a314 100644
--- a/src/index.h
+++ b/src/index.h
@@ -60,4 +60,6 @@ extern int git_index__find(
extern void git_index__set_ignore_case(git_index *index, bool ignore_case);
+extern unsigned int git_index__create_mode(unsigned int mode);
+
#endif
diff --git a/src/merge.c b/src/merge.c
index 66952c0..42fbd79 100644
--- a/src/merge.c
+++ b/src/merge.c
@@ -545,11 +545,9 @@ static int merge_conflict_resolve_automerge(
const git_merge_diff *conflict,
unsigned int merge_file_favor)
{
- git_merge_file_options merge_file_opts = GIT_MERGE_FILE_OPTIONS_INIT;
- git_merge_file_input ancestor = GIT_MERGE_FILE_INPUT_INIT,
- ours = GIT_MERGE_FILE_INPUT_INIT,
- theirs = GIT_MERGE_FILE_INPUT_INIT;
- git_merge_file_result result = GIT_MERGE_FILE_RESULT_INIT;
+ const git_index_entry *ancestor = NULL, *ours = NULL, *theirs = NULL;
+ git_merge_file_options opts = GIT_MERGE_FILE_OPTIONS_INIT;
+ git_merge_file_result result = {0};
git_index_entry *index_entry;
git_odb *odb = NULL;
git_oid automerge_oid;
@@ -559,7 +557,9 @@ static int merge_conflict_resolve_automerge(
*resolved = 0;
- merge_file_opts.favor = merge_file_favor;
+ if (!GIT_MERGE_INDEX_ENTRY_EXISTS(conflict->our_entry) ||
+ !GIT_MERGE_INDEX_ENTRY_EXISTS(conflict->their_entry))
+ return 0;
/* Reject D/F conflicts */
if (conflict->type == GIT_MERGE_DIFF_DIRECTORY_FILE)
@@ -590,13 +590,19 @@ static int merge_conflict_resolve_automerge(
if (conflict->binary)
return 0;
+ ancestor = GIT_MERGE_INDEX_ENTRY_EXISTS(conflict->ancestor_entry) ?
+ &conflict->ancestor_entry : NULL;
+ ours = GIT_MERGE_INDEX_ENTRY_EXISTS(conflict->our_entry) ?
+ &conflict->our_entry : NULL;
+ theirs = GIT_MERGE_INDEX_ENTRY_EXISTS(conflict->their_entry) ?
+ &conflict->their_entry : NULL;
+
+ opts.favor = merge_file_favor;
+
if ((error = git_repository_odb(&odb, diff_list->repo)) < 0 ||
- (error = git_merge_file_input_from_index_entry(&ancestor, diff_list->repo, &conflict->ancestor_entry)) < 0 ||
- (error = git_merge_file_input_from_index_entry(&ours, diff_list->repo, &conflict->our_entry)) < 0 ||
- (error = git_merge_file_input_from_index_entry(&theirs, diff_list->repo, &conflict->their_entry)) < 0 ||
- (error = git_merge_files(&result, &ancestor, &ours, &theirs, &merge_file_opts)) < 0 ||
+ (error = git_merge_file_from_index(&result, diff_list->repo, ancestor, ours, theirs, &opts)) < 0 ||
!result.automergeable ||
- (error = git_odb_write(&automerge_oid, odb, result.data, result.len, GIT_OBJ_BLOB)) < 0)
+ (error = git_odb_write(&automerge_oid, odb, result.ptr, result.len, GIT_OBJ_BLOB)) < 0)
goto done;
if ((index_entry = git_pool_malloc(&diff_list->pool, sizeof(git_index_entry))) == NULL)
@@ -615,9 +621,6 @@ static int merge_conflict_resolve_automerge(
*resolved = 1;
done:
- git_merge_file_input_free(&ancestor);
- git_merge_file_input_free(&ours);
- git_merge_file_input_free(&theirs);
git_merge_file_result_free(&result);
git_odb_free(odb);
@@ -667,7 +670,7 @@ static int index_entry_similarity_exact(
git_index_entry *b,
size_t b_idx,
void **cache,
- const git_merge_tree_opts *opts)
+ const git_merge_options *opts)
{
GIT_UNUSED(repo);
GIT_UNUSED(a_idx);
@@ -685,7 +688,7 @@ static int index_entry_similarity_calc(
void **out,
git_repository *repo,
git_index_entry *entry,
- const git_merge_tree_opts *opts)
+ const git_merge_options *opts)
{
git_blob *blob;
git_diff_file diff_file = {{{0}}};
@@ -725,7 +728,7 @@ static int index_entry_similarity_inexact(
git_index_entry *b,
size_t b_idx,
void **cache,
- const git_merge_tree_opts *opts)
+ const git_merge_options *opts)
{
int score = 0;
int error = 0;
@@ -762,9 +765,9 @@ static int merge_diff_mark_similarity(
git_merge_diff_list *diff_list,
struct merge_diff_similarity *similarity_ours,
struct merge_diff_similarity *similarity_theirs,
- int (*similarity_fn)(git_repository *, git_index_entry *, size_t, git_index_entry *, size_t, void **, const git_merge_tree_opts *),
+ int (*similarity_fn)(git_repository *, git_index_entry *, size_t, git_index_entry *, size_t, void **, const git_merge_options *),
void **cache,
- const git_merge_tree_opts *opts)
+ const git_merge_options *opts)
{
size_t i, j;
git_merge_diff *conflict_src, *conflict_tgt;
@@ -865,7 +868,7 @@ static void merge_diff_mark_rename_conflict(
bool theirs_renamed,
size_t theirs_source_idx,
git_merge_diff *target,
- const git_merge_tree_opts *opts)
+ const git_merge_options *opts)
{
git_merge_diff *ours_source = NULL, *theirs_source = NULL;
@@ -935,7 +938,7 @@ static void merge_diff_list_coalesce_renames(
git_merge_diff_list *diff_list,
struct merge_diff_similarity *similarity_ours,
struct merge_diff_similarity *similarity_theirs,
- const git_merge_tree_opts *opts)
+ const git_merge_options *opts)
{
size_t i;
bool ours_renamed = 0, theirs_renamed = 0;
@@ -1025,7 +1028,7 @@ static void merge_diff_list_count_candidates(
int git_merge_diff_list__find_renames(
git_repository *repo,
git_merge_diff_list *diff_list,
- const git_merge_tree_opts *opts)
+ const git_merge_options *opts)
{
struct merge_diff_similarity *similarity_ours, *similarity_theirs;
void **cache = NULL;
@@ -1453,10 +1456,10 @@ void git_merge_diff_list__free(git_merge_diff_list *diff_list)
git__free(diff_list);
}
-static int merge_tree_normalize_opts(
+static int merge_normalize_opts(
git_repository *repo,
- git_merge_tree_opts *opts,
- const git_merge_tree_opts *given)
+ git_merge_options *opts,
+ const git_merge_options *given)
{
git_config *cfg = NULL;
int error = 0;
@@ -1467,9 +1470,9 @@ static int merge_tree_normalize_opts(
return error;
if (given != NULL)
- memcpy(opts, given, sizeof(git_merge_tree_opts));
+ memcpy(opts, given, sizeof(git_merge_options));
else {
- git_merge_tree_opts init = GIT_MERGE_TREE_OPTS_INIT;
+ git_merge_options init = GIT_MERGE_OPTIONS_INIT;
memcpy(opts, &init, sizeof(init));
opts->flags = GIT_MERGE_TREE_FIND_RENAMES;
@@ -1637,10 +1640,10 @@ int git_merge_trees(
const git_tree *ancestor_tree,
const git_tree *our_tree,
const git_tree *their_tree,
- const git_merge_tree_opts *given_opts)
+ const git_merge_options *given_opts)
{
git_merge_diff_list *diff_list;
- git_merge_tree_opts opts;
+ git_merge_options opts;
git_merge_diff *conflict;
git_vector changes;
size_t i;
@@ -1650,9 +1653,9 @@ int git_merge_trees(
*out = NULL;
- GITERR_CHECK_VERSION(given_opts, GIT_MERGE_TREE_OPTS_VERSION, "git_merge_tree_opts");
+ GITERR_CHECK_VERSION(given_opts, GIT_MERGE_OPTIONS_VERSION, "git_merge_options");
- if ((error = merge_tree_normalize_opts(repo, &opts, given_opts)) < 0)
+ if ((error = merge_normalize_opts(repo, &opts, given_opts)) < 0)
return error;
diff_list = git_merge_diff_list__alloc(repo);
@@ -1691,7 +1694,7 @@ int git_merge_commits(
git_repository *repo,
const git_commit *our_commit,
const git_commit *their_commit,
- const git_merge_tree_opts *opts)
+ const git_merge_options *opts)
{
git_oid ancestor_oid;
git_commit *ancestor_commit = NULL;
@@ -1777,31 +1780,20 @@ cleanup:
return error;
}
-static int write_merge_mode(git_repository *repo, unsigned int flags)
+static int write_merge_mode(git_repository *repo)
{
git_filebuf file = GIT_FILEBUF_INIT;
git_buf file_path = GIT_BUF_INIT;
int error = 0;
- /* For future expansion */
- GIT_UNUSED(flags);
-
assert(repo);
if ((error = git_buf_joinpath(&file_path, repo->path_repository, GIT_MERGE_MODE_FILE)) < 0 ||
(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_FORCE, GIT_MERGE_FILE_MODE)) < 0)
goto cleanup;
- /*
- * no-ff is the only thing allowed here at present. One would
- * presume they would be space-delimited when there are more, but
- * this needs to be revisited.
- */
-
- if (flags & GIT_MERGE_NO_FASTFORWARD) {
- if ((error = git_filebuf_write(&file, "no-ff", 5)) < 0)
- goto cleanup;
- }
+ if ((error = git_filebuf_write(&file, "no-ff", 5)) < 0)
+ goto cleanup;
error = git_filebuf_commit(&file);
@@ -2117,6 +2109,25 @@ cleanup:
return error;
}
+int git_merge__setup(
+ git_repository *repo,
+ const git_merge_head *our_head,
+ const git_merge_head *heads[],
+ size_t heads_len)
+{
+ int error = 0;
+
+ assert (repo && our_head && heads);
+
+ if ((error = write_orig_head(repo, our_head)) == 0 &&
+ (error = write_merge_head(repo, heads, heads_len)) == 0 &&
+ (error = write_merge_mode(repo)) == 0) {
+ error = write_merge_msg(repo, heads, heads_len);
+ }
+
+ return error;
+}
+
/* Merge branches */
static int merge_ancestor_head(
@@ -2150,37 +2161,6 @@ on_error:
return error;
}
-GIT_INLINE(bool) merge_check_uptodate(
- git_merge_result *result,
- const git_merge_head *ancestor_head,
- const git_merge_head *their_head)
-{
- if (git_oid_cmp(&ancestor_head->oid, &their_head->oid) == 0) {
- result->is_uptodate = 1;
- return true;
- }
-
- return false;
-}
-
-GIT_INLINE(bool) merge_check_fastforward(
- git_merge_result *result,
- const git_merge_head *ancestor_head,
- const git_merge_head *our_head,
- const git_merge_head *their_head,
- unsigned int flags)
-{
- if ((flags & GIT_MERGE_NO_FASTFORWARD) == 0 &&
- git_oid_cmp(&ancestor_head->oid, &our_head->oid) == 0) {
- result->is_fastforward = 1;
- git_oid_cpy(&result->fastforward_oid, &their_head->oid);
-
- return true;
- }
-
- return false;
-}
-
const char *merge_their_label(const char *branchname)
{
const char *slash;
@@ -2194,10 +2174,10 @@ const char *merge_their_label(const char *branchname)
return slash+1;
}
-static int merge_normalize_opts(
+static int merge_normalize_checkout_opts(
git_repository *repo,
- git_merge_opts *opts,
- const git_merge_opts *given,
+ git_checkout_options *checkout_opts,
+ const git_checkout_options *given_checkout_opts,
const git_merge_head *ancestor_head,
const git_merge_head *our_head,
size_t their_heads_len,
@@ -2209,38 +2189,38 @@ static int merge_normalize_opts(
GIT_UNUSED(repo);
- if (given != NULL)
- memcpy(opts, given, sizeof(git_merge_opts));
+ if (given_checkout_opts != NULL)
+ memcpy(checkout_opts, given_checkout_opts, sizeof(git_checkout_options));
else {
- git_merge_opts default_opts = GIT_MERGE_OPTS_INIT;
- memcpy(opts, &default_opts, sizeof(git_merge_opts));
+ git_checkout_options default_checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
+ memcpy(checkout_opts, &default_checkout_opts, sizeof(git_checkout_options));
}
- if (!opts->checkout_opts.checkout_strategy)
- opts->checkout_opts.checkout_strategy = default_checkout_strategy;
+ if (!checkout_opts->checkout_strategy)
+ checkout_opts->checkout_strategy = default_checkout_strategy;
/* TODO: for multiple ancestors in merge-recursive, this is "merged common ancestors" */
- if (!opts->checkout_opts.ancestor_label) {
+ if (!checkout_opts->ancestor_label) {
if (ancestor_head && ancestor_head->commit)
- opts->checkout_opts.ancestor_label = git_commit_summary(ancestor_head->commit);
+ checkout_opts->ancestor_label = git_commit_summary(ancestor_head->commit);
else
- opts->checkout_opts.ancestor_label = "ancestor";
+ checkout_opts->ancestor_label = "ancestor";
}
- if (!opts->checkout_opts.our_label) {
+ if (!checkout_opts->our_label) {
if (our_head && our_head->ref_name)
- opts->checkout_opts.our_label = our_head->ref_name;
+ checkout_opts->our_label = our_head->ref_name;
else
- opts->checkout_opts.our_label = "ours";
+ checkout_opts->our_label = "ours";
}
- if (!opts->checkout_opts.their_label) {
+ if (!checkout_opts->their_label) {
if (their_heads_len == 1 && their_heads[0]->ref_name)
- opts->checkout_opts.their_label = merge_their_label(their_heads[0]->ref_name);
+ checkout_opts->their_label = merge_their_label(their_heads[0]->ref_name);
else if (their_heads_len == 1)
- opts->checkout_opts.their_label = their_heads[0]->oid_str;
+ checkout_opts->their_label = their_heads[0]->oid_str;
else
- opts->checkout_opts.their_label = "theirs";
+ checkout_opts->their_label = "theirs";
}
return error;
@@ -2500,71 +2480,128 @@ static int merge_state_cleanup(git_repository *repo)
return git_repository__cleanup_files(repo, state_files, ARRAY_SIZE(state_files));
}
-int git_merge(
- git_merge_result **out,
+static int merge_heads(
+ git_merge_head **ancestor_head_out,
+ git_merge_head **our_head_out,
git_repository *repo,
const git_merge_head **their_heads,
- size_t their_heads_len,
- const git_merge_opts *given_opts)
+ size_t their_heads_len)
{
- git_merge_result *result;
- git_merge_opts opts;
+ git_merge_head *ancestor_head = NULL, *our_head = NULL;
git_reference *our_ref = NULL;
+ int error = 0;
+
+ *ancestor_head_out = NULL;
+ *our_head_out = NULL;
+
+ if ((error = git_repository__ensure_not_bare(repo, "merge")) < 0)
+ goto done;
+
+ if ((error = git_reference_lookup(&our_ref, repo, GIT_HEAD_FILE)) < 0 ||
+ (error = git_merge_head_from_ref(&our_head, repo, our_ref)) < 0)
+ goto done;
+
+ if ((error = merge_ancestor_head(&ancestor_head, repo, our_head, their_heads, their_heads_len)) < 0) {
+ if (error != GIT_ENOTFOUND)
+ goto done;
+
+ giterr_clear();
+ error = 0;
+ }
+
+ *ancestor_head_out = ancestor_head;
+ *our_head_out = our_head;
+
+done:
+ if (error < 0) {
+ git_merge_head_free(ancestor_head);
+ git_merge_head_free(our_head);
+ }
+
+ git_reference_free(our_ref);
+
+ return error;
+}
+
+int git_merge_analysis(
+ git_merge_analysis_t *out,
+ git_repository *repo,
+ const git_merge_head **their_heads,
+ size_t their_heads_len)
+{
git_merge_head *ancestor_head = NULL, *our_head = NULL;
- git_tree *ancestor_tree = NULL, *our_tree = NULL, **their_trees = NULL;
- git_index *index_new = NULL, *index_repo = NULL;
- size_t i;
int error = 0;
assert(out && repo && their_heads);
- *out = NULL;
+ *out = GIT_MERGE_ANALYSIS_NONE;
- GITERR_CHECK_VERSION(given_opts, GIT_MERGE_OPTS_VERSION, "git_merge_opts");
+ if (git_repository_head_unborn(repo)) {
+ *out = GIT_MERGE_ANALYSIS_FASTFORWARD | GIT_MERGE_ANALYSIS_UNBORN;
+ goto done;
+ }
if (their_heads_len != 1) {
giterr_set(GITERR_MERGE, "Can only merge a single branch");
- return -1;
+ error = -1;
+ goto done;
}
- result = git__calloc(1, sizeof(git_merge_result));
- GITERR_CHECK_ALLOC(result);
+ if ((error = merge_heads(&ancestor_head, &our_head, repo, their_heads, their_heads_len)) < 0)
+ goto done;
- their_trees = git__calloc(their_heads_len, sizeof(git_tree *));
- GITERR_CHECK_ALLOC(their_trees);
+ /* We're up-to-date if we're trying to merge our own common ancestor. */
+ if (ancestor_head && git_oid_equal(&ancestor_head->oid, &their_heads[0]->oid))
+ *out = GIT_MERGE_ANALYSIS_UP_TO_DATE;
- if ((error = git_repository__ensure_not_bare(repo, "merge")) < 0)
- goto on_error;
+ /* We're fastforwardable if we're our own common ancestor. */
+ else if (ancestor_head && git_oid_equal(&ancestor_head->oid, &our_head->oid))
+ *out = GIT_MERGE_ANALYSIS_FASTFORWARD | GIT_MERGE_ANALYSIS_NORMAL;
- if ((error = git_reference_lookup(&our_ref, repo, GIT_HEAD_FILE)) < 0 ||
- (error = git_merge_head_from_ref(&our_head, repo, our_ref)) < 0)
- goto on_error;
+ /* Otherwise, just a normal merge is possible. */
+ else
+ *out = GIT_MERGE_ANALYSIS_NORMAL;
- if ((error = merge_ancestor_head(&ancestor_head, repo, our_head, their_heads, their_heads_len)) < 0 &&
- error != GIT_ENOTFOUND)
- goto on_error;
+done:
+ git_merge_head_free(ancestor_head);
+ git_merge_head_free(our_head);
+ return error;
+}
- if ((error = merge_normalize_opts(repo, &opts, given_opts, ancestor_head, our_head, their_heads_len, their_heads)) < 0)
- goto on_error;
+int git_merge(
+ git_repository *repo,
+ const git_merge_head **their_heads,
+ size_t their_heads_len,
+ const git_merge_options *merge_opts,
+ const git_checkout_options *given_checkout_opts)
+{
+ git_reference *our_ref = NULL;
+ git_checkout_options checkout_opts;
+ git_merge_head *ancestor_head = NULL, *our_head = NULL;
+ git_tree *ancestor_tree = NULL, *our_tree = NULL, **their_trees = NULL;
+ git_index *index_new = NULL, *index_repo = NULL;
+ size_t i;
+ int error = 0;
- if (their_heads_len == 1 &&
- ancestor_head != NULL &&
- (merge_check_uptodate(result, ancestor_head, their_heads[0]) ||
- merge_check_fastforward(result, ancestor_head, our_head, their_heads[0], opts.merge_flags))) {
- *out = result;
- goto done;
+ assert(repo && their_heads);
+
+ if (their_heads_len != 1) {
+ giterr_set(GITERR_MERGE, "Can only merge a single branch");
+ return -1;
}
- /* If FASTFORWARD_ONLY is specified, fail. */
- if ((opts.merge_flags & GIT_MERGE_FASTFORWARD_ONLY) ==
- GIT_MERGE_FASTFORWARD_ONLY) {
- giterr_set(GITERR_MERGE, "Not a fast-forward.");
- error = GIT_ENONFASTFORWARD;
+ their_trees = git__calloc(their_heads_len, sizeof(git_tree *));
+ GITERR_CHECK_ALLOC(their_trees);
+
+ if ((error = merge_heads(&ancestor_head, &our_head, repo, their_heads, their_heads_len)) < 0)
+ goto on_error;
+
+ if ((error = merge_normalize_checkout_opts(repo, &checkout_opts, given_checkout_opts,
+ ancestor_head, our_head, their_heads_len, their_heads)) < 0)
goto on_error;
- }
/* Write the merge files to the repository. */
- if ((error = git_merge__setup(repo, our_head, their_heads, their_heads_len, opts.merge_flags)) < 0)
+ if ((error = git_merge__setup(repo, our_head, their_heads, their_heads_len)) < 0)
goto on_error;
if (ancestor_head != NULL &&
@@ -2581,22 +2618,18 @@ int git_merge(
/* TODO: recursive, octopus, etc... */
- if ((error = git_merge_trees(&index_new, repo, ancestor_tree, our_tree, their_trees[0], &opts.merge_tree_opts)) < 0 ||
+ if ((error = git_merge_trees(&index_new, repo, ancestor_tree, our_tree, their_trees[0], merge_opts)) < 0 ||
(error = git_merge__indexes(repo, index_new)) < 0 ||
(error = git_repository_index(&index_repo, repo)) < 0 ||
- (error = git_checkout_index(repo, index_repo, &opts.checkout_opts)) < 0)
+ (error = git_checkout_index(repo, index_repo, &checkout_opts)) < 0)
goto on_error;
- result->index = index_new;
-
- *out = result;
goto done;
on_error:
merge_state_cleanup(repo);
git_index_free(index_new);
- git__free(result);
done:
git_index_free(index_repo);
@@ -2617,61 +2650,6 @@ done:
return error;
}
-int git_merge__setup(
- git_repository *repo,
- const git_merge_head *our_head,
- const git_merge_head *heads[],
- size_t heads_len,
- unsigned int flags)
-{
- int error = 0;
-
- assert (repo && our_head && heads);
-
- if ((error = write_orig_head(repo, our_head)) == 0 &&
- (error = write_merge_head(repo, heads, heads_len)) == 0 &&
- (error = write_merge_mode(repo, flags)) == 0) {
- error = write_merge_msg(repo, heads, heads_len);
- }
-
- return error;
-}
-
-/* Merge result data */
-
-int git_merge_result_is_uptodate(git_merge_result *merge_result)
-{
- assert(merge_result);
-
- return merge_result->is_uptodate;
-}
-
-int git_merge_result_is_fastforward(git_merge_result *merge_result)
-{
- assert(merge_result);
-
- return merge_result->is_fastforward;
-}
-
-int git_merge_result_fastforward_id(git_oid *out, git_merge_result *merge_result)
-{
- assert(out && merge_result);
-
- git_oid_cpy(out, &merge_result->fastforward_oid);
- return 0;
-}
-
-void git_merge_result_free(git_merge_result *merge_result)
-{
- if (merge_result == NULL)
- return;
-
- git_index_free(merge_result->index);
- merge_result->index = NULL;
-
- git__free(merge_result);
-}
-
/* Merge heads are the input to merge */
static int merge_head_init(
@@ -2776,25 +2754,37 @@ void git_merge_head_free(git_merge_head *head)
git__free(head);
}
-int git_merge_init_opts(git_merge_opts* opts, int version)
+int git_merge_init_options(git_merge_options *opts, int version)
{
- if (version != GIT_MERGE_OPTS_VERSION) {
- giterr_set(GITERR_INVALID, "Invalid version %d for git_merge_opts", version);
+ if (version != GIT_MERGE_OPTIONS_VERSION) {
+ giterr_set(GITERR_INVALID, "Invalid version %d for git_merge_options", version);
return -1;
} else {
- git_merge_opts o = GIT_MERGE_OPTS_INIT;
- memcpy(opts, &o, sizeof(o));
+ git_merge_options default_opts = GIT_MERGE_OPTIONS_INIT;
+ memcpy(opts, &default_opts, sizeof(git_merge_options));
+ return 0;
+ }
+}
+
+int git_merge_file_init_input(git_merge_file_input *input, int version)
+{
+ if (version != GIT_MERGE_FILE_INPUT_VERSION) {
+ giterr_set(GITERR_INVALID, "Invalid version %d for git_merge_file_input", version);
+ return -1;
+ } else {
+ git_merge_file_input i = GIT_MERGE_FILE_INPUT_INIT;
+ memcpy(input, &i, sizeof(i));
return 0;
}
}
-int git_merge_tree_init_opts(git_merge_tree_opts* opts, int version)
+int git_merge_file_init_options(git_merge_file_options *opts, int version)
{
- if (version != GIT_MERGE_TREE_OPTS_VERSION) {
- giterr_set(GITERR_INVALID, "Invalid version %d for git_merge_tree_opts", version);
+ if (version != GIT_MERGE_FILE_OPTIONS_VERSION) {
+ giterr_set(GITERR_INVALID, "Invalid version %d for git_merge_file_options", version);
return -1;
} else {
- git_merge_tree_opts o = GIT_MERGE_TREE_OPTS_INIT;
+ git_merge_file_options o = GIT_MERGE_FILE_OPTIONS_INIT;
memcpy(opts, &o, sizeof(o));
return 0;
}
diff --git a/src/merge.h b/src/merge.h
index dda0235..2362da0 100644
--- a/src/merge.h
+++ b/src/merge.h
@@ -120,16 +120,6 @@ struct git_merge_head {
git_commit *commit;
};
-/** Internal structure for merge results */
-struct git_merge_result {
- bool is_uptodate;
-
- bool is_fastforward;
- git_oid fastforward_oid;
-
- git_index *index;
-};
-
int git_merge__bases_many(
git_commit_list **out,
git_revwalk *walk,
@@ -147,7 +137,7 @@ int git_merge_diff_list__find_differences(git_merge_diff_list *merge_diff_list,
const git_tree *ours_tree,
const git_tree *theirs_tree);
-int git_merge_diff_list__find_renames(git_repository *repo, git_merge_diff_list *merge_diff_list, const git_merge_tree_opts *opts);
+int git_merge_diff_list__find_renames(git_repository *repo, git_merge_diff_list *merge_diff_list, const git_merge_options *opts);
void git_merge_diff_list__free(git_merge_diff_list *diff_list);
@@ -156,9 +146,8 @@ void git_merge_diff_list__free(git_merge_diff_list *diff_list);
int git_merge__setup(
git_repository *repo,
const git_merge_head *our_head,
- const git_merge_head *their_heads[],
- size_t their_heads_len,
- unsigned int flags);
+ const git_merge_head *heads[],
+ size_t heads_len);
int git_merge__indexes(git_repository *repo, git_index *index_new);
diff --git a/src/merge_file.c b/src/merge_file.c
index 986fbf9..fc45cbf 100644
--- a/src/merge_file.c
+++ b/src/merge_file.c
@@ -8,6 +8,9 @@
#include "common.h"
#include "repository.h"
#include "merge_file.h"
+#include "posix.h"
+#include "fileops.h"
+#include "index.h"
#include "git2/repository.h"
#include "git2/object.h"
@@ -22,17 +25,17 @@ GIT_INLINE(const char *) merge_file_best_path(
const git_merge_file_input *ours,
const git_merge_file_input *theirs)
{
- if (!GIT_MERGE_FILE_SIDE_EXISTS(ancestor)) {
- if (strcmp(ours->path, theirs->path) == 0)
+ if (!ancestor) {
+ if (ours && theirs && strcmp(ours->path, theirs->path) == 0)
return ours->path;
return NULL;
}
- if (strcmp(ancestor->path, ours->path) == 0)
- return theirs->path;
- else if(strcmp(ancestor->path, theirs->path) == 0)
- return ours->path;
+ if (ours && strcmp(ancestor->path, ours->path) == 0)
+ return theirs ? theirs->path : NULL;
+ else if(theirs && strcmp(ancestor->path, theirs->path) == 0)
+ return ours ? ours->path : NULL;
return NULL;
}
@@ -47,136 +50,230 @@ GIT_INLINE(int) merge_file_best_mode(
* assume executable. Otherwise, if any mode changed from the ancestor,
* use that one.
*/
- if (!GIT_MERGE_FILE_SIDE_EXISTS(ancestor)) {
- if (ours->mode == GIT_FILEMODE_BLOB_EXECUTABLE ||
- theirs->mode == GIT_FILEMODE_BLOB_EXECUTABLE)
+ if (!ancestor) {
+ if ((ours && ours->mode == GIT_FILEMODE_BLOB_EXECUTABLE) ||
+ (theirs && theirs->mode == GIT_FILEMODE_BLOB_EXECUTABLE))
return GIT_FILEMODE_BLOB_EXECUTABLE;
return GIT_FILEMODE_BLOB;
- }
+ } else if (ours && theirs) {
+ if (ancestor->mode == ours->mode)
+ return theirs->mode;
- if (ancestor->mode == ours->mode)
- return theirs->mode;
- else if(ancestor->mode == theirs->mode)
return ours->mode;
+ }
return 0;
}
-int git_merge_file_input_from_index_entry(
- git_merge_file_input *input,
- git_repository *repo,
+int git_merge_file__input_from_index(
+ git_merge_file_input *input_out,
+ git_odb_object **odb_object_out,
+ git_odb *odb,
const git_index_entry *entry)
{
- git_odb *odb = NULL;
int error = 0;
- assert(input && repo && entry);
-
- if (entry->mode == 0)
- return 0;
+ assert(input_out && odb_object_out && odb && entry);
- if ((error = git_repository_odb(&odb, repo)) < 0 ||
- (error = git_odb_read(&input->odb_object, odb, &entry->id)) < 0)
+ if ((error = git_odb_read(odb_object_out, odb, &entry->id)) < 0)
goto done;
- input->mode = entry->mode;
- input->path = git__strdup(entry->path);
- input->mmfile.size = git_odb_object_size(input->odb_object);
- input->mmfile.ptr = (char *)git_odb_object_data(input->odb_object);
-
- if (input->label == NULL)
- input->label = entry->path;
+ input_out->path = entry->path;
+ input_out->mode = entry->mode;
+ input_out->ptr = (char *)git_odb_object_data(*odb_object_out);
+ input_out->size = git_odb_object_size(*odb_object_out);
done:
- git_odb_free(odb);
-
return error;
}
-int git_merge_file_input_from_diff_file(
- git_merge_file_input *input,
- git_repository *repo,
- const git_diff_file *file)
+static void merge_file_normalize_opts(
+ git_merge_file_options *out,
+ const git_merge_file_options *given_opts)
{
- git_odb *odb = NULL;
- int error = 0;
-
- assert(input && repo && file);
-
- if (file->mode == 0)
- return 0;
-
- if ((error = git_repository_odb(&odb, repo)) < 0 ||
- (error = git_odb_read(&input->odb_object, odb, &file->id)) < 0)
- goto done;
-
- input->mode = file->mode;
- input->path = git__strdup(file->path);
- input->mmfile.size = git_odb_object_size(input->odb_object);
- input->mmfile.ptr = (char *)git_odb_object_data(input->odb_object);
-
- if (input->label == NULL)
- input->label = file->path;
-
-done:
- git_odb_free(odb);
-
- return error;
+ if (given_opts)
+ memcpy(out, given_opts, sizeof(git_merge_file_options));
+ else {
+ git_merge_file_options default_opts = GIT_MERGE_FILE_OPTIONS_INIT;
+ memcpy(out, &default_opts, sizeof(git_merge_file_options));
+ }
}
-int git_merge_files(
+static int git_merge_file__from_inputs(
git_merge_file_result *out,
- git_merge_file_input *ancestor,
- git_merge_file_input *ours,
- git_merge_file_input *theirs,
- git_merge_file_options *opts)
+ const git_merge_file_input *ancestor,
+ const git_merge_file_input *ours,
+ const git_merge_file_input *theirs,
+ const git_merge_file_options *given_opts)
{
xmparam_t xmparam;
+ mmfile_t ancestor_mmfile = {0}, our_mmfile = {0}, their_mmfile = {0};
mmbuffer_t mmbuffer;
+ git_merge_file_options options = GIT_MERGE_FILE_OPTIONS_INIT;
+ const char *path;
int xdl_result;
int error = 0;
- assert(out && ancestor && ours && theirs);
-
memset(out, 0x0, sizeof(git_merge_file_result));
- if (!GIT_MERGE_FILE_SIDE_EXISTS(ours) || !GIT_MERGE_FILE_SIDE_EXISTS(theirs))
- return 0;
+ merge_file_normalize_opts(&options, given_opts);
memset(&xmparam, 0x0, sizeof(xmparam_t));
- xmparam.ancestor = ancestor->label;
- xmparam.file1 = ours->label;
- xmparam.file2 = theirs->label;
- out->path = merge_file_best_path(ancestor, ours, theirs);
- out->mode = merge_file_best_mode(ancestor, ours, theirs);
+ if (ancestor) {
+ xmparam.ancestor = (options.ancestor_label) ?
+ options.ancestor_label : ancestor->path;
+ ancestor_mmfile.ptr = (char *)ancestor->ptr;
+ ancestor_mmfile.size = ancestor->size;
+ }
- if (opts && opts->favor == GIT_MERGE_FILE_FAVOR_OURS)
+ xmparam.file1 = (options.our_label) ?
+ options.our_label : ours->path;
+ our_mmfile.ptr = (char *)ours->ptr;
+ our_mmfile.size = ours->size;
+
+ xmparam.file2 = (options.their_label) ?
+ options.their_label : theirs->path;
+ their_mmfile.ptr = (char *)theirs->ptr;
+ their_mmfile.size = theirs->size;
+
+ if (options.favor == GIT_MERGE_FILE_FAVOR_OURS)
xmparam.favor = XDL_MERGE_FAVOR_OURS;
- else if (opts && opts->favor == GIT_MERGE_FILE_FAVOR_THEIRS)
+ else if (options.favor == GIT_MERGE_FILE_FAVOR_THEIRS)
xmparam.favor = XDL_MERGE_FAVOR_THEIRS;
- else if (opts && opts->favor == GIT_MERGE_FILE_FAVOR_UNION)
+ else if (options.favor == GIT_MERGE_FILE_FAVOR_UNION)
xmparam.favor = XDL_MERGE_FAVOR_UNION;
- xmparam.level =
- (opts && (opts->flags & GIT_MERGE_FILE_SIMPLIFY_ALNUM)) ?
+ xmparam.level = (options.flags & GIT_MERGE_FILE_SIMPLIFY_ALNUM) ?
XDL_MERGE_ZEALOUS_ALNUM : XDL_MERGE_ZEALOUS;
- if (opts && opts->style == GIT_MERGE_FILE_STYLE_DIFF3)
+ if (options.flags & GIT_MERGE_FILE_STYLE_DIFF3)
xmparam.style = XDL_MERGE_DIFF3;
- if ((xdl_result = xdl_merge(&ancestor->mmfile, &ours->mmfile,
- &theirs->mmfile, &xmparam, &mmbuffer)) < 0) {
+ if ((xdl_result = xdl_merge(&ancestor_mmfile, &our_mmfile,
+ &their_mmfile, &xmparam, &mmbuffer)) < 0) {
giterr_set(GITERR_MERGE, "Failed to merge files.");
error = -1;
goto done;
}
+ if ((path = merge_file_best_path(ancestor, ours, theirs)) != NULL &&
+ (out->path = strdup(path)) == NULL) {
+ error = -1;
+ goto done;
+ }
+
out->automergeable = (xdl_result == 0);
- out->data = (unsigned char *)mmbuffer.ptr;
+ out->ptr = (unsigned char *)mmbuffer.ptr;
out->len = mmbuffer.size;
+ out->mode = merge_file_best_mode(ancestor, ours, theirs);
done:
+ if (error < 0)
+ git_merge_file_result_free(out);
+
return error;
}
+
+static git_merge_file_input *git_merge_file__normalize_inputs(
+ git_merge_file_input *out,
+ const git_merge_file_input *given)
+{
+ memcpy(out, given, sizeof(git_merge_file_input));
+
+ if (!out->path)
+ out->path = "file.txt";
+
+ if (!out->mode)
+ out->mode = 0100644;
+
+ return out;
+}
+
+int git_merge_file(
+ git_merge_file_result *out,
+ const git_merge_file_input *ancestor,
+ const git_merge_file_input *ours,
+ const git_merge_file_input *theirs,
+ const git_merge_file_options *options)
+{
+ git_merge_file_input inputs[3] = { {0} };
+
+ assert(out && ours && theirs);
+
+ memset(out, 0x0, sizeof(git_merge_file_result));
+
+ if (ancestor)
+ ancestor = git_merge_file__normalize_inputs(&inputs[0], ancestor);
+
+ ours = git_merge_file__normalize_inputs(&inputs[1], ours);
+ theirs = git_merge_file__normalize_inputs(&inputs[2], theirs);
+
+ return git_merge_file__from_inputs(out, ancestor, ours, theirs, options);
+}
+
+int git_merge_file_from_index(
+ git_merge_file_result *out,
+ git_repository *repo,
+ const git_index_entry *ancestor,
+ const git_index_entry *ours,
+ const git_index_entry *theirs,
+ const git_merge_file_options *options)
+{
+ git_merge_file_input inputs[3] = { {0} },
+ *ancestor_input = NULL, *our_input = NULL, *their_input = NULL;
+ git_odb *odb = NULL;
+ git_odb_object *odb_object[3] = { 0 };
+ int error = 0;
+
+ assert(out && repo && ours && theirs);
+
+ memset(out, 0x0, sizeof(git_merge_file_result));
+
+ if ((error = git_repository_odb(&odb, repo)) < 0)
+ goto done;
+
+ if (ancestor) {
+ if ((error = git_merge_file__input_from_index(
+ &inputs[0], &odb_object[0], odb, ancestor)) < 0)
+ goto done;
+
+ ancestor_input = &inputs[0];
+ }
+
+ if ((error = git_merge_file__input_from_index(
+ &inputs[1], &odb_object[1], odb, ours)) < 0)
+ goto done;
+
+ our_input = &inputs[1];
+
+ if ((error = git_merge_file__input_from_index(
+ &inputs[2], &odb_object[2], odb, theirs)) < 0)
+ goto done;
+
+ their_input = &inputs[2];
+
+ if ((error = git_merge_file__from_inputs(out,
+ ancestor_input, our_input, their_input, options)) < 0)
+ goto done;
+
+done:
+ git_odb_object_free(odb_object[0]);
+ git_odb_object_free(odb_object[1]);
+ git_odb_object_free(odb_object[2]);
+ git_odb_free(odb);
+
+ return error;
+}
+
+void git_merge_file_result_free(git_merge_file_result *result)
+{
+ if (result == NULL)
+ return;
+
+ git__free(result->path);
+
+ /* xdiff uses malloc() not git_malloc, so we use free(), not git_free() */
+ free(result->ptr);
+}
diff --git a/src/merge_file.h b/src/merge_file.h
index 332be49..263391e 100644
--- a/src/merge_file.h
+++ b/src/merge_file.h
@@ -11,82 +11,4 @@
#include "git2/merge.h"
-typedef struct {
- const char *label;
- char *path;
- unsigned int mode;
- mmfile_t mmfile;
-
- git_odb_object *odb_object;
-} git_merge_file_input;
-
-#define GIT_MERGE_FILE_INPUT_INIT {0}
-
-typedef struct {
- bool automergeable;
-
- const char *path;
- int mode;
-
- unsigned char *data;
- size_t len;
-} git_merge_file_result;
-
-#define GIT_MERGE_FILE_RESULT_INIT {0}
-
-typedef enum {
- /* Condense non-alphanumeric regions for simplified diff file */
- GIT_MERGE_FILE_SIMPLIFY_ALNUM = (1 << 0),
-} git_merge_file_flags_t;
-
-typedef enum {
- /* Create standard conflicted merge files */
- GIT_MERGE_FILE_STYLE_MERGE = 0,
-
- /* Create diff3-style files */
- GIT_MERGE_FILE_STYLE_DIFF3 = 1,
-} git_merge_file_style_t;
-
-typedef struct {
- git_merge_file_favor_t favor;
- git_merge_file_flags_t flags;
- git_merge_file_style_t style;
-} git_merge_file_options;
-
-#define GIT_MERGE_FILE_OPTIONS_INIT {0}
-
-int git_merge_file_input_from_index_entry(
- git_merge_file_input *input,
- git_repository *repo,
- const git_index_entry *entry);
-
-int git_merge_file_input_from_diff_file(
- git_merge_file_input *input,
- git_repository *repo,
- const git_diff_file *file);
-
-int git_merge_files(
- git_merge_file_result *out,
- git_merge_file_input *ancestor,
- git_merge_file_input *ours,
- git_merge_file_input *theirs,
- git_merge_file_options *opts);
-
-GIT_INLINE(void) git_merge_file_input_free(git_merge_file_input *input)
-{
- assert(input);
- git__free(input->path);
- git_odb_object_free(input->odb_object);
-}
-
-GIT_INLINE(void) git_merge_file_result_free(git_merge_file_result *filediff)
-{
- if (filediff == NULL)
- return;
-
- /* xdiff uses malloc() not git_malloc, so we use free(), not git_free() */
- if (filediff->data != NULL)
- free(filediff->data);
-}
-
#endif
diff --git a/src/revert.c b/src/revert.c
index 8e84463..4039ec3 100644
--- a/src/revert.c
+++ b/src/revert.c
@@ -121,7 +121,7 @@ int git_revert_commit(
git_commit *revert_commit,
git_commit *our_commit,
unsigned int mainline,
- const git_merge_tree_opts *merge_tree_opts)
+ const git_merge_options *merge_opts)
{
git_commit *parent_commit = NULL;
git_tree *parent_tree = NULL, *our_tree = NULL, *revert_tree = NULL;
@@ -152,7 +152,7 @@ int git_revert_commit(
(error = git_commit_tree(&our_tree, our_commit)) < 0)
goto done;
- error = git_merge_trees(out, repo, revert_tree, our_tree, parent_tree, merge_tree_opts);
+ error = git_merge_trees(out, repo, revert_tree, our_tree, parent_tree, merge_opts);
done:
git_tree_free(parent_tree);
@@ -198,7 +198,7 @@ int git_revert(
(error = write_merge_msg(repo, commit_oidstr, commit_msg)) < 0 ||
(error = git_repository_head(&our_ref, repo)) < 0 ||
(error = git_reference_peel((git_object **)&our_commit, our_ref, GIT_OBJ_COMMIT)) < 0 ||
- (error = git_revert_commit(&index_new, repo, commit, our_commit, opts.mainline, &opts.merge_tree_opts)) < 0 ||
+ (error = git_revert_commit(&index_new, repo, commit, our_commit, opts.mainline, &opts.merge_opts)) < 0 ||
(error = git_merge__indexes(repo, index_new)) < 0 ||
(error = git_repository_index(&index_repo, repo)) < 0 ||
(error = git_checkout_index(repo, index_repo, &opts.checkout_opts)) < 0)
diff --git a/tests/merge/files.c b/tests/merge/files.c
new file mode 100644
index 0000000..c377471
--- /dev/null
+++ b/tests/merge/files.c
@@ -0,0 +1,175 @@
+#include "clar_libgit2.h"
+#include "git2/repository.h"
+#include "git2/merge.h"
+#include "buffer.h"
+#include "merge.h"
+#include "merge_helpers.h"
+#include "refs.h"
+#include "fileops.h"
+
+#define TEST_REPO_PATH "merge-resolve"
+#define TEST_INDEX_PATH TEST_REPO_PATH "/.git/index"
+
+static git_repository *repo;
+static git_index *repo_index;
+
+// Fixture setup and teardown
+void test_merge_files__initialize(void)
+{
+ git_config *cfg;
+
+ repo = cl_git_sandbox_init(TEST_REPO_PATH);
+ git_repository_index(&repo_index, repo);
+
+ /* Ensure that the user's merge.conflictstyle doesn't interfere */
+ cl_git_pass(git_repository_config(&cfg, repo));
+ cl_git_pass(git_config_set_string(cfg, "merge.conflictstyle", "merge"));
+ git_config_free(cfg);
+}
+
+void test_merge_files__cleanup(void)
+{
+ git_index_free(repo_index);
+ cl_git_sandbox_cleanup();
+}
+
+void test_merge_files__automerge_from_bufs(void)
+{
+ git_merge_file_input ancestor = GIT_MERGE_FILE_INPUT_INIT,
+ ours = GIT_MERGE_FILE_INPUT_INIT,
+ theirs = GIT_MERGE_FILE_INPUT_INIT;
+ git_merge_file_result result = {0};
+ const char *expected = "Zero\n1\n2\n3\n4\n5\n6\n7\n8\n9\nTen\n";
+
+ ancestor.ptr = "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n";
+ ancestor.size = strlen(ancestor.ptr);
+ ancestor.path = "testfile.txt";
+ ancestor.mode = 0100755;
+
+ ours.ptr = "Zero\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n";
+ ours.size = strlen(ours.ptr);
+ ours.path = "testfile.txt";
+ ours.mode = 0100755;
+
+ theirs.ptr = "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\nTen\n";
+ theirs.size = strlen(theirs.ptr);
+ theirs.path = "testfile.txt";
+ theirs.mode = 0100755;
+
+ cl_git_pass(git_merge_file(&result, &ancestor, &ours, &theirs, 0));
+
+ cl_assert_equal_i(1, result.automergeable);
+
+ cl_assert_equal_s("testfile.txt", result.path);
+ cl_assert_equal_i(0100755, result.mode);
+
+ cl_assert_equal_i(strlen(expected), result.len);
+ cl_assert_equal_strn(expected, result.ptr, result.len);
+
+ git_merge_file_result_free(&result);
+}
+
+void test_merge_files__automerge_use_best_path_and_mode(void)
+{
+ git_merge_file_input ancestor = GIT_MERGE_FILE_INPUT_INIT,
+ ours = GIT_MERGE_FILE_INPUT_INIT,
+ theirs = GIT_MERGE_FILE_INPUT_INIT;
+ git_merge_file_result result = {0};
+ const char *expected = "Zero\n1\n2\n3\n4\n5\n6\n7\n8\n9\nTen\n";
+
+ ancestor.ptr = "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n";
+ ancestor.size = strlen(ancestor.ptr);
+ ancestor.path = "testfile.txt";
+ ancestor.mode = 0100755;
+
+ ours.ptr = "Zero\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n";
+ ours.size = strlen(ours.ptr);
+ ours.path = "testfile.txt";
+ ours.mode = 0100644;
+
+ theirs.ptr = "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\nTen\n";
+ theirs.size = strlen(theirs.ptr);
+ theirs.path = "theirs.txt";
+ theirs.mode = 0100755;
+
+ cl_git_pass(git_merge_file(&result, &ancestor, &ours, &theirs, 0));
+
+ cl_assert_equal_i(1, result.automergeable);
+
+ cl_assert_equal_s("theirs.txt", result.path);
+ cl_assert_equal_i(0100644, result.mode);
+
+ cl_assert_equal_i(strlen(expected), result.len);
+ cl_assert_equal_strn(expected, result.ptr, result.len);
+
+ git_merge_file_result_free(&result);
+}
+
+void test_merge_files__conflict_from_bufs(void)
+{
+ git_merge_file_input ancestor = GIT_MERGE_FILE_INPUT_INIT,
+ ours = GIT_MERGE_FILE_INPUT_INIT,
+ theirs = GIT_MERGE_FILE_INPUT_INIT;
+ git_merge_file_result result = {0};
+
+ const char *expected = "<<<<<<< testfile.txt\nAloha!\nOurs.\n=======\nHi!\nTheirs.\n>>>>>>> theirs.txt\n";
+ size_t expected_len = strlen(expected);
+
+ ancestor.ptr = "Hello!\nAncestor!\n";
+ ancestor.size = strlen(ancestor.ptr);
+ ancestor.path = "testfile.txt";
+ ancestor.mode = 0100755;
+
+ ours.ptr = "Aloha!\nOurs.\n";
+ ours.size = strlen(ours.ptr);
+ ours.path = "testfile.txt";
+ ours.mode = 0100644;
+
+ theirs.ptr = "Hi!\nTheirs.\n";
+ theirs.size = strlen(theirs.ptr);
+ theirs.path = "theirs.txt";
+ theirs.mode = 0100755;
+
+ cl_git_pass(git_merge_file(&result, &ancestor, &ours, &theirs, NULL));
+
+ cl_assert_equal_i(0, result.automergeable);
+
+ cl_assert_equal_s("theirs.txt", result.path);
+ cl_assert_equal_i(0100644, result.mode);
+
+ cl_assert_equal_i(expected_len, result.len);
+ cl_assert_equal_strn(expected, result.ptr, expected_len);
+
+ git_merge_file_result_free(&result);
+}
+
+void test_merge_files__automerge_from_index(void)
+{
+ git_merge_file_result result = {0};
+ git_index_entry ancestor, ours, theirs;
+
+ git_oid_fromstr(&ancestor.id, "6212c31dab5e482247d7977e4f0dd3601decf13b");
+ ancestor.path = "automergeable.txt";
+ ancestor.mode = 0100644;
+
+ git_oid_fromstr(&ours.id, "ee3fa1b8c00aff7fe02065fdb50864bb0d932ccf");
+ ours.path = "automergeable.txt";
+ ours.mode = 0100755;
+
+ git_oid_fromstr(&theirs.id, "058541fc37114bfc1dddf6bd6bffc7fae5c2e6fe");
+ theirs.path = "newname.txt";
+ theirs.mode = 0100644;
+
+ cl_git_pass(git_merge_file_from_index(&result, repo,
+ &ancestor, &ours, &theirs, 0));
+
+ cl_assert_equal_i(1, result.automergeable);
+
+ cl_assert_equal_s("newname.txt", result.path);
+ cl_assert_equal_i(0100755, result.mode);
+
+ cl_assert_equal_i(strlen(AUTOMERGEABLE_MERGED_FILE), result.len);
+ cl_assert_equal_strn(AUTOMERGEABLE_MERGED_FILE, result.ptr, result.len);
+
+ git_merge_file_result_free(&result);
+}
diff --git a/tests/merge/merge_helpers.c b/tests/merge/merge_helpers.c
index 14a30b2..154985f 100644
--- a/tests/merge/merge_helpers.c
+++ b/tests/merge/merge_helpers.c
@@ -10,7 +10,7 @@
int merge_trees_from_branches(
git_index **index, git_repository *repo,
const char *ours_name, const char *theirs_name,
- git_merge_tree_opts *opts)
+ git_merge_options *opts)
{
git_commit *our_commit, *their_commit, *ancestor_commit = NULL;
git_tree *our_tree, *their_tree, *ancestor_tree = NULL;
@@ -55,7 +55,7 @@ int merge_trees_from_branches(
int merge_commits_from_branches(
git_index **index, git_repository *repo,
const char *ours_name, const char *theirs_name,
- git_merge_tree_opts *opts)
+ git_merge_options *opts)
{
git_commit *our_commit, *their_commit;
git_oid our_oid, their_oid;
@@ -79,7 +79,9 @@ int merge_commits_from_branches(
return 0;
}
-int merge_branches(git_merge_result **result, git_repository *repo, const char *ours_branch, const char *theirs_branch, git_merge_opts *opts)
+int merge_branches(git_repository *repo,
+ const char *ours_branch, const char *theirs_branch,
+ git_merge_options *merge_opts, git_checkout_options *checkout_opts)
{
git_reference *head_ref, *theirs_ref;
git_merge_head *theirs_head;
@@ -93,7 +95,7 @@ int merge_branches(git_merge_result **result, git_repository *repo, const char *
cl_git_pass(git_reference_lookup(&theirs_ref, repo, theirs_branch));
cl_git_pass(git_merge_head_from_ref(&theirs_head, repo, theirs_ref));
- cl_git_pass(git_merge(result, repo, (const git_merge_head **)&theirs_head, 1, opts));
+ cl_git_pass(git_merge(repo, (const git_merge_head **)&theirs_head, 1, merge_opts, checkout_opts));
git_reference_free(head_ref);
git_reference_free(theirs_ref);
diff --git a/tests/merge/merge_helpers.h b/tests/merge/merge_helpers.h
index 3f53abc..fddf8fa 100644
--- a/tests/merge/merge_helpers.h
+++ b/tests/merge/merge_helpers.h
@@ -4,6 +4,49 @@
#include "merge.h"
#include "git2/merge.h"
+#define AUTOMERGEABLE_MERGED_FILE \
+ "this file is changed in master\n" \
+ "this file is automergeable\n" \
+ "this file is automergeable\n" \
+ "this file is automergeable\n" \
+ "this file is automergeable\n" \
+ "this file is automergeable\n" \
+ "this file is automergeable\n" \
+ "this file is automergeable\n" \
+ "this file is changed in branch\n"
+
+#define AUTOMERGEABLE_MERGED_FILE_CRLF \
+ "this file is changed in master\r\n" \
+ "this file is automergeable\r\n" \
+ "this file is automergeable\r\n" \
+ "this file is automergeable\r\n" \
+ "this file is automergeable\r\n" \
+ "this file is automergeable\r\n" \
+ "this file is automergeable\r\n" \
+ "this file is automergeable\r\n" \
+ "this file is changed in branch\r\n"
+
+#define CONFLICTING_MERGE_FILE \
+ "<<<<<<< HEAD\n" \
+ "this file is changed in master and branch\n" \
+ "=======\n" \
+ "this file is changed in branch and master\n" \
+ ">>>>>>> 7cb63eed597130ba4abb87b3e544b85021905520\n"
+
+#define CONFLICTING_DIFF3_FILE \
+ "<<<<<<< HEAD\n" \
+ "this file is changed in master and branch\n" \
+ "||||||| initial\n" \
+ "this file is a conflict\n" \
+ "=======\n" \
+ "this file is changed in branch and master\n" \
+ ">>>>>>> 7cb63eed597130ba4abb87b3e544b85021905520\n"
+
+#define CONFLICTING_UNION_FILE \
+ "this file is changed in master and branch\n" \
+ "this file is changed in branch and master\n"
+
+
struct merge_index_entry {
uint16_t mode;
char oid_str[41];
@@ -42,15 +85,16 @@ struct merge_index_conflict_data {
int merge_trees_from_branches(
git_index **index, git_repository *repo,
const char *ours_name, const char *theirs_name,
- git_merge_tree_opts *opts);
+ git_merge_options *opts);
int merge_commits_from_branches(
git_index **index, git_repository *repo,
const char *ours_name, const char *theirs_name,
- git_merge_tree_opts *opts);
+ git_merge_options *opts);
-int merge_branches(git_merge_result **result, git_repository *repo,
- const char *ours_branch, const char *theirs_branch, git_merge_opts *opts);
+int merge_branches(git_repository *repo,
+ const char *ours_branch, const char *theirs_branch,
+ git_merge_options *merge_opts, git_checkout_options *checkout_opts);
int merge_test_diff_list(git_merge_diff_list *diff_list, const struct merge_index_entry expected[], size_t expected_len);
diff --git a/tests/merge/trees/automerge.c b/tests/merge/trees/automerge.c
index bd710e6..c18881d 100644
--- a/tests/merge/trees/automerge.c
+++ b/tests/merge/trees/automerge.c
@@ -54,28 +54,6 @@ static git_repository *repo;
"", \
"5c3b68a71fc4fa5d362fd3875e53137c6a5ab7a5" }
-#define AUTOMERGEABLE_MERGED_FILE \
- "this file is changed in master\n" \
- "this file is automergeable\n" \
- "this file is automergeable\n" \
- "this file is automergeable\n" \
- "this file is automergeable\n" \
- "this file is automergeable\n" \
- "this file is automergeable\n" \
- "this file is automergeable\n" \
- "this file is changed in branch\n"
-
-#define AUTOMERGEABLE_MERGED_FILE_CRLF \
- "this file is changed in master\r\n" \
- "this file is automergeable\r\n" \
- "this file is automergeable\r\n" \
- "this file is automergeable\r\n" \
- "this file is automergeable\r\n" \
- "this file is automergeable\r\n" \
- "this file is automergeable\r\n" \
- "this file is automergeable\r\n" \
- "this file is changed in branch\r\n"
-
// Fixture setup and teardown
void test_merge_trees_automerge__initialize(void)
{
@@ -91,7 +69,7 @@ void test_merge_trees_automerge__automerge(void)
{
git_index *index;
const git_index_entry *entry;
- git_merge_tree_opts opts = GIT_MERGE_TREE_OPTS_INIT;
+ git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
git_blob *blob;
struct merge_index_entry merge_index_entries[] = {
@@ -131,7 +109,7 @@ void test_merge_trees_automerge__automerge(void)
void test_merge_trees_automerge__favor_ours(void)
{
git_index *index;
- git_merge_tree_opts opts = GIT_MERGE_TREE_OPTS_INIT;
+ git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
ADDED_IN_MASTER_INDEX_ENTRY,
@@ -162,7 +140,7 @@ void test_merge_trees_automerge__favor_ours(void)
void test_merge_trees_automerge__favor_theirs(void)
{
git_index *index;
- git_merge_tree_opts opts = GIT_MERGE_TREE_OPTS_INIT;
+ git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
ADDED_IN_MASTER_INDEX_ENTRY,
@@ -193,7 +171,7 @@ void test_merge_trees_automerge__favor_theirs(void)
void test_merge_trees_automerge__unrelated(void)
{
git_index *index;
- git_merge_tree_opts opts = GIT_MERGE_TREE_OPTS_INIT;
+ git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "233c0919c998ed110a4b6ff36f353aec8b713487", 0, "added-in-master.txt" },
diff --git a/tests/merge/trees/commits.c b/tests/merge/trees/commits.c
index eeb30da..c4e4709 100644
--- a/tests/merge/trees/commits.c
+++ b/tests/merge/trees/commits.c
@@ -8,17 +8,6 @@ static git_repository *repo;
#define TEST_REPO_PATH "merge-resolve"
-#define AUTOMERGEABLE_MERGED_FILE \
- "this file is changed in master\n" \
- "this file is automergeable\n" \
- "this file is automergeable\n" \
- "this file is automergeable\n" \
- "this file is automergeable\n" \
- "this file is automergeable\n" \
- "this file is automergeable\n" \
- "this file is automergeable\n" \
- "this file is changed in branch\n"
-
void test_merge_trees_commits__initialize(void)
{
repo = cl_git_sandbox_init(TEST_REPO_PATH);
@@ -33,7 +22,7 @@ void test_merge_trees_commits__automerge(void)
{
git_index *index;
const git_index_entry *entry;
- git_merge_tree_opts opts = GIT_MERGE_TREE_OPTS_INIT;
+ git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
git_blob *blob;
struct merge_index_entry merge_index_entries[] = {
@@ -82,7 +71,7 @@ void test_merge_trees_commits__automerge(void)
void test_merge_trees_commits__no_ancestor(void)
{
git_index *index;
- git_merge_tree_opts opts = GIT_MERGE_TREE_OPTS_INIT;
+ git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "233c0919c998ed110a4b6ff36f353aec8b713487", 0, "added-in-master.txt" },
@@ -109,7 +98,7 @@ void test_merge_trees_commits__no_ancestor(void)
void test_merge_trees_commits__df_conflict(void)
{
git_index *index;
- git_merge_tree_opts opts = GIT_MERGE_TREE_OPTS_INIT;
+ git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "49130a28ef567af9a6a6104c38773fedfa5f9742", 2, "dir-10" },
diff --git a/tests/merge/trees/renames.c b/tests/merge/trees/renames.c
index 427b6bd..d7721c8 100644
--- a/tests/merge/trees/renames.c
+++ b/tests/merge/trees/renames.c
@@ -27,7 +27,7 @@ void test_merge_trees_renames__cleanup(void)
void test_merge_trees_renames__index(void)
{
git_index *index;
- git_merge_tree_opts *opts = NULL;
+ git_merge_options *opts = NULL;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "68c6c84b091926c7d90aa6a79b2bc3bb6adccd8e", 0, "0a-no-change.txt" },
@@ -205,7 +205,7 @@ void test_merge_trees_renames__index(void)
void test_merge_trees_renames__no_rename_index(void)
{
git_index *index;
- git_merge_tree_opts opts = GIT_MERGE_TREE_OPTS_INIT;
+ git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "68c6c84b091926c7d90aa6a79b2bc3bb6adccd8e", 0, "0a-no-change.txt" },
diff --git a/tests/merge/trees/treediff.c b/tests/merge/trees/treediff.c
index 357859d..2298a30 100644
--- a/tests/merge/trees/treediff.c
+++ b/tests/merge/trees/treediff.c
@@ -44,7 +44,7 @@ static void test_find_differences(
git_oid ancestor_oid, ours_oid, theirs_oid;
git_tree *ancestor_tree, *ours_tree, *theirs_tree;
- git_merge_tree_opts opts = GIT_MERGE_TREE_OPTS_INIT;
+ git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
opts.flags |= GIT_MERGE_TREE_FIND_RENAMES;
opts.target_limit = 1000;
opts.rename_threshold = 50;
diff --git a/tests/merge/trees/trivial.c b/tests/merge/trees/trivial.c
index 377b247..62a4574 100644
--- a/tests/merge/trees/trivial.c
+++ b/tests/merge/trees/trivial.c
@@ -31,7 +31,7 @@ static int merge_trivial(git_index **index, const char *ours, const char *theirs
git_tree *our_tree, *their_tree, *ancestor_tree;
git_oid our_oid, their_oid, ancestor_oid;
git_buf branch_buf = GIT_BUF_INIT;
- git_merge_tree_opts opts = GIT_MERGE_TREE_OPTS_INIT;
+ git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
git_buf_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, ours);
cl_git_pass(git_reference_name_to_id(&our_oid, repo, branch_buf.ptr));
diff --git a/tests/merge/workdir/analysis.c b/tests/merge/workdir/analysis.c
new file mode 100644
index 0000000..0e93785
--- /dev/null
+++ b/tests/merge/workdir/analysis.c
@@ -0,0 +1,107 @@
+#include "clar_libgit2.h"
+#include "git2/repository.h"
+#include "git2/merge.h"
+#include "git2/sys/index.h"
+#include "merge.h"
+#include "../merge_helpers.h"
+#include "refs.h"
+#include "posix.h"
+
+static git_repository *repo;
+static git_index *repo_index;
+
+#define TEST_REPO_PATH "merge-resolve"
+#define TEST_INDEX_PATH TEST_REPO_PATH "/.git/index"
+
+#define UPTODATE_BRANCH "master"
+#define PREVIOUS_BRANCH "previous"
+
+#define FASTFORWARD_BRANCH "ff_branch"
+#define FASTFORWARD_ID "fd89f8cffb663ac89095a0f9764902e93ceaca6a"
+
+#define NOFASTFORWARD_BRANCH "branch"
+#define NOFASTFORWARD_ID "7cb63eed597130ba4abb87b3e544b85021905520"
+
+
+// Fixture setup and teardown
+void test_merge_workdir_analysis__initialize(void)
+{
+ repo = cl_git_sandbox_init(TEST_REPO_PATH);
+ git_repository_index(&repo_index, repo);
+}
+
+void test_merge_workdir_analysis__cleanup(void)
+{
+ git_index_free(repo_index);
+ cl_git_sandbox_cleanup();
+}
+
+static git_merge_analysis_t analysis_from_branch(const char *branchname)
+{
+ git_buf refname = GIT_BUF_INIT;
+ git_reference *their_ref;
+ git_merge_head *their_head;
+ git_merge_analysis_t analysis;
+
+ git_buf_printf(&refname, "%s%s", GIT_REFS_HEADS_DIR, branchname);
+
+ cl_git_pass(git_reference_lookup(&their_ref, repo, git_buf_cstr(&refname)));
+ cl_git_pass(git_merge_head_from_ref(&their_head, repo, their_ref));
+
+ cl_git_pass(git_merge_analysis(&analysis, repo, (const git_merge_head **)&their_head, 1));
+
+ git_buf_free(&refname);
+ git_merge_head_free(their_head);
+ git_reference_free(their_ref);
+
+ return analysis;
+}
+
+void test_merge_workdir_analysis__fastforward(void)
+{
+ git_merge_analysis_t analysis;
+
+ analysis = analysis_from_branch(FASTFORWARD_BRANCH);
+ cl_assert_equal_i(GIT_MERGE_ANALYSIS_FASTFORWARD, (analysis & GIT_MERGE_ANALYSIS_FASTFORWARD));
+ cl_assert_equal_i(GIT_MERGE_ANALYSIS_NORMAL, (analysis & GIT_MERGE_ANALYSIS_NORMAL));
+}
+
+void test_merge_workdir_analysis__no_fastforward(void)
+{
+ git_merge_analysis_t analysis;
+
+ analysis = analysis_from_branch(NOFASTFORWARD_BRANCH);
+ cl_assert_equal_i(GIT_MERGE_ANALYSIS_NORMAL, analysis);
+}
+
+void test_merge_workdir_analysis__uptodate(void)
+{
+ git_merge_analysis_t analysis;
+
+ analysis = analysis_from_branch(UPTODATE_BRANCH);
+ cl_assert_equal_i(GIT_MERGE_ANALYSIS_UP_TO_DATE, analysis);
+}
+
+void test_merge_workdir_analysis__uptodate_merging_prev_commit(void)
+{
+ git_merge_analysis_t analysis;
+
+ analysis = analysis_from_branch(PREVIOUS_BRANCH);
+ cl_assert_equal_i(GIT_MERGE_ANALYSIS_UP_TO_DATE, analysis);
+}
+
+void test_merge_workdir_analysis__unborn(void)
+{
+ git_merge_analysis_t analysis;
+ git_buf master = GIT_BUF_INIT;
+
+ git_buf_joinpath(&master, git_repository_path(repo), "refs/heads/master");
+ p_unlink(git_buf_cstr(&master));
+
+ analysis = analysis_from_branch(NOFASTFORWARD_BRANCH);
+ cl_assert_equal_i(GIT_MERGE_ANALYSIS_FASTFORWARD, (analysis & GIT_MERGE_ANALYSIS_FASTFORWARD));
+ cl_assert_equal_i(GIT_MERGE_ANALYSIS_UNBORN, (analysis & GIT_MERGE_ANALYSIS_UNBORN));
+
+ git_buf_free(&master);
+}
+
diff --git a/tests/merge/workdir/dirty.c b/tests/merge/workdir/dirty.c
index a77f9b2..1d596c5 100644
--- a/tests/merge/workdir/dirty.c
+++ b/tests/merge/workdir/dirty.c
@@ -86,19 +86,20 @@ static void set_core_autocrlf_to(git_repository *repo, bool value)
git_config_free(cfg);
}
-static int merge_branch(git_merge_result **result, int merge_file_favor, int checkout_strategy)
+static int merge_branch(int merge_file_favor, int checkout_strategy)
{
git_oid their_oids[1];
git_merge_head *their_heads[1];
- git_merge_opts opts = GIT_MERGE_OPTS_INIT;
+ git_merge_options merge_opts = GIT_MERGE_OPTIONS_INIT;
+ git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
int error;
cl_git_pass(git_oid_fromstr(&their_oids[0], MERGE_BRANCH_OID));
cl_git_pass(git_merge_head_from_id(&their_heads[0], repo, &their_oids[0]));
- opts.merge_tree_opts.file_favor = merge_file_favor;
- opts.checkout_opts.checkout_strategy = checkout_strategy;
- error = git_merge(result, repo, (const git_merge_head **)their_heads, 1, &opts);
+ merge_opts.file_favor = merge_file_favor;
+ checkout_opts.checkout_strategy = checkout_strategy;
+ error = git_merge(repo, (const git_merge_head **)their_heads, 1, &merge_opts, &checkout_opts);
git_merge_head_free(their_heads[0]);
@@ -176,7 +177,6 @@ static void stage_content(char *content[])
{
git_reference *head;
git_object *head_object;
- git_merge_result *result = NULL;
git_buf path = GIT_BUF_INIT;
char *filename, *text;
size_t i;
@@ -197,7 +197,6 @@ static void stage_content(char *content[])
cl_git_pass(git_index_add_bypath(repo_index, filename));
}
- git_merge_result_free(result);
git_object_free(head_object);
git_reference_free(head);
git_buf_free(&path);
@@ -207,7 +206,6 @@ static int merge_dirty_files(char *dirty_files[])
{
git_reference *head;
git_object *head_object;
- git_merge_result *result = NULL;
int error;
cl_git_pass(git_repository_head(&head, repo));
@@ -216,9 +214,8 @@ static int merge_dirty_files(char *dirty_files[])
write_files(dirty_files);
- error = merge_branch(&result, 0, 0);
+ error = merge_branch(0, 0);
- git_merge_result_free(result);
git_object_free(head_object);
git_reference_free(head);
@@ -229,7 +226,6 @@ static int merge_differently_filtered_files(char *files[])
{
git_reference *head;
git_object *head_object;
- git_merge_result *result = NULL;
int error;
cl_git_pass(git_repository_head(&head, repo));
@@ -241,9 +237,8 @@ static int merge_differently_filtered_files(char *files[])
cl_git_pass(git_index_write(repo_index));
- error = merge_branch(&result, 0, 0);
+ error = merge_branch(0, 0);
- git_merge_result_free(result);
git_object_free(head_object);
git_reference_free(head);
@@ -251,17 +246,9 @@ static int merge_differently_filtered_files(char *files[])
}
static int merge_staged_files(char *staged_files[])
-{
- git_merge_result *result = NULL;
- int error;
-
+{
stage_random_files(staged_files);
-
- error = merge_branch(&result, 0, 0);
-
- git_merge_result_free(result);
-
- return error;
+ return merge_branch(0, 0);
}
void test_merge_workdir_dirty__unaffected_dirty_files_allowed(void)
@@ -296,7 +283,6 @@ void test_merge_workdir_dirty__staged_files_in_index_disallowed(void)
void test_merge_workdir_dirty__identical_staged_files_allowed(void)
{
- git_merge_result *result;
char **content;
size_t i;
@@ -306,9 +292,7 @@ void test_merge_workdir_dirty__identical_staged_files_allowed(void)
stage_content(content);
git_index_write(repo_index);
- cl_git_pass(merge_branch(&result, 0, 0));
-
- git_merge_result_free(result);
+ cl_git_pass(merge_branch(0, 0));
}
}
diff --git a/tests/merge/workdir/fastforward.c b/tests/merge/workdir/fastforward.c
deleted file mode 100644
index d6b3148..0000000
--- a/tests/merge/workdir/fastforward.c
+++ /dev/null
@@ -1,148 +0,0 @@
-#include "clar_libgit2.h"
-#include "git2/repository.h"
-#include "git2/merge.h"
-#include "git2/sys/index.h"
-#include "merge.h"
-#include "../merge_helpers.h"
-#include "refs.h"
-
-static git_repository *repo;
-static git_index *repo_index;
-
-#define TEST_REPO_PATH "merge-resolve"
-#define TEST_INDEX_PATH TEST_REPO_PATH "/.git/index"
-
-#define THEIRS_FASTFORWARD_BRANCH "ff_branch"
-#define THEIRS_FASTFORWARD_ID "fd89f8cffb663ac89095a0f9764902e93ceaca6a"
-
-#define THEIRS_NOFASTFORWARD_BRANCH "branch"
-#define THEIRS_NOFASTFORWARD_ID "7cb63eed597130ba4abb87b3e544b85021905520"
-
-
-// Fixture setup and teardown
-void test_merge_workdir_fastforward__initialize(void)
-{
- repo = cl_git_sandbox_init(TEST_REPO_PATH);
- git_repository_index(&repo_index, repo);
-}
-
-void test_merge_workdir_fastforward__cleanup(void)
-{
- git_index_free(repo_index);
- cl_git_sandbox_cleanup();
-}
-
-static git_merge_result *merge_fastforward_branch(int flags)
-{
- git_reference *their_ref;
- git_merge_head *their_heads[1];
- git_merge_result *result;
- git_merge_opts opts = GIT_MERGE_OPTS_INIT;
-
- opts.merge_flags = flags;
-
- cl_git_pass(git_reference_lookup(&their_ref, repo, GIT_REFS_HEADS_DIR THEIRS_FASTFORWARD_BRANCH));
- cl_git_pass(git_merge_head_from_ref(&their_heads[0], repo, their_ref));
-
- cl_git_pass(git_merge(&result, repo, (const git_merge_head **)their_heads, 1, &opts));
-
- git_merge_head_free(their_heads[0]);
- git_reference_free(their_ref);
-
- return result;
-}
-
-void test_merge_workdir_fastforward__fastforward(void)
-{
- git_merge_result *result;
- git_oid expected, ff_oid;
-
- cl_git_pass(git_oid_fromstr(&expected, THEIRS_FASTFORWARD_ID));
-
- cl_assert(result = merge_fastforward_branch(0));
- cl_assert(git_merge_result_is_fastforward(result));
- cl_git_pass(git_merge_result_fastforward_id(&ff_oid, result));
- cl_assert(git_oid_cmp(&ff_oid, &expected) == 0);
-
- git_merge_result_free(result);
-}
-
-void test_merge_workdir_fastforward__fastforward_only(void)
-{
- git_merge_result *result;
- git_merge_opts opts = GIT_MERGE_OPTS_INIT;
- git_reference *their_ref;
- git_merge_head *their_head;
- int error;
-
- opts.merge_flags = GIT_MERGE_FASTFORWARD_ONLY;
-
- cl_git_pass(git_reference_lookup(&their_ref, repo, GIT_REFS_HEADS_DIR THEIRS_NOFASTFORWARD_BRANCH));
- cl_git_pass(git_merge_head_from_ref(&their_head, repo, their_ref));
-
- cl_git_fail((error = git_merge(&result, repo, (const git_merge_head **)&their_head, 1, &opts)));
- cl_assert(error == GIT_ENONFASTFORWARD);
-
- git_merge_head_free(their_head);
- git_reference_free(their_ref);
-}
-
-void test_merge_workdir_fastforward__no_fastforward(void)
-{
- git_merge_result *result;
-
- struct merge_index_entry merge_index_entries[] = {
- { 0100644, "233c0919c998ed110a4b6ff36f353aec8b713487", 0, "added-in-master.txt" },
- { 0100644, "ee3fa1b8c00aff7fe02065fdb50864bb0d932ccf", 0, "automergeable.txt" },
- { 0100644, "ab6c44a2e84492ad4b41bb6bac87353e9d02ac8b", 0, "changed-in-branch.txt" },
- { 0100644, "bd9cb4cd0a770cb9adcb5fce212142ef40ea1c35", 0, "changed-in-master.txt" },
- { 0100644, "4e886e602529caa9ab11d71f86634bd1b6e0de10", 0, "conflicting.txt" },
- { 0100644, "364bbe4ce80c7bd31e6307dce77d46e3e1759fb3", 0, "new-in-ff.txt" },
- { 0100644, "dfe3f22baa1f6fce5447901c3086bae368de6bdd", 0, "removed-in-branch.txt" },
- { 0100644, "c8f06f2e3bb2964174677e91f0abead0e43c9e5d", 0, "unchanged.txt" },
- };
-
- cl_assert(result = merge_fastforward_branch(GIT_MERGE_NO_FASTFORWARD));
- cl_assert(!git_merge_result_is_fastforward(result));
-
- cl_assert(merge_test_index(repo_index, merge_index_entries, 8));
- cl_assert(git_index_reuc_entrycount(repo_index) == 0);
-
- git_merge_result_free(result);
-}
-
-void test_merge_workdir_fastforward__uptodate(void)
-{
- git_reference *their_ref;
- git_merge_head *their_heads[1];
- git_merge_result *result;
-
- cl_git_pass(git_reference_lookup(&their_ref, repo, GIT_HEAD_FILE));
- cl_git_pass(git_merge_head_from_ref(&their_heads[0], repo, their_ref));
-
- cl_git_pass(git_merge(&result, repo, (const git_merge_head **)their_heads, 1, NULL));
-
- cl_assert(git_merge_result_is_uptodate(result));
-
- git_merge_head_free(their_heads[0]);
- git_reference_free(their_ref);
- git_merge_result_free(result);
-}
-
-void test_merge_workdir_fastforward__uptodate_merging_prev_commit(void)
-{
- git_oid their_oid;
- git_merge_head *their_heads[1];
- git_merge_result *result;
-
- cl_git_pass(git_oid_fromstr(&their_oid, "c607fc30883e335def28cd686b51f6cfa02b06ec"));
- cl_git_pass(git_merge_head_from_id(&their_heads[0], repo, &their_oid));
-
- cl_git_pass(git_merge(&result, repo, (const git_merge_head **)their_heads, 1, NULL));
-
- cl_assert(git_merge_result_is_uptodate(result));
-
- git_merge_head_free(their_heads[0]);
- git_merge_result_free(result);
-}
-
diff --git a/tests/merge/workdir/renames.c b/tests/merge/workdir/renames.c
index 2774772..807a88f 100644
--- a/tests/merge/workdir/renames.c
+++ b/tests/merge/workdir/renames.c
@@ -34,8 +34,7 @@ void test_merge_workdir_renames__cleanup(void)
void test_merge_workdir_renames__renames(void)
{
- git_merge_result *result;
- git_merge_opts opts = GIT_MERGE_OPTS_INIT;
+ git_merge_options merge_opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "68c6c84b091926c7d90aa6a79b2bc3bb6adccd8e", 0, "0a-no-change.txt" },
@@ -64,20 +63,18 @@ void test_merge_workdir_renames__renames(void)
{ 0100644, "b69fe837e4cecfd4c9a40cdca7c138468687df07", 0, "7-both-renamed.txt~rename_conflict_theirs" },
};
- opts.merge_tree_opts.flags |= GIT_MERGE_TREE_FIND_RENAMES;
- opts.merge_tree_opts.rename_threshold = 50;
+ merge_opts.flags |= GIT_MERGE_TREE_FIND_RENAMES;
+ merge_opts.rename_threshold = 50;
- cl_git_pass(merge_branches(&result, repo, GIT_REFS_HEADS_DIR BRANCH_RENAME_OURS, GIT_REFS_HEADS_DIR BRANCH_RENAME_THEIRS, &opts));
+ cl_git_pass(merge_branches(repo, GIT_REFS_HEADS_DIR BRANCH_RENAME_OURS, GIT_REFS_HEADS_DIR BRANCH_RENAME_THEIRS, &merge_opts, NULL));
cl_assert(merge_test_workdir(repo, merge_index_entries, 24));
-
- git_merge_result_free(result);
}
void test_merge_workdir_renames__ours(void)
{
git_index *index;
- git_merge_result *result;
- git_merge_opts opts = GIT_MERGE_OPTS_INIT;
+ git_merge_options merge_opts = GIT_MERGE_OPTIONS_INIT;
+ git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "68c6c84b091926c7d90aa6a79b2bc3bb6adccd8e", 0, "0a-no-change.txt" },
@@ -102,23 +99,21 @@ void test_merge_workdir_renames__ours(void)
{ 0100644, "b42712cfe99a1a500b2a51fe984e0b8a7702ba11", 0, "7-both-renamed.txt" },
};
- opts.merge_tree_opts.flags |= GIT_MERGE_TREE_FIND_RENAMES;
- opts.merge_tree_opts.rename_threshold = 50;
- opts.checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_USE_OURS;
+ merge_opts.flags |= GIT_MERGE_TREE_FIND_RENAMES;
+ merge_opts.rename_threshold = 50;
+ checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_USE_OURS;
- cl_git_pass(merge_branches(&result, repo, GIT_REFS_HEADS_DIR BRANCH_RENAME_OURS, GIT_REFS_HEADS_DIR BRANCH_RENAME_THEIRS, &opts));
+ cl_git_pass(merge_branches(repo, GIT_REFS_HEADS_DIR BRANCH_RENAME_OURS, GIT_REFS_HEADS_DIR BRANCH_RENAME_THEIRS, &merge_opts, &checkout_opts));
cl_git_pass(git_repository_index(&index, repo));
cl_git_pass(git_index_write(index));
cl_assert(merge_test_workdir(repo, merge_index_entries, 20));
- git_merge_result_free(result);
git_index_free(index);
}
void test_merge_workdir_renames__similar(void)
{
- git_merge_result *result;
- git_merge_opts opts = GIT_MERGE_OPTS_INIT;
+ git_merge_options merge_opts = GIT_MERGE_OPTIONS_INIT;
/*
* Note: this differs slightly from the core git merge result - there, 4a is
@@ -152,12 +147,10 @@ void test_merge_workdir_renames__similar(void)
{ 0100644, "b69fe837e4cecfd4c9a40cdca7c138468687df07", 0, "7-both-renamed.txt~rename_conflict_theirs" },
};
- opts.merge_tree_opts.flags |= GIT_MERGE_TREE_FIND_RENAMES;
- opts.merge_tree_opts.rename_threshold = 50;
+ merge_opts.flags |= GIT_MERGE_TREE_FIND_RENAMES;
+ merge_opts.rename_threshold = 50;
- cl_git_pass(merge_branches(&result, repo, GIT_REFS_HEADS_DIR BRANCH_RENAME_OURS, GIT_REFS_HEADS_DIR BRANCH_RENAME_THEIRS, &opts));
+ cl_git_pass(merge_branches(repo, GIT_REFS_HEADS_DIR BRANCH_RENAME_OURS, GIT_REFS_HEADS_DIR BRANCH_RENAME_THEIRS, &merge_opts, NULL));
cl_assert(merge_test_workdir(repo, merge_index_entries, 24));
-
- git_merge_result_free(result);
}
diff --git a/tests/merge/workdir/setup.c b/tests/merge/workdir/setup.c
index 05f994e..49b38b2 100644
--- a/tests/merge/workdir/setup.c
+++ b/tests/merge/workdir/setup.c
@@ -71,7 +71,7 @@ static void write_file_contents(const char *filename, const char *output)
git_buf_free(&file_path_buf);
}
-/* git merge octo1 */
+/* git merge --no-ff octo1 */
void test_merge_workdir_setup__one_branch(void)
{
git_oid our_oid;
@@ -84,33 +84,7 @@ void test_merge_workdir_setup__one_branch(void)
cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH));
cl_git_pass(git_merge_head_from_ref(&their_heads[0], repo, octo1_ref));
- cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 1, 0));
-
- cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n"));
- cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
- cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, ""));
- cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branch '" OCTO1_BRANCH "'\n"));
-
- git_reference_free(octo1_ref);
-
- git_merge_head_free(our_head);
- git_merge_head_free(their_heads[0]);
-}
-
-/* git merge --no-ff octo1 */
-void test_merge_workdir_setup__no_fastforward(void)
-{
- git_oid our_oid;
- git_reference *octo1_ref;
- git_merge_head *our_head, *their_heads[1];
-
- cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
- cl_git_pass(git_merge_head_from_id(&our_head, repo, &our_oid));
-
- cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH));
- cl_git_pass(git_merge_head_from_ref(&their_heads[0], repo, octo1_ref));
-
- cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 1, GIT_MERGE_NO_FASTFORWARD));
+ cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 1));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
@@ -118,12 +92,12 @@ void test_merge_workdir_setup__no_fastforward(void)
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branch '" OCTO1_BRANCH "'\n"));
git_reference_free(octo1_ref);
-
+
git_merge_head_free(our_head);
git_merge_head_free(their_heads[0]);
}
-/* git merge 16f825815cfd20a07a75c71554e82d8eede0b061 */
+/* git merge --no-ff 16f825815cfd20a07a75c71554e82d8eede0b061 */
void test_merge_workdir_setup__one_oid(void)
{
git_oid our_oid;
@@ -136,11 +110,11 @@ void test_merge_workdir_setup__one_oid(void)
cl_git_pass(git_oid_fromstr(&octo1_oid, OCTO1_OID));
cl_git_pass(git_merge_head_from_id(&their_heads[0], repo, &octo1_oid));
- cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 1, 0));
+ cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 1));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
- cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, ""));
+ cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge commit '" OCTO1_OID "'\n"));
git_merge_head_free(our_head);
@@ -164,11 +138,11 @@ void test_merge_workdir_setup__two_branches(void)
cl_git_pass(git_reference_lookup(&octo2_ref, repo, GIT_REFS_HEADS_DIR OCTO2_BRANCH));
cl_git_pass(git_merge_head_from_ref(&their_heads[1], repo, octo2_ref));
- cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 2, 0));
+ cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 2));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
- cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, ""));
+ cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branches '" OCTO1_BRANCH "' and '" OCTO2_BRANCH "'\n"));
git_reference_free(octo1_ref);
@@ -200,11 +174,11 @@ void test_merge_workdir_setup__three_branches(void)
cl_git_pass(git_reference_lookup(&octo3_ref, repo, GIT_REFS_HEADS_DIR OCTO3_BRANCH));
cl_git_pass(git_merge_head_from_ref(&their_heads[2], repo, octo3_ref));
- cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 3, 0));
+ cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 3));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n" OCTO3_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
- cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, ""));
+ cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branches '" OCTO1_BRANCH "', '" OCTO2_BRANCH "' and '" OCTO3_BRANCH "'\n"));
git_reference_free(octo1_ref);
@@ -238,11 +212,11 @@ void test_merge_workdir_setup__three_oids(void)
cl_git_pass(git_oid_fromstr(&octo3_oid, OCTO3_OID));
cl_git_pass(git_merge_head_from_id(&their_heads[2], repo, &octo3_oid));
- cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 3, 0));
+ cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 3));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n" OCTO3_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
- cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, ""));
+ cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge commit '" OCTO1_OID "'; commit '" OCTO2_OID "'; commit '" OCTO3_OID "'\n"));
git_merge_head_free(our_head);
@@ -268,11 +242,11 @@ void test_merge_workdir_setup__branches_and_oids_1(void)
cl_git_pass(git_oid_fromstr(&octo2_oid, OCTO2_OID));
cl_git_pass(git_merge_head_from_id(&their_heads[1], repo, &octo2_oid));
- cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 2, 0));
+ cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 2));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
- cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, ""));
+ cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branch '" OCTO1_BRANCH "'; commit '" OCTO2_OID "'\n"));
git_reference_free(octo1_ref);
@@ -307,11 +281,11 @@ void test_merge_workdir_setup__branches_and_oids_2(void)
cl_git_pass(git_oid_fromstr(&octo4_oid, OCTO4_OID));
cl_git_pass(git_merge_head_from_id(&their_heads[3], repo, &octo4_oid));
- cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 4, 0));
+ cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 4));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n" OCTO3_OID "\n" OCTO4_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
- cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, ""));
+ cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branches '" OCTO1_BRANCH "' and '" OCTO3_BRANCH "'; commit '" OCTO2_OID "'; commit '" OCTO4_OID "'\n"));
git_reference_free(octo1_ref);
@@ -349,11 +323,11 @@ void test_merge_workdir_setup__branches_and_oids_3(void)
cl_git_pass(git_reference_lookup(&octo4_ref, repo, GIT_REFS_HEADS_DIR OCTO4_BRANCH));
cl_git_pass(git_merge_head_from_ref(&their_heads[3], repo, octo4_ref));
- cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 4, 0));
+ cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 4));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n" OCTO3_OID "\n" OCTO4_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
- cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, ""));
+ cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge commit '" OCTO1_OID "'; branches '" OCTO2_BRANCH "' and '" OCTO4_BRANCH "'; commit '" OCTO3_OID "'\n"));
git_reference_free(octo2_ref);
@@ -395,11 +369,11 @@ void test_merge_workdir_setup__branches_and_oids_4(void)
cl_git_pass(git_reference_lookup(&octo5_ref, repo, GIT_REFS_HEADS_DIR OCTO5_BRANCH));
cl_git_pass(git_merge_head_from_ref(&their_heads[4], repo, octo5_ref));
- cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 5, 0));
+ cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 5));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n" OCTO3_OID "\n" OCTO4_OID "\n" OCTO5_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
- cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, ""));
+ cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge commit '" OCTO1_OID "'; branches '" OCTO2_BRANCH "', '" OCTO4_BRANCH "' and '" OCTO5_BRANCH "'; commit '" OCTO3_OID "'\n"));
git_reference_free(octo2_ref);
@@ -435,11 +409,11 @@ void test_merge_workdir_setup__three_same_branches(void)
cl_git_pass(git_reference_lookup(&octo1_3_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH));
cl_git_pass(git_merge_head_from_ref(&their_heads[2], repo, octo1_3_ref));
- cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 3, 0));
+ cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 3));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO1_OID "\n" OCTO1_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
- cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, ""));
+ cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branches '" OCTO1_BRANCH "', '" OCTO1_BRANCH "' and '" OCTO1_BRANCH "'\n"));
git_reference_free(octo1_1_ref);
@@ -473,11 +447,11 @@ void test_merge_workdir_setup__three_same_oids(void)
cl_git_pass(git_oid_fromstr(&octo1_3_oid, OCTO1_OID));
cl_git_pass(git_merge_head_from_id(&their_heads[2], repo, &octo1_3_oid));
- cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 3, 0));
+ cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 3));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO1_OID "\n" OCTO1_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
- cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, ""));
+ cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge commit '" OCTO1_OID "'; commit '" OCTO1_OID "'; commit '" OCTO1_OID "'\n"));
git_merge_head_free(our_head);
@@ -544,11 +518,11 @@ void test_merge_workdir_setup__remote_tracking_one_branch(void)
cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_REMOTES_DIR "origin/" OCTO1_BRANCH));
cl_git_pass(git_merge_head_from_ref(&their_heads[0], repo, octo1_ref));
- cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 1, 0));
+ cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 1));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
- cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, ""));
+ cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge remote-tracking branch 'refs/remotes/origin/" OCTO1_BRANCH "'\n"));
git_reference_free(octo1_ref);
@@ -577,11 +551,11 @@ void test_merge_workdir_setup__remote_tracking_two_branches(void)
cl_git_pass(git_reference_lookup(&octo2_ref, repo, GIT_REFS_REMOTES_DIR "origin/" OCTO2_BRANCH));
cl_git_pass(git_merge_head_from_ref(&their_heads[1], repo, octo2_ref));
- cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 2, 0));
+ cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 2));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
- cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, ""));
+ cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge remote-tracking branches 'refs/remotes/origin/" OCTO1_BRANCH "' and 'refs/remotes/origin/" OCTO2_BRANCH "'\n"));
git_reference_free(octo1_ref);
@@ -617,11 +591,11 @@ void test_merge_workdir_setup__remote_tracking_three_branches(void)
cl_git_pass(git_reference_lookup(&octo3_ref, repo, GIT_REFS_REMOTES_DIR "origin/" OCTO3_BRANCH));
cl_git_pass(git_merge_head_from_ref(&their_heads[2], repo, octo3_ref));
- cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 3, 0));
+ cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 3));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n" OCTO3_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
- cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, ""));
+ cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge remote-tracking branches 'refs/remotes/origin/" OCTO1_BRANCH "', 'refs/remotes/origin/" OCTO2_BRANCH "' and 'refs/remotes/origin/" OCTO3_BRANCH "'\n"));
git_reference_free(octo1_ref);
@@ -653,11 +627,11 @@ void test_merge_workdir_setup__normal_branch_and_remote_tracking_branch(void)
cl_git_pass(git_reference_lookup(&octo2_ref, repo, GIT_REFS_REMOTES_DIR "origin/" OCTO2_BRANCH));
cl_git_pass(git_merge_head_from_ref(&their_heads[1], repo, octo2_ref));
- cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 2, 0));
+ cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 2));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
- cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, ""));
+ cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branch '" OCTO1_BRANCH "', remote-tracking branch 'refs/remotes/origin/" OCTO2_BRANCH "'\n"));
git_reference_free(octo1_ref);
@@ -687,11 +661,11 @@ void test_merge_workdir_setup__remote_tracking_branch_and_normal_branch(void)
cl_git_pass(git_reference_lookup(&octo2_ref, repo, GIT_REFS_HEADS_DIR OCTO2_BRANCH));
cl_git_pass(git_merge_head_from_ref(&their_heads[1], repo, octo2_ref));
- cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 2, 0));
+ cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 2));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
- cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, ""));
+ cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branch '" OCTO2_BRANCH "', remote-tracking branch 'refs/remotes/origin/" OCTO1_BRANCH "'\n"));
git_reference_free(octo1_ref);
@@ -730,11 +704,11 @@ void test_merge_workdir_setup__two_remote_tracking_branch_and_two_normal_branche
cl_git_pass(git_reference_lookup(&octo4_ref, repo, GIT_REFS_REMOTES_DIR "origin/" OCTO4_BRANCH));
cl_git_pass(git_merge_head_from_ref(&their_heads[3], repo, octo4_ref));
- cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 4, 0));
+ cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 4));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n" OCTO3_OID "\n" OCTO4_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
- cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, ""));
+ cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branches '" OCTO1_BRANCH "' and '" OCTO3_BRANCH "', remote-tracking branches 'refs/remotes/origin/" OCTO2_BRANCH "' and 'refs/remotes/origin/" OCTO4_BRANCH "'\n"));
git_reference_free(octo1_ref);
@@ -762,11 +736,11 @@ void test_merge_workdir_setup__pull_one(void)
cl_git_pass(git_oid_fromstr(&octo1_1_oid, OCTO1_OID));
cl_git_pass(git_merge_head_from_fetchhead(&their_heads[0], repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH, "http://remote.url/repo.git", &octo1_1_oid));
- cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 1, 0));
+ cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 1));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
- cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, ""));
+ cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branch 'octo1' of http://remote.url/repo.git\n"));
git_merge_head_free(our_head);
@@ -790,11 +764,11 @@ void test_merge_workdir_setup__pull_two(void)
cl_git_pass(git_oid_fromstr(&octo2_oid, OCTO2_OID));
cl_git_pass(git_merge_head_from_fetchhead(&their_heads[1], repo, GIT_REFS_HEADS_DIR OCTO2_BRANCH, "http://remote.url/repo.git", &octo2_oid));
- cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 2, 0));
+ cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 2));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
- cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, ""));
+ cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branches '" OCTO1_BRANCH "' and '" OCTO2_BRANCH "' of http://remote.url/repo.git\n"));
git_merge_head_free(our_head);
@@ -823,11 +797,11 @@ void test_merge_workdir_setup__pull_three(void)
cl_git_pass(git_oid_fromstr(&octo3_oid, OCTO3_OID));
cl_git_pass(git_merge_head_from_fetchhead(&their_heads[2], repo, GIT_REFS_HEADS_DIR OCTO3_BRANCH, "http://remote.url/repo.git", &octo3_oid));
- cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 3, 0));
+ cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 3));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n" OCTO3_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
- cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, ""));
+ cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branches '" OCTO1_BRANCH "', '" OCTO2_BRANCH "' and '" OCTO3_BRANCH "' of http://remote.url/repo.git\n"));
git_merge_head_free(our_head);
@@ -856,11 +830,11 @@ void test_merge_workdir_setup__three_remotes(void)
cl_git_pass(git_oid_fromstr(&octo3_oid, OCTO3_OID));
cl_git_pass(git_merge_head_from_fetchhead(&their_heads[2], repo, GIT_REFS_HEADS_DIR OCTO3_BRANCH, "http://remote.third/repo.git", &octo3_oid));
- cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 3, 0));
+ cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 3));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n" OCTO3_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
- cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, ""));
+ cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branch '" OCTO1_BRANCH "' of http://remote.first/repo.git, branch '" OCTO2_BRANCH "' of http://remote.second/repo.git, branch '" OCTO3_BRANCH "' of http://remote.third/repo.git\n"));
git_merge_head_free(our_head);
@@ -893,11 +867,11 @@ void test_merge_workdir_setup__two_remotes(void)
cl_git_pass(git_oid_fromstr(&octo4_oid, OCTO4_OID));
cl_git_pass(git_merge_head_from_fetchhead(&their_heads[3], repo, GIT_REFS_HEADS_DIR OCTO4_BRANCH, "http://remote.second/repo.git", &octo4_oid));
- cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 4, 0));
+ cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 4));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n" OCTO3_OID "\n" OCTO4_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
- cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, ""));
+ cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branches '" OCTO1_BRANCH "' and '" OCTO3_BRANCH "' of http://remote.first/repo.git, branches '" OCTO2_BRANCH "' and '" OCTO4_BRANCH "' of http://remote.second/repo.git\n"));
git_merge_head_free(our_head);
@@ -996,10 +970,6 @@ void test_merge_workdir_setup__retained_after_success(void)
git_oid our_oid;
git_reference *octo1_ref;
git_merge_head *our_head, *their_heads[1];
- git_merge_result *result;
- git_merge_opts opts = GIT_MERGE_OPTS_INIT;
-
- opts.merge_flags |= GIT_MERGE_NO_FASTFORWARD;
cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
cl_git_pass(git_merge_head_from_id(&our_head, repo, &our_oid));
@@ -1008,7 +978,7 @@ void test_merge_workdir_setup__retained_after_success(void)
cl_git_pass(git_merge_head_from_ref(&their_heads[0], repo, octo1_ref));
- cl_git_pass(git_merge(&result, repo, (const git_merge_head **)&their_heads[0], 1, &opts));
+ cl_git_pass(git_merge(repo, (const git_merge_head **)&their_heads[0], 1, NULL, NULL));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
@@ -1019,7 +989,6 @@ void test_merge_workdir_setup__retained_after_success(void)
git_merge_head_free(our_head);
git_merge_head_free(their_heads[0]);
- git_merge_result_free(result);
}
void test_merge_workdir_setup__removed_after_failure(void)
@@ -1027,10 +996,6 @@ void test_merge_workdir_setup__removed_after_failure(void)
git_oid our_oid;
git_reference *octo1_ref;
git_merge_head *our_head, *their_heads[1];
- git_merge_result *result;
- git_merge_opts opts = GIT_MERGE_OPTS_INIT;
-
- opts.merge_flags |= GIT_MERGE_NO_FASTFORWARD;
cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
cl_git_pass(git_merge_head_from_id(&our_head, repo, &our_oid));
@@ -1042,7 +1007,7 @@ void test_merge_workdir_setup__removed_after_failure(void)
"Conflicting file!\n\nMerge will fail!\n");
cl_git_fail(git_merge(
- &result, repo, (const git_merge_head **)&their_heads[0], 1, &opts));
+ repo, (const git_merge_head **)&their_heads[0], 1, NULL, NULL));
cl_assert(!git_path_exists("merge-resolve/" GIT_MERGE_HEAD_FILE));
cl_assert(!git_path_exists("merge-resolve/" GIT_ORIG_HEAD_FILE));
@@ -1053,5 +1018,4 @@ void test_merge_workdir_setup__removed_after_failure(void)
git_merge_head_free(our_head);
git_merge_head_free(their_heads[0]);
- git_merge_result_free(result);
}
diff --git a/tests/merge/workdir/simple.c b/tests/merge/workdir/simple.c
index a9a6365..032e97f 100644
--- a/tests/merge/workdir/simple.c
+++ b/tests/merge/workdir/simple.c
@@ -71,47 +71,6 @@ static git_index *repo_index;
"", \
"5c3b68a71fc4fa5d362fd3875e53137c6a5ab7a5" }
-#define AUTOMERGEABLE_MERGED_FILE \
- "this file is changed in master\n" \
- "this file is automergeable\n" \
- "this file is automergeable\n" \
- "this file is automergeable\n" \
- "this file is automergeable\n" \
- "this file is automergeable\n" \
- "this file is automergeable\n" \
- "this file is automergeable\n" \
- "this file is changed in branch\n"
-
-#define AUTOMERGEABLE_MERGED_FILE_CRLF \
- "this file is changed in master\r\n" \
- "this file is automergeable\r\n" \
- "this file is automergeable\r\n" \
- "this file is automergeable\r\n" \
- "this file is automergeable\r\n" \
- "this file is automergeable\r\n" \
- "this file is automergeable\r\n" \
- "this file is automergeable\r\n" \
- "this file is changed in branch\r\n"
-
-#define CONFLICTING_MERGE_FILE \
- "<<<<<<< HEAD\n" \
- "this file is changed in master and branch\n" \
- "=======\n" \
- "this file is changed in branch and master\n" \
- ">>>>>>> 7cb63eed597130ba4abb87b3e544b85021905520\n"
-
-#define CONFLICTING_DIFF3_FILE \
- "<<<<<<< HEAD\n" \
- "this file is changed in master and branch\n" \
- "||||||| initial\n" \
- "this file is a conflict\n" \
- "=======\n" \
- "this file is changed in branch and master\n" \
- ">>>>>>> 7cb63eed597130ba4abb87b3e544b85021905520\n"
-
-#define CONFLICTING_UNION_FILE \
- "this file is changed in master and branch\n" \
- "this file is changed in branch and master\n"
// Fixture setup and teardown
void test_merge_workdir_simple__initialize(void)
@@ -133,23 +92,21 @@ void test_merge_workdir_simple__cleanup(void)
cl_git_sandbox_cleanup();
}
-static git_merge_result *merge_simple_branch(int merge_file_favor, int checkout_strategy)
+static void merge_simple_branch(int merge_file_favor, int checkout_strategy)
{
git_oid their_oids[1];
git_merge_head *their_heads[1];
- git_merge_result *result;
- git_merge_opts opts = GIT_MERGE_OPTS_INIT;
+ git_merge_options merge_opts = GIT_MERGE_OPTIONS_INIT;
+ git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
cl_git_pass(git_oid_fromstr(&their_oids[0], THEIRS_SIMPLE_OID));
cl_git_pass(git_merge_head_from_id(&their_heads[0], repo, &their_oids[0]));
- opts.merge_tree_opts.file_favor = merge_file_favor;
- opts.checkout_opts.checkout_strategy = checkout_strategy;
- cl_git_pass(git_merge(&result, repo, (const git_merge_head **)their_heads, 1, &opts));
+ merge_opts.file_favor = merge_file_favor;
+ checkout_opts.checkout_strategy = checkout_strategy;
+ cl_git_pass(git_merge(repo, (const git_merge_head **)their_heads, 1, &merge_opts, &checkout_opts));
git_merge_head_free(their_heads[0]);
-
- return result;
}
static void set_core_autocrlf_to(git_repository *repo, bool value)
@@ -166,7 +123,6 @@ void test_merge_workdir_simple__automerge(void)
{
git_index *index;
const git_index_entry *entry;
- git_merge_result *result;
git_buf automergeable_buf = GIT_BUF_INIT;
struct merge_index_entry merge_index_entries[] = {
@@ -191,8 +147,7 @@ void test_merge_workdir_simple__automerge(void)
set_core_autocrlf_to(repo, false);
- cl_assert(result = merge_simple_branch(0, 0));
- cl_assert(!git_merge_result_is_fastforward(result));
+ merge_simple_branch(0, 0);
cl_git_pass(git_futils_readbuffer(&automergeable_buf,
TEST_REPO_PATH "/automergeable.txt"));
@@ -202,8 +157,6 @@ void test_merge_workdir_simple__automerge(void)
cl_assert(merge_test_index(repo_index, merge_index_entries, 8));
cl_assert(merge_test_reuc(repo_index, merge_reuc_entries, 3));
- git_merge_result_free(result);
-
git_repository_index(&index, repo);
cl_assert((entry = git_index_get_bypath(index, "automergeable.txt", 0)) != NULL);
@@ -217,8 +170,6 @@ void test_merge_workdir_simple__automerge_crlf(void)
#ifdef GIT_WIN32
git_index *index;
const git_index_entry *entry;
-
- git_merge_result *result;
git_buf automergeable_buf = GIT_BUF_INIT;
struct merge_index_entry merge_index_entries[] = {
@@ -242,8 +193,7 @@ void test_merge_workdir_simple__automerge_crlf(void)
set_core_autocrlf_to(repo, true);
- cl_assert(result = merge_simple_branch(0, 0));
- cl_assert(!git_merge_result_is_fastforward(result));
+ merge_simple_branch(0, 0);
cl_git_pass(git_futils_readbuffer(&automergeable_buf,
TEST_REPO_PATH "/automergeable.txt"));
@@ -253,8 +203,6 @@ void test_merge_workdir_simple__automerge_crlf(void)
cl_assert(merge_test_index(repo_index, merge_index_entries, 8));
cl_assert(merge_test_reuc(repo_index, merge_reuc_entries, 3));
- git_merge_result_free(result);
-
git_repository_index(&index, repo);
cl_assert((entry = git_index_get_bypath(index, "automergeable.txt", 0)) != NULL);
@@ -266,7 +214,6 @@ void test_merge_workdir_simple__automerge_crlf(void)
void test_merge_workdir_simple__mergefile(void)
{
- git_merge_result *result;
git_buf conflicting_buf = GIT_BUF_INIT;
struct merge_index_entry merge_index_entries[] = {
@@ -288,8 +235,7 @@ void test_merge_workdir_simple__mergefile(void)
REMOVED_IN_MASTER_REUC_ENTRY
};
- cl_assert(result = merge_simple_branch(0, 0));
- cl_assert(!git_merge_result_is_fastforward(result));
+ merge_simple_branch(0, 0);
cl_git_pass(git_futils_readbuffer(&conflicting_buf,
TEST_REPO_PATH "/conflicting.txt"));
@@ -298,13 +244,10 @@ void test_merge_workdir_simple__mergefile(void)
cl_assert(merge_test_index(repo_index, merge_index_entries, 8));
cl_assert(merge_test_reuc(repo_index, merge_reuc_entries, 3));
-
- git_merge_result_free(result);
}
void test_merge_workdir_simple__diff3(void)
{
- git_merge_result *result;
git_buf conflicting_buf = GIT_BUF_INIT;
struct merge_index_entry merge_index_entries[] = {
@@ -326,8 +269,7 @@ void test_merge_workdir_simple__diff3(void)
REMOVED_IN_MASTER_REUC_ENTRY
};
- cl_assert(result = merge_simple_branch(0, GIT_CHECKOUT_CONFLICT_STYLE_DIFF3));
- cl_assert(!git_merge_result_is_fastforward(result));
+ merge_simple_branch(0, GIT_CHECKOUT_CONFLICT_STYLE_DIFF3);
cl_git_pass(git_futils_readbuffer(&conflicting_buf,
TEST_REPO_PATH "/conflicting.txt"));
@@ -336,13 +278,10 @@ void test_merge_workdir_simple__diff3(void)
cl_assert(merge_test_index(repo_index, merge_index_entries, 8));
cl_assert(merge_test_reuc(repo_index, merge_reuc_entries, 3));
-
- git_merge_result_free(result);
}
void test_merge_workdir_simple__union(void)
{
- git_merge_result *result;
git_buf conflicting_buf = GIT_BUF_INIT;
struct merge_index_entry merge_index_entries[] = {
@@ -365,8 +304,7 @@ void test_merge_workdir_simple__union(void)
set_core_autocrlf_to(repo, false);
- cl_assert(result = merge_simple_branch(GIT_MERGE_FILE_FAVOR_UNION, 0));
- cl_assert(!git_merge_result_is_fastforward(result));
+ merge_simple_branch(GIT_MERGE_FILE_FAVOR_UNION, 0);
cl_git_pass(git_futils_readbuffer(&conflicting_buf,
TEST_REPO_PATH "/conflicting.txt"));
@@ -375,13 +313,10 @@ void test_merge_workdir_simple__union(void)
cl_assert(merge_test_index(repo_index, merge_index_entries, 6));
cl_assert(merge_test_reuc(repo_index, merge_reuc_entries, 4));
-
- git_merge_result_free(result);
}
void test_merge_workdir_simple__diff3_from_config(void)
{
- git_merge_result *result;
git_config *config;
git_buf conflicting_buf = GIT_BUF_INIT;
@@ -407,8 +342,7 @@ void test_merge_workdir_simple__diff3_from_config(void)
cl_git_pass(git_repository_config(&config, repo));
cl_git_pass(git_config_set_string(config, "merge.conflictstyle", "diff3"));
- cl_assert(result = merge_simple_branch(0, 0));
- cl_assert(!git_merge_result_is_fastforward(result));
+ merge_simple_branch(0, 0);
cl_git_pass(git_futils_readbuffer(&conflicting_buf,
TEST_REPO_PATH "/conflicting.txt"));
@@ -418,13 +352,11 @@ void test_merge_workdir_simple__diff3_from_config(void)
cl_assert(merge_test_index(repo_index, merge_index_entries, 8));
cl_assert(merge_test_reuc(repo_index, merge_reuc_entries, 3));
- git_merge_result_free(result);
git_config_free(config);
}
void test_merge_workdir_simple__merge_overrides_config(void)
{
- git_merge_result *result;
git_config *config;
git_buf conflicting_buf = GIT_BUF_INIT;
@@ -450,8 +382,7 @@ void test_merge_workdir_simple__merge_overrides_config(void)
cl_git_pass(git_repository_config(&config, repo));
cl_git_pass(git_config_set_string(config, "merge.conflictstyle", "diff3"));
- cl_assert(result = merge_simple_branch(0, GIT_CHECKOUT_CONFLICT_STYLE_MERGE));
- cl_assert(!git_merge_result_is_fastforward(result));
+ merge_simple_branch(0, GIT_CHECKOUT_CONFLICT_STYLE_MERGE);
cl_git_pass(git_futils_readbuffer(&conflicting_buf,
TEST_REPO_PATH "/conflicting.txt"));
@@ -461,14 +392,11 @@ void test_merge_workdir_simple__merge_overrides_config(void)
cl_assert(merge_test_index(repo_index, merge_index_entries, 8));
cl_assert(merge_test_reuc(repo_index, merge_reuc_entries, 3));
- git_merge_result_free(result);
git_config_free(config);
}
void test_merge_workdir_simple__checkout_ours(void)
{
- git_merge_result *result;
-
struct merge_index_entry merge_index_entries[] = {
ADDED_IN_MASTER_INDEX_ENTRY,
AUTOMERGEABLE_INDEX_ENTRY,
@@ -488,21 +416,16 @@ void test_merge_workdir_simple__checkout_ours(void)
REMOVED_IN_MASTER_REUC_ENTRY
};
- cl_assert(result = merge_simple_branch(0, GIT_CHECKOUT_SAFE | GIT_CHECKOUT_USE_OURS));
- cl_assert(!git_merge_result_is_fastforward(result));
+ merge_simple_branch(0, GIT_CHECKOUT_SAFE | GIT_CHECKOUT_USE_OURS);
cl_assert(merge_test_index(repo_index, merge_index_entries, 8));
cl_assert(merge_test_reuc(repo_index, merge_reuc_entries, 3));
cl_assert(git_path_exists(TEST_REPO_PATH "/conflicting.txt"));
-
- git_merge_result_free(result);
}
void test_merge_workdir_simple__favor_ours(void)
{
- git_merge_result *result;
-
struct merge_index_entry merge_index_entries[] = {
ADDED_IN_MASTER_INDEX_ENTRY,
AUTOMERGEABLE_INDEX_ENTRY,
@@ -519,19 +442,14 @@ void test_merge_workdir_simple__favor_ours(void)
REMOVED_IN_MASTER_REUC_ENTRY,
};
- cl_assert(result = merge_simple_branch(GIT_MERGE_FILE_FAVOR_OURS, 0));
- cl_assert(!git_merge_result_is_fastforward(result));
+ merge_simple_branch(GIT_MERGE_FILE_FAVOR_OURS, 0);
cl_assert(merge_test_index(repo_index, merge_index_entries, 6));
cl_assert(merge_test_reuc(repo_index, merge_reuc_entries, 4));
-
- git_merge_result_free(result);
}
void test_merge_workdir_simple__favor_theirs(void)
{
- git_merge_result *result;
-
struct merge_index_entry merge_index_entries[] = {
ADDED_IN_MASTER_INDEX_ENTRY,
AUTOMERGEABLE_INDEX_ENTRY,
@@ -548,13 +466,10 @@ void test_merge_workdir_simple__favor_theirs(void)
REMOVED_IN_MASTER_REUC_ENTRY,
};
- cl_assert(result = merge_simple_branch(GIT_MERGE_FILE_FAVOR_THEIRS, 0));
- cl_assert(!git_merge_result_is_fastforward(result));
+ merge_simple_branch(GIT_MERGE_FILE_FAVOR_THEIRS, 0);
cl_assert(merge_test_index(repo_index, merge_index_entries, 6));
cl_assert(merge_test_reuc(repo_index, merge_reuc_entries, 4));
-
- git_merge_result_free(result);
}
void test_merge_workdir_simple__directory_file(void)
@@ -562,8 +477,7 @@ void test_merge_workdir_simple__directory_file(void)
git_reference *head;
git_oid their_oids[1], head_commit_id;
git_merge_head *their_heads[1];
- git_merge_result *result;
- git_merge_opts opts = GIT_MERGE_OPTS_INIT;
+ git_merge_options merge_opts = GIT_MERGE_OPTIONS_INIT;
git_commit *head_commit;
struct merge_index_entry merge_index_entries[] = {
@@ -597,23 +511,21 @@ void test_merge_workdir_simple__directory_file(void)
cl_git_pass(git_oid_fromstr(&their_oids[0], THEIRS_DIRECTORY_FILE));
cl_git_pass(git_merge_head_from_id(&their_heads[0], repo, &their_oids[0]));
- opts.merge_tree_opts.file_favor = 0;
- cl_git_pass(git_merge(&result, repo, (const git_merge_head **)their_heads, 1, &opts));
+ merge_opts.file_favor = 0;
+ cl_git_pass(git_merge(repo, (const git_merge_head **)their_heads, 1, &merge_opts, NULL));
cl_assert(merge_test_index(repo_index, merge_index_entries, 20));
git_reference_free(head);
git_commit_free(head_commit);
git_merge_head_free(their_heads[0]);
- git_merge_result_free(result);
}
void test_merge_workdir_simple__unrelated(void)
{
git_oid their_oids[1];
git_merge_head *their_heads[1];
- git_merge_result *result;
- git_merge_opts opts = GIT_MERGE_OPTS_INIT;
+ git_merge_options merge_opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "233c0919c998ed110a4b6ff36f353aec8b713487", 0, "added-in-master.txt" },
@@ -630,21 +542,19 @@ void test_merge_workdir_simple__unrelated(void)
cl_git_pass(git_oid_fromstr(&their_oids[0], THEIRS_UNRELATED_PARENT));
cl_git_pass(git_merge_head_from_id(&their_heads[0], repo, &their_oids[0]));
- opts.merge_tree_opts.file_favor = 0;
- cl_git_pass(git_merge(&result, repo, (const git_merge_head **)their_heads, 1, &opts));
+ merge_opts.file_favor = 0;
+ cl_git_pass(git_merge(repo, (const git_merge_head **)their_heads, 1, &merge_opts, NULL));
cl_assert(merge_test_index(repo_index, merge_index_entries, 9));
git_merge_head_free(their_heads[0]);
- git_merge_result_free(result);
}
void test_merge_workdir_simple__unrelated_with_conflicts(void)
{
git_oid their_oids[1];
git_merge_head *their_heads[1];
- git_merge_result *result;
- git_merge_opts opts = GIT_MERGE_OPTS_INIT;
+ git_merge_options merge_opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "233c0919c998ed110a4b6ff36f353aec8b713487", 0, "added-in-master.txt" },
@@ -663,13 +573,12 @@ void test_merge_workdir_simple__unrelated_with_conflicts(void)
cl_git_pass(git_oid_fromstr(&their_oids[0], THEIRS_UNRELATED_OID));
cl_git_pass(git_merge_head_from_id(&their_heads[0], repo, &their_oids[0]));
- opts.merge_tree_opts.file_favor = 0;
- cl_git_pass(git_merge(&result, repo, (const git_merge_head **)their_heads, 1, &opts));
+ merge_opts.file_favor = 0;
+ cl_git_pass(git_merge(repo, (const git_merge_head **)their_heads, 1, &merge_opts, NULL));
cl_assert(merge_test_index(repo_index, merge_index_entries, 11));
git_merge_head_free(their_heads[0]);
- git_merge_result_free(result);
}
void test_merge_workdir_simple__binary(void)
@@ -677,9 +586,7 @@ void test_merge_workdir_simple__binary(void)
git_oid our_oid, their_oid, our_file_oid;
git_commit *our_commit;
git_merge_head *their_head;
- git_merge_result *result;
const git_index_entry *binary_entry;
- git_merge_opts opts = GIT_MERGE_OPTS_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "1c51d885170f57a0c4e8c69ff6363d91a5b51f85", 1, "binary" },
@@ -695,7 +602,7 @@ void test_merge_workdir_simple__binary(void)
cl_git_pass(git_merge_head_from_id(&their_head, repo, &their_oid));
- cl_git_pass(git_merge(&result, repo, (const git_merge_head **)&their_head, 1, &opts));
+ cl_git_pass(git_merge(repo, (const git_merge_head **)&their_head, 1, NULL, NULL));
cl_assert(merge_test_index(repo_index, merge_index_entries, 3));
@@ -706,6 +613,5 @@ void test_merge_workdir_simple__binary(void)
cl_assert(git_oid_cmp(&binary_entry->id, &our_file_oid) == 0);
git_merge_head_free(their_head);
- git_merge_result_free(result);
git_commit_free(our_commit);
}
diff --git a/tests/merge/workdir/submodules.c b/tests/merge/workdir/submodules.c
index 42451bd..e093e77 100644
--- a/tests/merge/workdir/submodules.c
+++ b/tests/merge/workdir/submodules.c
@@ -31,8 +31,6 @@ void test_merge_workdir_submodules__automerge(void)
git_reference *our_ref, *their_ref;
git_commit *our_commit;
git_merge_head *their_head;
- git_merge_result *result;
- git_merge_opts opts = GIT_MERGE_OPTS_INIT;
git_index *index;
struct merge_index_entry merge_index_entries[] = {
@@ -51,13 +49,12 @@ void test_merge_workdir_submodules__automerge(void)
cl_git_pass(git_reference_lookup(&their_ref, repo, "refs/heads/" SUBMODULE_OTHER_BRANCH));
cl_git_pass(git_merge_head_from_ref(&their_head, repo, their_ref));
- cl_git_pass(git_merge(&result, repo, (const git_merge_head **)&their_head, 1, &opts));
+ cl_git_pass(git_merge(repo, (const git_merge_head **)&their_head, 1, NULL, NULL));
cl_git_pass(git_repository_index(&index, repo));
cl_assert(merge_test_index(index, merge_index_entries, 6));
git_index_free(index);
- git_merge_result_free(result);
git_merge_head_free(their_head);
git_commit_free(our_commit);
git_reference_free(their_ref);
@@ -69,8 +66,6 @@ void test_merge_workdir_submodules__take_changed(void)
git_reference *our_ref, *their_ref;
git_commit *our_commit;
git_merge_head *their_head;
- git_merge_result *result;
- git_merge_opts opts = GIT_MERGE_OPTS_INIT;
git_index *index;
struct merge_index_entry merge_index_entries[] = {
@@ -87,13 +82,12 @@ void test_merge_workdir_submodules__take_changed(void)
cl_git_pass(git_reference_lookup(&their_ref, repo, "refs/heads/" SUBMODULE_OTHER2_BRANCH));
cl_git_pass(git_merge_head_from_ref(&their_head, repo, their_ref));
- cl_git_pass(git_merge(&result, repo, (const git_merge_head **)&their_head, 1, &opts));
+ cl_git_pass(git_merge(repo, (const git_merge_head **)&their_head, 1, NULL, NULL));
cl_git_pass(git_repository_index(&index, repo));
cl_assert(merge_test_index(index, merge_index_entries, 4));
git_index_free(index);
- git_merge_result_free(result);
git_merge_head_free(their_head);
git_commit_free(our_commit);
git_reference_free(their_ref);
diff --git a/tests/merge/workdir/trivial.c b/tests/merge/workdir/trivial.c
index 8b0d328..cc82d99 100644
--- a/tests/merge/workdir/trivial.c
+++ b/tests/merge/workdir/trivial.c
@@ -34,8 +34,6 @@ static int merge_trivial(const char *ours, const char *theirs)
git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
git_reference *our_ref, *their_ref;
git_merge_head *their_heads[1];
- git_merge_opts opts = GIT_MERGE_OPTS_INIT;
- git_merge_result *result;
checkout_opts.checkout_strategy = GIT_CHECKOUT_FORCE;
@@ -49,13 +47,12 @@ static int merge_trivial(const char *ours, const char *theirs)
cl_git_pass(git_reference_lookup(&their_ref, repo, branch_buf.ptr));
cl_git_pass(git_merge_head_from_ref(&their_heads[0], repo, their_ref));
- cl_git_pass(git_merge(&result, repo, (const git_merge_head **)their_heads, 1, &opts));
+ cl_git_pass(git_merge(repo, (const git_merge_head **)their_heads, 1, NULL, NULL));
git_buf_free(&branch_buf);
git_reference_free(our_ref);
git_reference_free(their_ref);
git_merge_head_free(their_heads[0]);
- git_merge_result_free(result);
return 0;
}
diff --git a/tests/resources/merge-resolve/.gitted/refs/heads/previous b/tests/resources/merge-resolve/.gitted/refs/heads/previous
new file mode 100644
index 0000000..7bc1a8d
--- /dev/null
+++ b/tests/resources/merge-resolve/.gitted/refs/heads/previous
@@ -0,0 +1 @@
+c607fc30883e335def28cd686b51f6cfa02b06ec
diff --git a/tests/revert/workdir.c b/tests/revert/workdir.c
index afbdffe..694f247 100644
--- a/tests/revert/workdir.c
+++ b/tests/revert/workdir.c
@@ -398,8 +398,8 @@ void test_revert_workdir__rename_1_of_2(void)
{ 0100644, "0f5bfcf58c558d865da6be0281d7795993646cee", 2, "file6.txt" },
};
- opts.merge_tree_opts.flags |= GIT_MERGE_TREE_FIND_RENAMES;
- opts.merge_tree_opts.rename_threshold = 50;
+ opts.merge_opts.flags |= GIT_MERGE_TREE_FIND_RENAMES;
+ opts.merge_opts.rename_threshold = 50;
git_oid_fromstr(&head_oid, "cef56612d71a6af8d8015691e4865f7fece905b5");
cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
@@ -432,8 +432,8 @@ void test_revert_workdir__rename(void)
{ "file4.txt", "file5.txt", "" },
};
- opts.merge_tree_opts.flags |= GIT_MERGE_TREE_FIND_RENAMES;
- opts.merge_tree_opts.rename_threshold = 50;
+ opts.merge_opts.flags |= GIT_MERGE_TREE_FIND_RENAMES;
+ opts.merge_opts.rename_threshold = 50;
git_oid_fromstr(&head_oid, "55568c8de5322ff9a95d72747a239cdb64a19965");
cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
diff --git a/tests/structinit/structinit.c b/tests/structinit/structinit.c
index 1df970d..2942099 100644
--- a/tests/structinit/structinit.c
+++ b/tests/structinit/structinit.c
@@ -65,15 +65,20 @@ void test_structinit_structinit__compare(void)
git_diff_find_options, GIT_DIFF_FIND_OPTIONS_VERSION, \
GIT_DIFF_FIND_OPTIONS_INIT, git_diff_find_init_options);
- /* merge_tree */
+ /* merge_file_input */
+ CHECK_MACRO_FUNC_INIT_EQUAL( \
+ git_merge_file_input, GIT_MERGE_FILE_INPUT_VERSION, \
+ GIT_MERGE_FILE_INPUT_INIT, git_merge_file_init_input);
+
+ /* merge_file */
CHECK_MACRO_FUNC_INIT_EQUAL( \
- git_merge_tree_opts, GIT_MERGE_TREE_OPTS_VERSION, \
- GIT_MERGE_TREE_OPTS_INIT, git_merge_tree_init_opts);
+ git_merge_file_options, GIT_MERGE_FILE_OPTIONS_VERSION, \
+ GIT_MERGE_FILE_OPTIONS_INIT, git_merge_file_init_options);
- /* merge */
+ /* merge_tree */
CHECK_MACRO_FUNC_INIT_EQUAL( \
- git_merge_opts, GIT_MERGE_OPTS_VERSION, \
- GIT_MERGE_OPTS_INIT, git_merge_init_opts);
+ git_merge_options, GIT_MERGE_OPTIONS_VERSION, \
+ GIT_MERGE_OPTIONS_INIT, git_merge_init_options);
/* push */
CHECK_MACRO_FUNC_INIT_EQUAL( \