Merge pull request #2061 from ethomson/merge_improvements Merge improvements
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
diff --git a/include/git2/checkout.h b/include/git2/checkout.h
index b94a5e2..0faf4ab 100644
--- a/include/git2/checkout.h
+++ b/include/git2/checkout.h
@@ -152,6 +152,12 @@ typedef enum {
/** Don't overwrite ignored files that exist in the checkout target */
GIT_CHECKOUT_DONT_OVERWRITE_IGNORED = (1u << 19),
+ /** Write normal merge files for conflicts */
+ GIT_CHECKOUT_CONFLICT_STYLE_MERGE = (1u << 20),
+
+ /** Include common ancestor data in diff3 format files for conflicts */
+ GIT_CHECKOUT_CONFLICT_STYLE_DIFF3 = (1u << 21),
+
/**
* THE FOLLOWING OPTIONS ARE NOT YET IMPLEMENTED
*/
@@ -252,6 +258,7 @@ typedef struct git_checkout_opts {
const char *target_directory; /** alternative checkout path to workdir */
+ const char *ancestor_label; /** the name of the common ancestor side of conflicts */
const char *our_label; /** the name of the "our" side of conflicts */
const char *their_label; /** the name of the "their" side of conflicts */
} git_checkout_opts;
diff --git a/include/git2/merge.h b/include/git2/merge.h
index 8a1dfec..ad9b5e2 100644
--- a/include/git2/merge.h
+++ b/include/git2/merge.h
@@ -32,14 +32,21 @@ typedef enum {
} git_merge_tree_flag_t;
/**
- * Automerge options for `git_merge_trees_opts`.
+ * Merge file options for `git_merge_trees_opts`.
*/
typedef enum {
- GIT_MERGE_AUTOMERGE_NORMAL = 0,
- GIT_MERGE_AUTOMERGE_NONE = 1,
- GIT_MERGE_AUTOMERGE_FAVOR_OURS = 2,
- GIT_MERGE_AUTOMERGE_FAVOR_THEIRS = 3,
-} git_merge_automerge_flags;
+ /* Produce a conflict in a file when two similar regions are changed. */
+ GIT_MERGE_FILE_FAVOR_NORMAL = 0,
+
+ /* Produce a file containing the "ours" side of conflicting regions. */
+ GIT_MERGE_FILE_FAVOR_OURS = 1,
+
+ /* Produce a file containing the "theirs" side of conflicting regions. */
+ GIT_MERGE_FILE_FAVOR_THEIRS = 2,
+
+ /* Produce a file blending the sides in a union of conflicting regions */
+ GIT_MERGE_FILE_FAVOR_UNION = 3,
+} git_merge_file_favor_t;
typedef struct {
@@ -58,7 +65,7 @@ typedef struct {
git_diff_similarity_metric *metric;
/** Flags for automerging content. */
- git_merge_automerge_flags automerge_flags;
+ git_merge_file_favor_t file_favor;
} git_merge_tree_opts;
#define GIT_MERGE_TREE_OPTS_VERSION 1
diff --git a/src/checkout.c b/src/checkout.c
index e642c97..cfb0e72 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -70,7 +70,9 @@ typedef struct {
int name_collision:1,
directoryfile:1,
- one_to_two:1;
+ one_to_two:1,
+ binary:1,
+ submodule:1;
} checkout_conflictdata;
static int checkout_notify(
@@ -681,6 +683,51 @@ GIT_INLINE(bool) conflict_pathspec_match(
return false;
}
+GIT_INLINE(int) checkout_conflict_detect_submodule(checkout_conflictdata *conflict)
+{
+ conflict->submodule = ((conflict->ancestor && S_ISGITLINK(conflict->ancestor->mode)) ||
+ (conflict->ours && S_ISGITLINK(conflict->ours->mode)) ||
+ (conflict->theirs && S_ISGITLINK(conflict->theirs->mode)));
+ return 0;
+}
+
+GIT_INLINE(int) checkout_conflict_detect_binary(git_repository *repo, checkout_conflictdata *conflict)
+{
+ git_blob *ancestor_blob = NULL, *our_blob = NULL, *their_blob = NULL;
+ int error = 0;
+
+ if (conflict->submodule)
+ return 0;
+
+ if (conflict->ancestor) {
+ if ((error = git_blob_lookup(&ancestor_blob, repo, &conflict->ancestor->oid)) < 0)
+ goto done;
+
+ conflict->binary = git_blob_is_binary(ancestor_blob);
+ }
+
+ if (!conflict->binary && conflict->ours) {
+ if ((error = git_blob_lookup(&our_blob, repo, &conflict->ours->oid)) < 0)
+ goto done;
+
+ conflict->binary = git_blob_is_binary(our_blob);
+ }
+
+ if (!conflict->binary && conflict->theirs) {
+ if ((error = git_blob_lookup(&their_blob, repo, &conflict->theirs->oid)) < 0)
+ goto done;
+
+ conflict->binary = git_blob_is_binary(their_blob);
+ }
+
+done:
+ git_blob_free(ancestor_blob);
+ git_blob_free(our_blob);
+ git_blob_free(their_blob);
+
+ return error;
+}
+
static int checkout_conflicts_load(checkout_data *data, git_iterator *workdir, git_vector *pathspec)
{
git_index_conflict_iterator *iterator = NULL;
@@ -705,6 +752,10 @@ static int checkout_conflicts_load(checkout_data *data, git_iterator *workdir, g
conflict->ours = ours;
conflict->theirs = theirs;
+ if ((error = checkout_conflict_detect_submodule(conflict)) < 0 ||
+ (error = checkout_conflict_detect_binary(data->repo, conflict)) < 0)
+ goto done;
+
git_vector_insert(&data->conflicts, conflict);
}
@@ -1626,6 +1677,7 @@ 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;
@@ -1633,6 +1685,9 @@ static int checkout_write_merge(
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) ||
@@ -1642,7 +1697,7 @@ static int checkout_write_merge(
&theirs, data->repo, conflict->theirs)) < 0)
goto done;
- ancestor.label = NULL;
+ 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";
@@ -1662,7 +1717,7 @@ static int checkout_write_merge(
theirs.label = git_buf_cstr(&their_label);
}
- if ((error = git_merge_files(&result, &ancestor, &ours, &theirs, 0)) < 0)
+ if ((error = git_merge_files(&result, &ancestor, &ours, &theirs, &merge_file_opts)) < 0)
goto done;
if (result.path == NULL || result.mode == 0) {
@@ -1705,6 +1760,7 @@ static int checkout_create_conflicts(checkout_data *data)
int error = 0;
git_vector_foreach(&data->conflicts, i, conflict) {
+
/* Both deleted: nothing to do */
if (conflict->ours == NULL && conflict->theirs == NULL)
error = 0;
@@ -1748,7 +1804,15 @@ static int checkout_create_conflicts(checkout_data *data)
else if (S_ISLNK(conflict->theirs->mode))
error = checkout_write_entry(data, conflict, conflict->ours);
- else
+ /* If any side is a gitlink, do nothing. */
+ else if (conflict->submodule)
+ error = 0;
+
+ /* If any side is binary, write the ours side */
+ else if (conflict->binary)
+ error = checkout_write_entry(data, conflict, conflict->ours);
+
+ else if (!error)
error = checkout_write_merge(data, conflict);
if (error)
@@ -1891,6 +1955,29 @@ static int checkout_data_init(
goto cleanup;
}
+ if ((data->opts.checkout_strategy &
+ (GIT_CHECKOUT_CONFLICT_STYLE_MERGE | GIT_CHECKOUT_CONFLICT_STYLE_DIFF3)) == 0) {
+ const char *conflict_style;
+ git_config *cfg = NULL;
+
+ if ((error = git_repository_config__weakptr(&cfg, repo)) < 0 ||
+ (error = git_config_get_string(&conflict_style, cfg, "merge.conflictstyle")) < 0 ||
+ error == GIT_ENOTFOUND)
+ ;
+ else if (error)
+ goto cleanup;
+ else if (strcmp(conflict_style, "merge") == 0)
+ data->opts.checkout_strategy |= GIT_CHECKOUT_CONFLICT_STYLE_MERGE;
+ else if (strcmp(conflict_style, "diff3") == 0)
+ data->opts.checkout_strategy |= GIT_CHECKOUT_CONFLICT_STYLE_DIFF3;
+ else {
+ giterr_set(GITERR_CHECKOUT, "unknown style '%s' given for 'merge.conflictstyle'",
+ conflict_style);
+ error = -1;
+ goto cleanup;
+ }
+ }
+
if ((error = git_vector_init(&data->removes, 0, git__strcmp_cb)) < 0 ||
(error = git_vector_init(&data->conflicts, 0, NULL)) < 0 ||
(error = git_pool_init(&data->pool, 1, 0)) < 0 ||
diff --git a/src/merge.c b/src/merge.c
index c0be37d..2fb1c58 100644
--- a/src/merge.c
+++ b/src/merge.c
@@ -42,6 +42,7 @@
#include "git2/sys/index.h"
#define GIT_MERGE_INDEX_ENTRY_EXISTS(X) ((X).mode != 0)
+#define GIT_MERGE_INDEX_ENTRY_ISFILE(X) S_ISREG((X).mode)
typedef enum {
TREE_IDX_ANCESTOR = 0,
@@ -447,7 +448,6 @@ static int merge_conflict_resolve_one_removed(
return error;
}
-
static int merge_conflict_resolve_one_renamed(
int *resolved,
git_merge_diff_list *diff_list,
@@ -511,8 +511,9 @@ static int merge_conflict_resolve_automerge(
int *resolved,
git_merge_diff_list *diff_list,
const git_merge_diff *conflict,
- unsigned int automerge_flags)
+ 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;
@@ -526,13 +527,18 @@ static int merge_conflict_resolve_automerge(
*resolved = 0;
- if (automerge_flags == GIT_MERGE_AUTOMERGE_NONE)
- return 0;
+ merge_file_opts.favor = merge_file_favor;
/* Reject D/F conflicts */
if (conflict->type == GIT_MERGE_DIFF_DIRECTORY_FILE)
return 0;
+ /* Reject submodules. */
+ if (S_ISGITLINK(conflict->ancestor_entry.mode) ||
+ S_ISGITLINK(conflict->our_entry.mode) ||
+ S_ISGITLINK(conflict->their_entry.mode))
+ return 0;
+
/* Reject link/file conflicts. */
if ((S_ISLNK(conflict->ancestor_entry.mode) ^ S_ISLNK(conflict->our_entry.mode)) ||
(S_ISLNK(conflict->ancestor_entry.mode) ^ S_ISLNK(conflict->their_entry.mode)))
@@ -548,11 +554,15 @@ static int merge_conflict_resolve_automerge(
strcmp(conflict->ancestor_entry.path, conflict->their_entry.path) != 0)
return 0;
+ /* Reject binary conflicts */
+ if (conflict->binary)
+ return 0;
+
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, automerge_flags)) < 0 ||
+ (error = git_merge_files(&result, &ancestor, &ours, &theirs, &merge_file_opts)) < 0 ||
!result.automergeable ||
(error = git_odb_write(&automerge_oid, odb, result.data, result.len, GIT_OBJ_BLOB)) < 0)
goto done;
@@ -586,7 +596,7 @@ static int merge_conflict_resolve(
int *out,
git_merge_diff_list *diff_list,
const git_merge_diff *conflict,
- unsigned int automerge_flags)
+ unsigned int merge_file_favor)
{
int resolved = 0;
int error = 0;
@@ -596,16 +606,14 @@ static int merge_conflict_resolve(
if ((error = merge_conflict_resolve_trivial(&resolved, diff_list, conflict)) < 0)
goto done;
- if (automerge_flags != GIT_MERGE_AUTOMERGE_NONE) {
- if (!resolved && (error = merge_conflict_resolve_one_removed(&resolved, diff_list, conflict)) < 0)
- goto done;
+ if (!resolved && (error = merge_conflict_resolve_one_removed(&resolved, diff_list, conflict)) < 0)
+ goto done;
- if (!resolved && (error = merge_conflict_resolve_one_renamed(&resolved, diff_list, conflict)) < 0)
- goto done;
+ if (!resolved && (error = merge_conflict_resolve_one_renamed(&resolved, diff_list, conflict)) < 0)
+ goto done;
- if (!resolved && (error = merge_conflict_resolve_automerge(&resolved, diff_list, conflict, automerge_flags)) < 0)
- goto done;
- }
+ if (!resolved && (error = merge_conflict_resolve_automerge(&resolved, diff_list, conflict, merge_file_favor)) < 0)
+ goto done;
*out = resolved;
@@ -1147,6 +1155,44 @@ GIT_INLINE(int) merge_diff_detect_type(
return 0;
}
+GIT_INLINE(int) merge_diff_detect_binary(
+ git_repository *repo,
+ git_merge_diff *conflict)
+{
+ git_blob *ancestor_blob = NULL, *our_blob = NULL, *their_blob = NULL;
+ int error = 0;
+
+ if (GIT_MERGE_INDEX_ENTRY_ISFILE(conflict->ancestor_entry)) {
+ if ((error = git_blob_lookup(&ancestor_blob, repo, &conflict->ancestor_entry.oid)) < 0)
+ goto done;
+
+ conflict->binary = git_blob_is_binary(ancestor_blob);
+ }
+
+ if (!conflict->binary &&
+ GIT_MERGE_INDEX_ENTRY_ISFILE(conflict->our_entry)) {
+ if ((error = git_blob_lookup(&our_blob, repo, &conflict->our_entry.oid)) < 0)
+ goto done;
+
+ conflict->binary = git_blob_is_binary(our_blob);
+ }
+
+ if (!conflict->binary &&
+ GIT_MERGE_INDEX_ENTRY_ISFILE(conflict->their_entry)) {
+ if ((error = git_blob_lookup(&their_blob, repo, &conflict->their_entry.oid)) < 0)
+ goto done;
+
+ conflict->binary = git_blob_is_binary(their_blob);
+ }
+
+done:
+ git_blob_free(ancestor_blob);
+ git_blob_free(our_blob);
+ git_blob_free(their_blob);
+
+ return error;
+}
+
GIT_INLINE(int) index_entry_dup(
git_index_entry *out,
git_pool *pool,
@@ -1218,6 +1264,7 @@ static int merge_diff_list_insert_conflict(
if ((conflict = merge_diff_from_index_entries(diff_list, tree_items)) == NULL ||
merge_diff_detect_type(conflict) < 0 ||
merge_diff_detect_df_conflict(merge_df_data, conflict) < 0 ||
+ merge_diff_detect_binary(diff_list->repo, conflict) < 0 ||
git_vector_insert(&diff_list->conflicts, conflict) < 0)
return -1;
@@ -1589,7 +1636,7 @@ int git_merge_trees(
git_vector_foreach(&changes, i, conflict) {
int resolved = 0;
- if ((error = merge_conflict_resolve(&resolved, diff_list, conflict, opts.automerge_flags)) < 0)
+ if ((error = merge_conflict_resolve(&resolved, diff_list, conflict, opts.file_favor)) < 0)
goto done;
if (!resolved)
@@ -2119,6 +2166,8 @@ static int merge_normalize_opts(
git_repository *repo,
git_merge_opts *opts,
const git_merge_opts *given,
+ const git_merge_head *ancestor_head,
+ const git_merge_head *our_head,
size_t their_heads_len,
const git_merge_head **their_heads)
{
@@ -2138,8 +2187,20 @@ static int merge_normalize_opts(
if (!opts->checkout_opts.checkout_strategy)
opts->checkout_opts.checkout_strategy = default_checkout_strategy;
- if (!opts->checkout_opts.our_label)
- opts->checkout_opts.our_label = "HEAD";
+ /* TODO: for multiple ancestors in merge-recursive, this is "merged common ancestors" */
+ if (!opts->checkout_opts.ancestor_label) {
+ if (ancestor_head && ancestor_head->commit)
+ opts->checkout_opts.ancestor_label = git_commit_summary(ancestor_head->commit);
+ else
+ opts->checkout_opts.ancestor_label = "ancestor";
+ }
+
+ if (!opts->checkout_opts.our_label) {
+ if (our_head && our_head->ref_name)
+ opts->checkout_opts.our_label = our_head->ref_name;
+ else
+ opts->checkout_opts.our_label = "ours";
+ }
if (!opts->checkout_opts.their_label) {
if (their_heads_len == 1 && their_heads[0]->ref_name)
@@ -2434,9 +2495,6 @@ int git_merge(
their_trees = git__calloc(their_heads_len, sizeof(git_tree *));
GITERR_CHECK_ALLOC(their_trees);
- if ((error = merge_normalize_opts(repo, &opts, given_opts, their_heads_len, their_heads)) < 0)
- goto on_error;
-
if ((error = git_repository__ensure_not_bare(repo, "merge")) < 0)
goto on_error;
@@ -2448,6 +2506,9 @@ int git_merge(
error != GIT_ENOTFOUND)
goto on_error;
+ if ((error = merge_normalize_opts(repo, &opts, given_opts, ancestor_head, our_head, their_heads_len, their_heads)) < 0)
+ goto on_error;
+
if (their_heads_len == 1 &&
ancestor_head != NULL &&
(merge_check_uptodate(result, ancestor_head, their_heads[0]) ||
diff --git a/src/merge.h b/src/merge.h
index b240f6c..dda0235 100644
--- a/src/merge.h
+++ b/src/merge.h
@@ -106,6 +106,8 @@ typedef struct {
git_index_entry their_entry;
git_delta_t their_status;
+
+ int binary:1;
} git_merge_diff;
/** Internal structure for merge inputs */
diff --git a/src/merge_file.c b/src/merge_file.c
index 48fc46e..9961ef2 100644
--- a/src/merge_file.c
+++ b/src/merge_file.c
@@ -130,7 +130,7 @@ int git_merge_files(
git_merge_file_input *ancestor,
git_merge_file_input *ours,
git_merge_file_input *theirs,
- git_merge_automerge_flags flags)
+ git_merge_file_options *opts)
{
xmparam_t xmparam;
mmbuffer_t mmbuffer;
@@ -152,11 +152,19 @@ int git_merge_files(
out->path = merge_file_best_path(ancestor, ours, theirs);
out->mode = merge_file_best_mode(ancestor, ours, theirs);
- if (flags == GIT_MERGE_AUTOMERGE_FAVOR_OURS)
+ if (opts && opts->favor == GIT_MERGE_FILE_FAVOR_OURS)
xmparam.favor = XDL_MERGE_FAVOR_OURS;
-
- if (flags == GIT_MERGE_AUTOMERGE_FAVOR_THEIRS)
+ else if (opts && opts->favor == GIT_MERGE_FILE_FAVOR_THEIRS)
xmparam.favor = XDL_MERGE_FAVOR_THEIRS;
+ else if (opts && opts->favor == GIT_MERGE_FILE_FAVOR_UNION)
+ xmparam.favor = XDL_MERGE_FAVOR_UNION;
+
+ xmparam.level =
+ (opts && (opts->flags & GIT_MERGE_FILE_SIMPLIFY_ALNUM)) ?
+ XDL_MERGE_ZEALOUS_ALNUM : XDL_MERGE_ZEALOUS;
+
+ if (opts && opts->style == GIT_MERGE_FILE_STYLE_DIFF3)
+ xmparam.style = XDL_MERGE_DIFF3;
if ((xdl_result = xdl_merge(&ancestor->mmfile, &ours->mmfile,
&theirs->mmfile, &xmparam, &mmbuffer)) < 0) {
diff --git a/src/merge_file.h b/src/merge_file.h
index 0af2f0a..332be49 100644
--- a/src/merge_file.h
+++ b/src/merge_file.h
@@ -34,6 +34,27 @@ typedef struct {
#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,
@@ -49,7 +70,7 @@ int git_merge_files(
git_merge_file_input *ancestor,
git_merge_file_input *ours,
git_merge_file_input *theirs,
- git_merge_automerge_flags flags);
+ git_merge_file_options *opts);
GIT_INLINE(void) git_merge_file_input_free(git_merge_file_input *input)
{
diff --git a/tests/merge/trees/automerge.c b/tests/merge/trees/automerge.c
index 746ce50..ebc6e27 100644
--- a/tests/merge/trees/automerge.c
+++ b/tests/merge/trees/automerge.c
@@ -149,7 +149,7 @@ void test_merge_trees_automerge__favor_ours(void)
REMOVED_IN_MASTER_REUC_ENTRY,
};
- opts.automerge_flags = GIT_MERGE_AUTOMERGE_FAVOR_OURS;
+ opts.file_favor = GIT_MERGE_FILE_FAVOR_OURS;
cl_git_pass(merge_trees_from_branches(&index, repo, "master", THEIRS_AUTOMERGE_BRANCH, &opts));
@@ -180,7 +180,7 @@ void test_merge_trees_automerge__favor_theirs(void)
REMOVED_IN_MASTER_REUC_ENTRY,
};
- opts.automerge_flags = GIT_MERGE_AUTOMERGE_FAVOR_THEIRS;
+ opts.file_favor = GIT_MERGE_FILE_FAVOR_THEIRS;
cl_git_pass(merge_trees_from_branches(&index, repo, "master", THEIRS_AUTOMERGE_BRANCH, &opts));
diff --git a/tests/merge/trees/trivial.c b/tests/merge/trees/trivial.c
index bfd5dfe..2de187b 100644
--- a/tests/merge/trees/trivial.c
+++ b/tests/merge/trees/trivial.c
@@ -25,7 +25,7 @@ void test_merge_trees_trivial__cleanup(void)
}
-static int merge_trivial(git_index **index, const char *ours, const char *theirs, bool automerge)
+static int merge_trivial(git_index **index, const char *ours, const char *theirs)
{
git_commit *our_commit, *their_commit, *ancestor_commit;
git_tree *our_tree, *their_tree, *ancestor_tree;
@@ -33,8 +33,6 @@ static int merge_trivial(git_index **index, const char *ours, const char *theirs
git_buf branch_buf = GIT_BUF_INIT;
git_merge_tree_opts opts = GIT_MERGE_TREE_OPTS_INIT;
- opts.automerge_flags |= automerge ? 0 : GIT_MERGE_AUTOMERGE_NONE;
-
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));
cl_git_pass(git_commit_lookup(&our_commit, repo, &our_oid));
@@ -86,7 +84,7 @@ void test_merge_trees_trivial__2alt(void)
git_index *result;
const git_index_entry *entry;
- cl_git_pass(merge_trivial(&result, "trivial-2alt", "trivial-2alt-branch", 0));
+ cl_git_pass(merge_trivial(&result, "trivial-2alt", "trivial-2alt-branch"));
cl_assert(entry = git_index_get_bypath(result, "new-in-branch.txt", 0));
cl_assert(git_index_reuc_entrycount(result) == 0);
@@ -101,7 +99,7 @@ void test_merge_trees_trivial__3alt(void)
git_index *result;
const git_index_entry *entry;
- cl_git_pass(merge_trivial(&result, "trivial-3alt", "trivial-3alt-branch", 0));
+ cl_git_pass(merge_trivial(&result, "trivial-3alt", "trivial-3alt-branch"));
cl_assert(entry = git_index_get_bypath(result, "new-in-3alt.txt", 0));
cl_assert(git_index_reuc_entrycount(result) == 0);
@@ -116,7 +114,7 @@ void test_merge_trees_trivial__4(void)
git_index *result;
const git_index_entry *entry;
- cl_git_pass(merge_trivial(&result, "trivial-4", "trivial-4-branch", 0));
+ cl_git_pass(merge_trivial(&result, "trivial-4", "trivial-4-branch"));
cl_assert((entry = git_index_get_bypath(result, "new-and-different.txt", 0)) == NULL);
cl_assert(git_index_reuc_entrycount(result) == 0);
@@ -134,7 +132,7 @@ void test_merge_trees_trivial__5alt_1(void)
git_index *result;
const git_index_entry *entry;
- cl_git_pass(merge_trivial(&result, "trivial-5alt-1", "trivial-5alt-1-branch", 0));
+ cl_git_pass(merge_trivial(&result, "trivial-5alt-1", "trivial-5alt-1-branch"));
cl_assert(entry = git_index_get_bypath(result, "new-and-same.txt", 0));
cl_assert(git_index_reuc_entrycount(result) == 0);
@@ -149,7 +147,7 @@ void test_merge_trees_trivial__5alt_2(void)
git_index *result;
const git_index_entry *entry;
- cl_git_pass(merge_trivial(&result, "trivial-5alt-2", "trivial-5alt-2-branch", 0));
+ cl_git_pass(merge_trivial(&result, "trivial-5alt-2", "trivial-5alt-2-branch"));
cl_assert(entry = git_index_get_bypath(result, "modified-to-same.txt", 0));
cl_assert(git_index_reuc_entrycount(result) == 0);
@@ -163,26 +161,9 @@ void test_merge_trees_trivial__6(void)
{
git_index *result;
const git_index_entry *entry;
-
- cl_git_pass(merge_trivial(&result, "trivial-6", "trivial-6-branch", 0));
-
- cl_assert((entry = git_index_get_bypath(result, "removed-in-both.txt", 0)) == NULL);
- cl_assert(git_index_reuc_entrycount(result) == 0);
-
- cl_assert(merge_trivial_conflict_entrycount(result) == 1);
- cl_assert(entry = git_index_get_bypath(result, "removed-in-both.txt", 1));
-
- git_index_free(result);
-}
-
-/* 6: ancest:ancest+, head:(empty), remote:(empty) = result:no merge */
-void test_merge_trees_trivial__6_automerge(void)
-{
- git_index *result;
- const git_index_entry *entry;
const git_index_reuc_entry *reuc;
- cl_git_pass(merge_trivial(&result, "trivial-6", "trivial-6-branch", 1));
+ cl_git_pass(merge_trivial(&result, "trivial-6", "trivial-6-branch"));
cl_assert((entry = git_index_get_bypath(result, "removed-in-both.txt", 0)) == NULL);
cl_assert(git_index_reuc_entrycount(result) == 1);
@@ -198,27 +179,9 @@ void test_merge_trees_trivial__8(void)
{
git_index *result;
const git_index_entry *entry;
-
- cl_git_pass(merge_trivial(&result, "trivial-8", "trivial-8-branch", 0));
-
- cl_assert((entry = git_index_get_bypath(result, "removed-in-8.txt", 0)) == NULL);
- cl_assert(git_index_reuc_entrycount(result) == 0);
-
- cl_assert(merge_trivial_conflict_entrycount(result) == 2);
- cl_assert(entry = git_index_get_bypath(result, "removed-in-8.txt", 1));
- cl_assert(entry = git_index_get_bypath(result, "removed-in-8.txt", 3));
-
- git_index_free(result);
-}
-
-/* 8: ancest:ancest^, head:(empty), remote:ancest = result:no merge */
-void test_merge_trees_trivial__8_automerge(void)
-{
- git_index *result;
- const git_index_entry *entry;
const git_index_reuc_entry *reuc;
- cl_git_pass(merge_trivial(&result, "trivial-8", "trivial-8-branch", 1));
+ cl_git_pass(merge_trivial(&result, "trivial-8", "trivial-8-branch"));
cl_assert((entry = git_index_get_bypath(result, "removed-in-8.txt", 0)) == NULL);
@@ -236,25 +199,7 @@ void test_merge_trees_trivial__7(void)
git_index *result;
const git_index_entry *entry;
- cl_git_pass(merge_trivial(&result, "trivial-7", "trivial-7-branch", 0));
-
- cl_assert((entry = git_index_get_bypath(result, "removed-in-7.txt", 0)) == NULL);
- cl_assert(git_index_reuc_entrycount(result) == 0);
-
- cl_assert(merge_trivial_conflict_entrycount(result) == 2);
- cl_assert(entry = git_index_get_bypath(result, "removed-in-7.txt", 1));
- cl_assert(entry = git_index_get_bypath(result, "removed-in-7.txt", 3));
-
- git_index_free(result);
-}
-
-/* 7: ancest:ancest+, head:(empty), remote:remote = result:no merge */
-void test_merge_trees_trivial__7_automerge(void)
-{
- git_index *result;
- const git_index_entry *entry;
-
- cl_git_pass(merge_trivial(&result, "trivial-7", "trivial-7-branch", 0));
+ cl_git_pass(merge_trivial(&result, "trivial-7", "trivial-7-branch"));
cl_assert((entry = git_index_get_bypath(result, "removed-in-7.txt", 0)) == NULL);
cl_assert(git_index_reuc_entrycount(result) == 0);
@@ -271,27 +216,9 @@ void test_merge_trees_trivial__10(void)
{
git_index *result;
const git_index_entry *entry;
-
- cl_git_pass(merge_trivial(&result, "trivial-10", "trivial-10-branch", 0));
-
- cl_assert((entry = git_index_get_bypath(result, "removed-in-10-branch.txt", 0)) == NULL);
- cl_assert(git_index_reuc_entrycount(result) == 0);
-
- cl_assert(merge_trivial_conflict_entrycount(result) == 2);
- cl_assert(entry = git_index_get_bypath(result, "removed-in-10-branch.txt", 1));
- cl_assert(entry = git_index_get_bypath(result, "removed-in-10-branch.txt", 2));
-
- git_index_free(result);
-}
-
-/* 10: ancest:ancest^, head:ancest, remote:(empty) = result:no merge */
-void test_merge_trees_trivial__10_automerge(void)
-{
- git_index *result;
- const git_index_entry *entry;
const git_index_reuc_entry *reuc;
- cl_git_pass(merge_trivial(&result, "trivial-10", "trivial-10-branch", 1));
+ cl_git_pass(merge_trivial(&result, "trivial-10", "trivial-10-branch"));
cl_assert((entry = git_index_get_bypath(result, "removed-in-10-branch.txt", 0)) == NULL);
@@ -309,25 +236,7 @@ void test_merge_trees_trivial__9(void)
git_index *result;
const git_index_entry *entry;
- cl_git_pass(merge_trivial(&result, "trivial-9", "trivial-9-branch", 0));
-
- cl_assert((entry = git_index_get_bypath(result, "removed-in-9-branch.txt", 0)) == NULL);
- cl_assert(git_index_reuc_entrycount(result) == 0);
-
- cl_assert(merge_trivial_conflict_entrycount(result) == 2);
- cl_assert(entry = git_index_get_bypath(result, "removed-in-9-branch.txt", 1));
- cl_assert(entry = git_index_get_bypath(result, "removed-in-9-branch.txt", 2));
-
- git_index_free(result);
-}
-
-/* 9: ancest:ancest+, head:head, remote:(empty) = result:no merge */
-void test_merge_trees_trivial__9_automerge(void)
-{
- git_index *result;
- const git_index_entry *entry;
-
- cl_git_pass(merge_trivial(&result, "trivial-9", "trivial-9-branch", 1));
+ cl_git_pass(merge_trivial(&result, "trivial-9", "trivial-9-branch"));
cl_assert((entry = git_index_get_bypath(result, "removed-in-9-branch.txt", 0)) == NULL);
cl_assert(git_index_reuc_entrycount(result) == 0);
@@ -346,7 +255,7 @@ void test_merge_trees_trivial__13(void)
const git_index_entry *entry;
git_oid expected_oid;
- cl_git_pass(merge_trivial(&result, "trivial-13", "trivial-13-branch", 0));
+ cl_git_pass(merge_trivial(&result, "trivial-13", "trivial-13-branch"));
cl_assert(entry = git_index_get_bypath(result, "modified-in-13.txt", 0));
cl_git_pass(git_oid_fromstr(&expected_oid, "1cff9ec6a47a537380dedfdd17c9e76d74259a2b"));
@@ -365,7 +274,7 @@ void test_merge_trees_trivial__14(void)
const git_index_entry *entry;
git_oid expected_oid;
- cl_git_pass(merge_trivial(&result, "trivial-14", "trivial-14-branch", 0));
+ cl_git_pass(merge_trivial(&result, "trivial-14", "trivial-14-branch"));
cl_assert(entry = git_index_get_bypath(result, "modified-in-14-branch.txt", 0));
cl_git_pass(git_oid_fromstr(&expected_oid, "26153a3ff3649b6c2bb652d3f06878c6e0a172f9"));
@@ -383,7 +292,7 @@ void test_merge_trees_trivial__11(void)
git_index *result;
const git_index_entry *entry;
- cl_git_pass(merge_trivial(&result, "trivial-11", "trivial-11-branch", 0));
+ cl_git_pass(merge_trivial(&result, "trivial-11", "trivial-11-branch"));
cl_assert((entry = git_index_get_bypath(result, "modified-in-both.txt", 0)) == NULL);
cl_assert(git_index_reuc_entrycount(result) == 0);
diff --git a/tests/merge/workdir/simple.c b/tests/merge/workdir/simple.c
index 98dca53..6b152cc 100644
--- a/tests/merge/workdir/simple.c
+++ b/tests/merge/workdir/simple.c
@@ -93,13 +93,26 @@ static git_index *repo_index;
"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)
{
@@ -113,7 +126,7 @@ void test_merge_workdir_simple__cleanup(void)
cl_git_sandbox_cleanup();
}
-static git_merge_result *merge_simple_branch(int automerge_flags, int checkout_strategy)
+static git_merge_result *merge_simple_branch(int merge_file_favor, int checkout_strategy)
{
git_oid their_oids[1];
git_merge_head *their_heads[1];
@@ -123,7 +136,7 @@ static git_merge_result *merge_simple_branch(int automerge_flags, int checkout_s
cl_git_pass(git_oid_fromstr(&their_oids[0], THEIRS_SIMPLE_OID));
cl_git_pass(git_merge_head_from_oid(&their_heads[0], repo, &their_oids[0]));
- opts.merge_tree_opts.automerge_flags = automerge_flags;
+ 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));
@@ -244,6 +257,44 @@ void test_merge_workdir_simple__automerge_crlf(void)
#endif /* GIT_WIN32 */
}
+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[] = {
+ ADDED_IN_MASTER_INDEX_ENTRY,
+ AUTOMERGEABLE_INDEX_ENTRY,
+ CHANGED_IN_BRANCH_INDEX_ENTRY,
+ CHANGED_IN_MASTER_INDEX_ENTRY,
+
+ { 0100644, "d427e0b2e138501a3d15cc376077a3631e15bd46", 1, "conflicting.txt" },
+ { 0100644, "4e886e602529caa9ab11d71f86634bd1b6e0de10", 2, "conflicting.txt" },
+ { 0100644, "2bd0a343aeef7a2cf0d158478966a6e587ff3863", 3, "conflicting.txt" },
+
+ UNCHANGED_INDEX_ENTRY,
+ };
+
+ struct merge_reuc_entry merge_reuc_entries[] = {
+ AUTOMERGEABLE_REUC_ENTRY,
+ REMOVED_IN_BRANCH_REUC_ENTRY,
+ REMOVED_IN_MASTER_REUC_ENTRY
+ };
+
+ cl_assert(result = merge_simple_branch(0, 0));
+ cl_assert(!git_merge_result_is_fastforward(result));
+
+ cl_git_pass(git_futils_readbuffer(&conflicting_buf,
+ TEST_REPO_PATH "/conflicting.txt"));
+ cl_assert(strcmp(conflicting_buf.ptr, CONFLICTING_MERGE_FILE) == 0);
+ git_buf_free(&conflicting_buf);
+
+ 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;
@@ -268,6 +319,87 @@ 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));
+
+ cl_git_pass(git_futils_readbuffer(&conflicting_buf,
+ TEST_REPO_PATH "/conflicting.txt"));
+ cl_assert(strcmp(conflicting_buf.ptr, CONFLICTING_DIFF3_FILE) == 0);
+ git_buf_free(&conflicting_buf);
+
+ 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[] = {
+ ADDED_IN_MASTER_INDEX_ENTRY,
+ AUTOMERGEABLE_INDEX_ENTRY,
+ CHANGED_IN_BRANCH_INDEX_ENTRY,
+ CHANGED_IN_MASTER_INDEX_ENTRY,
+
+ { 0100644, "72cdb057b340205164478565e91eb71647e66891", 0, "conflicting.txt" },
+
+ UNCHANGED_INDEX_ENTRY,
+ };
+
+ struct merge_reuc_entry merge_reuc_entries[] = {
+ AUTOMERGEABLE_REUC_ENTRY,
+ CONFLICTING_REUC_ENTRY,
+ REMOVED_IN_BRANCH_REUC_ENTRY,
+ REMOVED_IN_MASTER_REUC_ENTRY
+ };
+
+ 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));
+
+ cl_git_pass(git_futils_readbuffer(&conflicting_buf,
+ TEST_REPO_PATH "/conflicting.txt"));
+ cl_assert(strcmp(conflicting_buf.ptr, CONFLICTING_UNION_FILE) == 0);
+ git_buf_free(&conflicting_buf);
+
+ 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;
+
+ struct merge_index_entry merge_index_entries[] = {
+ ADDED_IN_MASTER_INDEX_ENTRY,
+ AUTOMERGEABLE_INDEX_ENTRY,
+ CHANGED_IN_BRANCH_INDEX_ENTRY,
+ CHANGED_IN_MASTER_INDEX_ENTRY,
+
+ { 0100644, "d427e0b2e138501a3d15cc376077a3631e15bd46", 1, "conflicting.txt" },
+ { 0100644, "4e886e602529caa9ab11d71f86634bd1b6e0de10", 2, "conflicting.txt" },
+ { 0100644, "2bd0a343aeef7a2cf0d158478966a6e587ff3863", 3, "conflicting.txt" },
+
+ UNCHANGED_INDEX_ENTRY,
+ };
+
+ struct merge_reuc_entry merge_reuc_entries[] = {
+ AUTOMERGEABLE_REUC_ENTRY,
+ REMOVED_IN_BRANCH_REUC_ENTRY,
+ REMOVED_IN_MASTER_REUC_ENTRY
+ };
+
+ 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));
@@ -280,6 +412,50 @@ void test_merge_workdir_simple__diff3(void)
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;
+
+ struct merge_index_entry merge_index_entries[] = {
+ ADDED_IN_MASTER_INDEX_ENTRY,
+ AUTOMERGEABLE_INDEX_ENTRY,
+ CHANGED_IN_BRANCH_INDEX_ENTRY,
+ CHANGED_IN_MASTER_INDEX_ENTRY,
+
+ { 0100644, "d427e0b2e138501a3d15cc376077a3631e15bd46", 1, "conflicting.txt" },
+ { 0100644, "4e886e602529caa9ab11d71f86634bd1b6e0de10", 2, "conflicting.txt" },
+ { 0100644, "2bd0a343aeef7a2cf0d158478966a6e587ff3863", 3, "conflicting.txt" },
+
+ UNCHANGED_INDEX_ENTRY,
+ };
+
+ struct merge_reuc_entry merge_reuc_entries[] = {
+ AUTOMERGEABLE_REUC_ENTRY,
+ REMOVED_IN_BRANCH_REUC_ENTRY,
+ REMOVED_IN_MASTER_REUC_ENTRY
+ };
+
+ 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));
+
+ cl_git_pass(git_futils_readbuffer(&conflicting_buf,
+ TEST_REPO_PATH "/conflicting.txt"));
+ cl_assert(strcmp(conflicting_buf.ptr, CONFLICTING_MERGE_FILE) == 0);
+ git_buf_free(&conflicting_buf);
+
+ 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)
@@ -336,7 +512,7 @@ void test_merge_workdir_simple__favor_ours(void)
REMOVED_IN_MASTER_REUC_ENTRY,
};
- cl_assert(result = merge_simple_branch(GIT_MERGE_AUTOMERGE_FAVOR_OURS, 0));
+ cl_assert(result = merge_simple_branch(GIT_MERGE_FILE_FAVOR_OURS, 0));
cl_assert(!git_merge_result_is_fastforward(result));
cl_assert(merge_test_index(repo_index, merge_index_entries, 6));
@@ -365,7 +541,7 @@ void test_merge_workdir_simple__favor_theirs(void)
REMOVED_IN_MASTER_REUC_ENTRY,
};
- cl_assert(result = merge_simple_branch(GIT_MERGE_AUTOMERGE_FAVOR_THEIRS, 0));
+ cl_assert(result = merge_simple_branch(GIT_MERGE_FILE_FAVOR_THEIRS, 0));
cl_assert(!git_merge_result_is_fastforward(result));
cl_assert(merge_test_index(repo_index, merge_index_entries, 6));
@@ -414,7 +590,7 @@ 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_oid(&their_heads[0], repo, &their_oids[0]));
- opts.merge_tree_opts.automerge_flags = 0;
+ opts.merge_tree_opts.file_favor = 0;
cl_git_pass(git_merge(&result, repo, (const git_merge_head **)their_heads, 1, &opts));
cl_assert(merge_test_index(repo_index, merge_index_entries, 20));
@@ -447,7 +623,7 @@ 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_oid(&their_heads[0], repo, &their_oids[0]));
- opts.merge_tree_opts.automerge_flags = 0;
+ opts.merge_tree_opts.file_favor = 0;
cl_git_pass(git_merge(&result, repo, (const git_merge_head **)their_heads, 1, &opts));
cl_assert(merge_test_index(repo_index, merge_index_entries, 9));
@@ -480,7 +656,7 @@ 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_oid(&their_heads[0], repo, &their_oids[0]));
- opts.merge_tree_opts.automerge_flags = 0;
+ opts.merge_tree_opts.file_favor = 0;
cl_git_pass(git_merge(&result, repo, (const git_merge_head **)their_heads, 1, &opts));
cl_assert(merge_test_index(repo_index, merge_index_entries, 11));
@@ -489,3 +665,40 @@ void test_merge_workdir_simple__unrelated_with_conflicts(void)
git_merge_result_free(result);
}
+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" },
+ { 0100644, "23ed141a6ae1e798b2f721afedbe947c119111ba", 2, "binary" },
+ { 0100644, "836b8b82b26cab22eaaed8820877c76d6c8bca19", 3, "binary" },
+ };
+
+ cl_git_pass(git_oid_fromstr(&our_oid, "cc338e4710c9b257106b8d16d82f86458d5beaf1"));
+ cl_git_pass(git_oid_fromstr(&their_oid, "ad01aebfdf2ac13145efafe3f9fcf798882f1730"));
+
+ cl_git_pass(git_commit_lookup(&our_commit, repo, &our_oid));
+ cl_git_pass(git_reset(repo, (git_object *)our_commit, GIT_RESET_HARD));
+
+ cl_git_pass(git_merge_head_from_oid(&their_head, repo, &their_oid));
+
+ cl_git_pass(git_merge(&result, repo, (const git_merge_head **)&their_head, 1, &opts));
+
+ cl_assert(merge_test_index(repo_index, merge_index_entries, 3));
+
+ cl_git_pass(git_index_add_bypath(repo_index, "binary"));
+ cl_assert((binary_entry = git_index_get_bypath(repo_index, "binary", 0)) != NULL);
+
+ cl_git_pass(git_oid_fromstr(&our_file_oid, "23ed141a6ae1e798b2f721afedbe947c119111ba"));
+ cl_assert(git_oid_cmp(&binary_entry->oid, &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
new file mode 100644
index 0000000..f01faac
--- /dev/null
+++ b/tests/merge/workdir/submodules.c
@@ -0,0 +1,101 @@
+#include "clar_libgit2.h"
+#include "git2/repository.h"
+#include "git2/merge.h"
+#include "buffer.h"
+#include "merge.h"
+#include "../merge_helpers.h"
+
+static git_repository *repo;
+
+#define TEST_REPO_PATH "merge-resolve"
+
+#define SUBMODULE_MAIN_BRANCH "submodules"
+#define SUBMODULE_OTHER_BRANCH "submodules-branch"
+#define SUBMODULE_OTHER2_BRANCH "submodules-branch2"
+
+#define TEST_INDEX_PATH TEST_REPO_PATH "/.git/index"
+
+// Fixture setup and teardown
+void test_merge_workdir_submodules__initialize(void)
+{
+ repo = cl_git_sandbox_init(TEST_REPO_PATH);
+}
+
+void test_merge_workdir_submodules__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+}
+
+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[] = {
+ { 0100644, "caff6b7d44973f53e3e0cf31d0d695188b19aec6", 0, ".gitmodules" },
+ { 0100644, "950a663a6a7b2609eed1ed1ba9f41eb1a3192a9f", 0, "file1.txt" },
+ { 0100644, "343e660b9cb4bee5f407c2e33fcb9df24d9407a4", 0, "file2.txt" },
+ { 0160000, "d3d806a4bef96889117fd7ebac0e3cb5ec152932", 1, "submodule" },
+ { 0160000, "297aa6cd028b3336c7802c7a6f49143da4e1602d", 2, "submodule" },
+ { 0160000, "ae39c77c70cb6bad18bb471912460c4e1ba0f586", 3, "submodule" },
+ };
+
+ cl_git_pass(git_reference_lookup(&our_ref, repo, "refs/heads/" SUBMODULE_MAIN_BRANCH));
+ cl_git_pass(git_commit_lookup(&our_commit, repo, git_reference_target(our_ref)));
+ cl_git_pass(git_reset(repo, (git_object *)our_commit, GIT_RESET_HARD));
+
+ 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_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);
+ git_reference_free(our_ref);
+}
+
+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[] = {
+ { 0100644, "caff6b7d44973f53e3e0cf31d0d695188b19aec6", 0, ".gitmodules" },
+ { 0100644, "b438ff23300b2e0f80b84a6f30140dfa91e71423", 0, "file1.txt" },
+ { 0100644, "f27fbafdfa6693f8f7a5128506fe3e338dbfcad2", 0, "file2.txt" },
+ { 0160000, "297aa6cd028b3336c7802c7a6f49143da4e1602d", 0, "submodule" },
+ };
+
+ cl_git_pass(git_reference_lookup(&our_ref, repo, "refs/heads/" SUBMODULE_MAIN_BRANCH));
+ cl_git_pass(git_commit_lookup(&our_commit, repo, git_reference_target(our_ref)));
+ cl_git_pass(git_reset(repo, (git_object *)our_commit, GIT_RESET_HARD));
+
+ 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_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);
+ git_reference_free(our_ref);
+}
diff --git a/tests/merge/workdir/trivial.c b/tests/merge/workdir/trivial.c
index df18b0e..71437d4 100644
--- a/tests/merge/workdir/trivial.c
+++ b/tests/merge/workdir/trivial.c
@@ -28,7 +28,7 @@ void test_merge_workdir_trivial__cleanup(void)
}
-static int merge_trivial(const char *ours, const char *theirs, bool automerge)
+static int merge_trivial(const char *ours, const char *theirs)
{
git_buf branch_buf = GIT_BUF_INIT;
git_checkout_opts checkout_opts = GIT_CHECKOUT_OPTS_INIT;
@@ -39,8 +39,6 @@ static int merge_trivial(const char *ours, const char *theirs, bool automerge)
checkout_opts.checkout_strategy = GIT_CHECKOUT_FORCE;
- opts.merge_tree_opts.automerge_flags |= automerge ? 0 : GIT_MERGE_AUTOMERGE_NONE;
-
git_buf_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, ours);
cl_git_pass(git_reference_symbolic_create(&our_ref, repo, "HEAD", branch_buf.ptr, 1, NULL, NULL));
@@ -83,7 +81,7 @@ void test_merge_workdir_trivial__2alt(void)
{
const git_index_entry *entry;
- cl_git_pass(merge_trivial("trivial-2alt", "trivial-2alt-branch", 0));
+ cl_git_pass(merge_trivial("trivial-2alt", "trivial-2alt-branch"));
cl_assert(entry = git_index_get_bypath(repo_index, "new-in-branch.txt", 0));
cl_assert(git_index_reuc_entrycount(repo_index) == 0);
@@ -95,7 +93,7 @@ void test_merge_workdir_trivial__3alt(void)
{
const git_index_entry *entry;
- cl_git_pass(merge_trivial("trivial-3alt", "trivial-3alt-branch", 0));
+ cl_git_pass(merge_trivial("trivial-3alt", "trivial-3alt-branch"));
cl_assert(entry = git_index_get_bypath(repo_index, "new-in-3alt.txt", 0));
cl_assert(git_index_reuc_entrycount(repo_index) == 0);
@@ -107,7 +105,7 @@ void test_merge_workdir_trivial__4(void)
{
const git_index_entry *entry;
- cl_git_pass(merge_trivial("trivial-4", "trivial-4-branch", 0));
+ cl_git_pass(merge_trivial("trivial-4", "trivial-4-branch"));
cl_assert((entry = git_index_get_bypath(repo_index, "new-and-different.txt", 0)) == NULL);
cl_assert(git_index_reuc_entrycount(repo_index) == 0);
@@ -122,7 +120,7 @@ void test_merge_workdir_trivial__5alt_1(void)
{
const git_index_entry *entry;
- cl_git_pass(merge_trivial("trivial-5alt-1", "trivial-5alt-1-branch", 0));
+ cl_git_pass(merge_trivial("trivial-5alt-1", "trivial-5alt-1-branch"));
cl_assert(entry = git_index_get_bypath(repo_index, "new-and-same.txt", 0));
cl_assert(git_index_reuc_entrycount(repo_index) == 0);
@@ -134,7 +132,7 @@ void test_merge_workdir_trivial__5alt_2(void)
{
const git_index_entry *entry;
- cl_git_pass(merge_trivial("trivial-5alt-2", "trivial-5alt-2-branch", 0));
+ cl_git_pass(merge_trivial("trivial-5alt-2", "trivial-5alt-2-branch"));
cl_assert(entry = git_index_get_bypath(repo_index, "modified-to-same.txt", 0));
cl_assert(git_index_reuc_entrycount(repo_index) == 0);
@@ -145,23 +143,9 @@ void test_merge_workdir_trivial__5alt_2(void)
void test_merge_workdir_trivial__6(void)
{
const git_index_entry *entry;
-
- cl_git_pass(merge_trivial("trivial-6", "trivial-6-branch", 0));
-
- cl_assert((entry = git_index_get_bypath(repo_index, "removed-in-both.txt", 0)) == NULL);
- cl_assert(git_index_reuc_entrycount(repo_index) == 0);
-
- cl_assert(merge_trivial_conflict_entrycount() == 1);
- cl_assert(entry = git_index_get_bypath(repo_index, "removed-in-both.txt", 1));
-}
-
-/* 6: ancest:ancest+, head:(empty), remote:(empty) = result:no merge */
-void test_merge_workdir_trivial__6_automerge(void)
-{
- const git_index_entry *entry;
const git_index_reuc_entry *reuc;
- cl_git_pass(merge_trivial("trivial-6", "trivial-6-branch", 1));
+ cl_git_pass(merge_trivial("trivial-6", "trivial-6-branch"));
cl_assert((entry = git_index_get_bypath(repo_index, "removed-in-both.txt", 0)) == NULL);
cl_assert(git_index_reuc_entrycount(repo_index) == 1);
@@ -174,24 +158,9 @@ void test_merge_workdir_trivial__6_automerge(void)
void test_merge_workdir_trivial__8(void)
{
const git_index_entry *entry;
-
- cl_git_pass(merge_trivial("trivial-8", "trivial-8-branch", 0));
-
- cl_assert((entry = git_index_get_bypath(repo_index, "removed-in-8.txt", 0)) == NULL);
- cl_assert(git_index_reuc_entrycount(repo_index) == 0);
-
- cl_assert(merge_trivial_conflict_entrycount() == 2);
- cl_assert(entry = git_index_get_bypath(repo_index, "removed-in-8.txt", 1));
- cl_assert(entry = git_index_get_bypath(repo_index, "removed-in-8.txt", 3));
-}
-
-/* 8: ancest:ancest^, head:(empty), remote:ancest = result:no merge */
-void test_merge_workdir_trivial__8_automerge(void)
-{
- const git_index_entry *entry;
const git_index_reuc_entry *reuc;
- cl_git_pass(merge_trivial("trivial-8", "trivial-8-branch", 1));
+ cl_git_pass(merge_trivial("trivial-8", "trivial-8-branch"));
cl_assert((entry = git_index_get_bypath(repo_index, "removed-in-8.txt", 0)) == NULL);
@@ -206,22 +175,7 @@ void test_merge_workdir_trivial__7(void)
{
const git_index_entry *entry;
- cl_git_pass(merge_trivial("trivial-7", "trivial-7-branch", 0));
-
- cl_assert((entry = git_index_get_bypath(repo_index, "removed-in-7.txt", 0)) == NULL);
- cl_assert(git_index_reuc_entrycount(repo_index) == 0);
-
- cl_assert(merge_trivial_conflict_entrycount() == 2);
- cl_assert(entry = git_index_get_bypath(repo_index, "removed-in-7.txt", 1));
- cl_assert(entry = git_index_get_bypath(repo_index, "removed-in-7.txt", 3));
-}
-
-/* 7: ancest:ancest+, head:(empty), remote:remote = result:no merge */
-void test_merge_workdir_trivial__7_automerge(void)
-{
- const git_index_entry *entry;
-
- cl_git_pass(merge_trivial("trivial-7", "trivial-7-branch", 0));
+ cl_git_pass(merge_trivial("trivial-7", "trivial-7-branch"));
cl_assert((entry = git_index_get_bypath(repo_index, "removed-in-7.txt", 0)) == NULL);
cl_assert(git_index_reuc_entrycount(repo_index) == 0);
@@ -235,24 +189,9 @@ void test_merge_workdir_trivial__7_automerge(void)
void test_merge_workdir_trivial__10(void)
{
const git_index_entry *entry;
-
- cl_git_pass(merge_trivial("trivial-10", "trivial-10-branch", 0));
-
- cl_assert((entry = git_index_get_bypath(repo_index, "removed-in-10-branch.txt", 0)) == NULL);
- cl_assert(git_index_reuc_entrycount(repo_index) == 0);
-
- cl_assert(merge_trivial_conflict_entrycount() == 2);
- cl_assert(entry = git_index_get_bypath(repo_index, "removed-in-10-branch.txt", 1));
- cl_assert(entry = git_index_get_bypath(repo_index, "removed-in-10-branch.txt", 2));
-}
-
-/* 10: ancest:ancest^, head:ancest, remote:(empty) = result:no merge */
-void test_merge_workdir_trivial__10_automerge(void)
-{
- const git_index_entry *entry;
const git_index_reuc_entry *reuc;
- cl_git_pass(merge_trivial("trivial-10", "trivial-10-branch", 1));
+ cl_git_pass(merge_trivial("trivial-10", "trivial-10-branch"));
cl_assert((entry = git_index_get_bypath(repo_index, "removed-in-10-branch.txt", 0)) == NULL);
@@ -267,22 +206,7 @@ void test_merge_workdir_trivial__9(void)
{
const git_index_entry *entry;
- cl_git_pass(merge_trivial("trivial-9", "trivial-9-branch", 0));
-
- cl_assert((entry = git_index_get_bypath(repo_index, "removed-in-9-branch.txt", 0)) == NULL);
- cl_assert(git_index_reuc_entrycount(repo_index) == 0);
-
- cl_assert(merge_trivial_conflict_entrycount() == 2);
- cl_assert(entry = git_index_get_bypath(repo_index, "removed-in-9-branch.txt", 1));
- cl_assert(entry = git_index_get_bypath(repo_index, "removed-in-9-branch.txt", 2));
-}
-
-/* 9: ancest:ancest+, head:head, remote:(empty) = result:no merge */
-void test_merge_workdir_trivial__9_automerge(void)
-{
- const git_index_entry *entry;
-
- cl_git_pass(merge_trivial("trivial-9", "trivial-9-branch", 1));
+ cl_git_pass(merge_trivial("trivial-9", "trivial-9-branch"));
cl_assert((entry = git_index_get_bypath(repo_index, "removed-in-9-branch.txt", 0)) == NULL);
cl_assert(git_index_reuc_entrycount(repo_index) == 0);
@@ -298,7 +222,7 @@ void test_merge_workdir_trivial__13(void)
const git_index_entry *entry;
git_oid expected_oid;
- cl_git_pass(merge_trivial("trivial-13", "trivial-13-branch", 0));
+ cl_git_pass(merge_trivial("trivial-13", "trivial-13-branch"));
cl_assert(entry = git_index_get_bypath(repo_index, "modified-in-13.txt", 0));
cl_git_pass(git_oid_fromstr(&expected_oid, "1cff9ec6a47a537380dedfdd17c9e76d74259a2b"));
@@ -314,7 +238,7 @@ void test_merge_workdir_trivial__14(void)
const git_index_entry *entry;
git_oid expected_oid;
- cl_git_pass(merge_trivial("trivial-14", "trivial-14-branch", 0));
+ cl_git_pass(merge_trivial("trivial-14", "trivial-14-branch"));
cl_assert(entry = git_index_get_bypath(repo_index, "modified-in-14-branch.txt", 0));
cl_git_pass(git_oid_fromstr(&expected_oid, "26153a3ff3649b6c2bb652d3f06878c6e0a172f9"));
@@ -329,7 +253,7 @@ void test_merge_workdir_trivial__11(void)
{
const git_index_entry *entry;
- cl_git_pass(merge_trivial("trivial-11", "trivial-11-branch", 0));
+ cl_git_pass(merge_trivial("trivial-11", "trivial-11-branch"));
cl_assert((entry = git_index_get_bypath(repo_index, "modified-in-both.txt", 0)) == NULL);
cl_assert(git_index_reuc_entrycount(repo_index) == 0);
diff --git a/tests/resources/merge-resolve/.gitted/config b/tests/resources/merge-resolve/.gitted/config
index af10792..26c4842 100644
--- a/tests/resources/merge-resolve/.gitted/config
+++ b/tests/resources/merge-resolve/.gitted/config
@@ -4,3 +4,5 @@
bare = false
logallrefupdates = true
ignorecase = true
+[submodule "submodule"]
+ url = ../submodule
diff --git a/tests/resources/merge-resolve/.gitted/modules/submodule/HEAD b/tests/resources/merge-resolve/.gitted/modules/submodule/HEAD
new file mode 100644
index 0000000..cb089cd
--- /dev/null
+++ b/tests/resources/merge-resolve/.gitted/modules/submodule/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests/resources/merge-resolve/.gitted/modules/submodule/ORIG_HEAD b/tests/resources/merge-resolve/.gitted/modules/submodule/ORIG_HEAD
new file mode 100644
index 0000000..d1bfcf0
--- /dev/null
+++ b/tests/resources/merge-resolve/.gitted/modules/submodule/ORIG_HEAD
@@ -0,0 +1 @@
+ae39c77c70cb6bad18bb471912460c4e1ba0f586
diff --git a/tests/resources/merge-resolve/.gitted/modules/submodule/config b/tests/resources/merge-resolve/.gitted/modules/submodule/config
new file mode 100644
index 0000000..575cc85
--- /dev/null
+++ b/tests/resources/merge-resolve/.gitted/modules/submodule/config
@@ -0,0 +1,15 @@
+[core]
+ repositoryformatversion = 0
+ filemode = false
+ bare = false
+ logallrefupdates = true
+ worktree = ../../../submodule
+ symlinks = false
+ ignorecase = true
+ hideDotFiles = dotGitOnly
+[remote "origin"]
+ url = c:/Temp/TestRepos/submodule
+ fetch = +refs/heads/*:refs/remotes/origin/*
+[branch "master"]
+ remote = origin
+ merge = refs/heads/master
diff --git a/tests/resources/merge-resolve/.gitted/modules/submodule/index b/tests/resources/merge-resolve/.gitted/modules/submodule/index
new file mode 100644
index 0000000..e948afb
Binary files /dev/null and b/tests/resources/merge-resolve/.gitted/modules/submodule/index differ
diff --git a/tests/resources/merge-resolve/.gitted/modules/submodule/info/exclude b/tests/resources/merge-resolve/.gitted/modules/submodule/info/exclude
new file mode 100644
index 0000000..a5196d1
--- /dev/null
+++ b/tests/resources/merge-resolve/.gitted/modules/submodule/info/exclude
@@ -0,0 +1,6 @@
+# git ls-files --others --exclude-from=.git/info/exclude
+# Lines that start with '#' are comments.
+# For a project mostly in C, the following would be a good set of
+# exclude patterns (uncomment them if you want to use them):
+# *.[oa]
+# *~
diff --git a/tests/resources/merge-resolve/.gitted/modules/submodule/objects/18/fae1354bba0a5f1e6a531f9988369142c24a9e b/tests/resources/merge-resolve/.gitted/modules/submodule/objects/18/fae1354bba0a5f1e6a531f9988369142c24a9e
new file mode 100644
index 0000000..fcf1c63
Binary files /dev/null and b/tests/resources/merge-resolve/.gitted/modules/submodule/objects/18/fae1354bba0a5f1e6a531f9988369142c24a9e differ
diff --git a/tests/resources/merge-resolve/.gitted/modules/submodule/objects/29/7aa6cd028b3336c7802c7a6f49143da4e1602d b/tests/resources/merge-resolve/.gitted/modules/submodule/objects/29/7aa6cd028b3336c7802c7a6f49143da4e1602d
new file mode 100644
index 0000000..aa9fc50
Binary files /dev/null and b/tests/resources/merge-resolve/.gitted/modules/submodule/objects/29/7aa6cd028b3336c7802c7a6f49143da4e1602d differ
diff --git a/tests/resources/merge-resolve/.gitted/modules/submodule/objects/38/6c80dc813b89d719797668f40c1be0a6efa996 b/tests/resources/merge-resolve/.gitted/modules/submodule/objects/38/6c80dc813b89d719797668f40c1be0a6efa996
new file mode 100644
index 0000000..bc9a32e
Binary files /dev/null and b/tests/resources/merge-resolve/.gitted/modules/submodule/objects/38/6c80dc813b89d719797668f40c1be0a6efa996 differ
diff --git a/tests/resources/merge-resolve/.gitted/modules/submodule/objects/ab/435a147bae6d5906ecfd0916a570c4ab3eeea8 b/tests/resources/merge-resolve/.gitted/modules/submodule/objects/ab/435a147bae6d5906ecfd0916a570c4ab3eeea8
new file mode 100644
index 0000000..65a8d75
Binary files /dev/null and b/tests/resources/merge-resolve/.gitted/modules/submodule/objects/ab/435a147bae6d5906ecfd0916a570c4ab3eeea8 differ
diff --git a/tests/resources/merge-resolve/.gitted/modules/submodule/objects/ad/16e0a7684ea95bf892980a2ee412293ae979cc b/tests/resources/merge-resolve/.gitted/modules/submodule/objects/ad/16e0a7684ea95bf892980a2ee412293ae979cc
new file mode 100644
index 0000000..49e1aaf
Binary files /dev/null and b/tests/resources/merge-resolve/.gitted/modules/submodule/objects/ad/16e0a7684ea95bf892980a2ee412293ae979cc differ
diff --git a/tests/resources/merge-resolve/.gitted/modules/submodule/objects/ae/39c77c70cb6bad18bb471912460c4e1ba0f586 b/tests/resources/merge-resolve/.gitted/modules/submodule/objects/ae/39c77c70cb6bad18bb471912460c4e1ba0f586
new file mode 100644
index 0000000..6ceffdd
--- /dev/null
+++ b/tests/resources/merge-resolve/.gitted/modules/submodule/objects/ae/39c77c70cb6bad18bb471912460c4e1ba0f586
@@ -0,0 +1,2 @@
+x
!@=S
hf%x! ]k/{k-a]
xWs =,lP
+#g0KIC,51 9;alB=>|h}_{{Me?u6">:叄ʃ6^Kd
\ No newline at end of file
diff --git a/tests/resources/merge-resolve/.gitted/modules/submodule/objects/c2/0765f6e24e8bbb63a648d0d11d84da63170190 b/tests/resources/merge-resolve/.gitted/modules/submodule/objects/c2/0765f6e24e8bbb63a648d0d11d84da63170190
new file mode 100644
index 0000000..1478103
Binary files /dev/null and b/tests/resources/merge-resolve/.gitted/modules/submodule/objects/c2/0765f6e24e8bbb63a648d0d11d84da63170190 differ
diff --git a/tests/resources/merge-resolve/.gitted/modules/submodule/objects/d3/d806a4bef96889117fd7ebac0e3cb5ec152932 b/tests/resources/merge-resolve/.gitted/modules/submodule/objects/d3/d806a4bef96889117fd7ebac0e3cb5ec152932
new file mode 100644
index 0000000..8df72a4
--- /dev/null
+++ b/tests/resources/merge-resolve/.gitted/modules/submodule/objects/d3/d806a4bef96889117fd7ebac0e3cb5ec152932
@@ -0,0 +1,3 @@
+xA
+0E]semDx$҂@gpQs^+ZD[a
+,cGsBO# vhGpIZ4U{^c]zo@ǎ\M-\<Bt流A
\ No newline at end of file
diff --git a/tests/resources/merge-resolve/.gitted/modules/submodule/objects/f1/065ff5593604072837fecaad3e2e268cb0147b b/tests/resources/merge-resolve/.gitted/modules/submodule/objects/f1/065ff5593604072837fecaad3e2e268cb0147b
new file mode 100644
index 0000000..e0d73e1
Binary files /dev/null and b/tests/resources/merge-resolve/.gitted/modules/submodule/objects/f1/065ff5593604072837fecaad3e2e268cb0147b differ
diff --git a/tests/resources/merge-resolve/.gitted/modules/submodule/packed-refs b/tests/resources/merge-resolve/.gitted/modules/submodule/packed-refs
new file mode 100644
index 0000000..992c4ee
--- /dev/null
+++ b/tests/resources/merge-resolve/.gitted/modules/submodule/packed-refs
@@ -0,0 +1,3 @@
+# pack-refs with: peeled
+297aa6cd028b3336c7802c7a6f49143da4e1602d refs/remotes/origin/master
+ae39c77c70cb6bad18bb471912460c4e1ba0f586 refs/remotes/origin/submodule-branch
diff --git a/tests/resources/merge-resolve/.gitted/modules/submodule/refs/heads/master b/tests/resources/merge-resolve/.gitted/modules/submodule/refs/heads/master
new file mode 100644
index 0000000..fe28256
--- /dev/null
+++ b/tests/resources/merge-resolve/.gitted/modules/submodule/refs/heads/master
@@ -0,0 +1 @@
+297aa6cd028b3336c7802c7a6f49143da4e1602d
diff --git a/tests/resources/merge-resolve/.gitted/modules/submodule/refs/remotes/origin/HEAD b/tests/resources/merge-resolve/.gitted/modules/submodule/refs/remotes/origin/HEAD
new file mode 100644
index 0000000..6efe28f
--- /dev/null
+++ b/tests/resources/merge-resolve/.gitted/modules/submodule/refs/remotes/origin/HEAD
@@ -0,0 +1 @@
+ref: refs/remotes/origin/master
diff --git a/tests/resources/merge-resolve/.gitted/objects/0f/3fc5dddc8964b9ac1040d0e957f9eb02d9efb3 b/tests/resources/merge-resolve/.gitted/objects/0f/3fc5dddc8964b9ac1040d0e957f9eb02d9efb3
new file mode 100644
index 0000000..d0ca42d
Binary files /dev/null and b/tests/resources/merge-resolve/.gitted/objects/0f/3fc5dddc8964b9ac1040d0e957f9eb02d9efb3 differ
diff --git a/tests/resources/merge-resolve/.gitted/objects/11/aeee27ac45a8402c2fd5b875d66dd844e5df00 b/tests/resources/merge-resolve/.gitted/objects/11/aeee27ac45a8402c2fd5b875d66dd844e5df00
new file mode 100644
index 0000000..90e729f
Binary files /dev/null and b/tests/resources/merge-resolve/.gitted/objects/11/aeee27ac45a8402c2fd5b875d66dd844e5df00 differ
diff --git a/tests/resources/merge-resolve/.gitted/objects/1c/51d885170f57a0c4e8c69ff6363d91a5b51f85 b/tests/resources/merge-resolve/.gitted/objects/1c/51d885170f57a0c4e8c69ff6363d91a5b51f85
new file mode 100644
index 0000000..9a21e26
Binary files /dev/null and b/tests/resources/merge-resolve/.gitted/objects/1c/51d885170f57a0c4e8c69ff6363d91a5b51f85 differ
diff --git a/tests/resources/merge-resolve/.gitted/objects/23/ed141a6ae1e798b2f721afedbe947c119111ba b/tests/resources/merge-resolve/.gitted/objects/23/ed141a6ae1e798b2f721afedbe947c119111ba
new file mode 100644
index 0000000..06dee3b
Binary files /dev/null and b/tests/resources/merge-resolve/.gitted/objects/23/ed141a6ae1e798b2f721afedbe947c119111ba differ
diff --git a/tests/resources/merge-resolve/.gitted/objects/27/4bbe983022fb4c02f8a2bf2ebe8da4fe130054 b/tests/resources/merge-resolve/.gitted/objects/27/4bbe983022fb4c02f8a2bf2ebe8da4fe130054
new file mode 100644
index 0000000..c7afad2
Binary files /dev/null and b/tests/resources/merge-resolve/.gitted/objects/27/4bbe983022fb4c02f8a2bf2ebe8da4fe130054 differ
diff --git a/tests/resources/merge-resolve/.gitted/objects/2b/fdd7e1b6c6ae993f23dfe8e84a8e06a772fa2a b/tests/resources/merge-resolve/.gitted/objects/2b/fdd7e1b6c6ae993f23dfe8e84a8e06a772fa2a
new file mode 100644
index 0000000..c86edfb
Binary files /dev/null and b/tests/resources/merge-resolve/.gitted/objects/2b/fdd7e1b6c6ae993f23dfe8e84a8e06a772fa2a differ
diff --git a/tests/resources/merge-resolve/.gitted/objects/34/8dcd41e2b467991578e92bedd16971b877ef1e b/tests/resources/merge-resolve/.gitted/objects/34/8dcd41e2b467991578e92bedd16971b877ef1e
new file mode 100644
index 0000000..fd61b6c
Binary files /dev/null and b/tests/resources/merge-resolve/.gitted/objects/34/8dcd41e2b467991578e92bedd16971b877ef1e differ
diff --git a/tests/resources/merge-resolve/.gitted/objects/42/18670ab81cc219a9f94befb5c5dad90ec52648 b/tests/resources/merge-resolve/.gitted/objects/42/18670ab81cc219a9f94befb5c5dad90ec52648
new file mode 100644
index 0000000..33ead61
Binary files /dev/null and b/tests/resources/merge-resolve/.gitted/objects/42/18670ab81cc219a9f94befb5c5dad90ec52648 differ
diff --git a/tests/resources/merge-resolve/.gitted/objects/49/fd9edac79d15c8fbfca2d481cbb900beba22a6 b/tests/resources/merge-resolve/.gitted/objects/49/fd9edac79d15c8fbfca2d481cbb900beba22a6
new file mode 100644
index 0000000..d808d9f
--- /dev/null
+++ b/tests/resources/merge-resolve/.gitted/objects/49/fd9edac79d15c8fbfca2d481cbb900beba22a6
@@ -0,0 +1,3 @@
+xU
+0D=+
+f5dI~Ehe3x2?ذ$Ɂ%+"SRAWRm Kn\tXZ/hMƱߙg2j>#
\ No newline at end of file
diff --git a/tests/resources/merge-resolve/.gitted/objects/58/87a5e516c53bd58efb0f02ec6aa031b6fe9ad7 b/tests/resources/merge-resolve/.gitted/objects/58/87a5e516c53bd58efb0f02ec6aa031b6fe9ad7
new file mode 100644
index 0000000..550d288
Binary files /dev/null and b/tests/resources/merge-resolve/.gitted/objects/58/87a5e516c53bd58efb0f02ec6aa031b6fe9ad7 differ
diff --git a/tests/resources/merge-resolve/.gitted/objects/60/61fe116ecba0800c26113ea1a7dfac2e16eeaf b/tests/resources/merge-resolve/.gitted/objects/60/61fe116ecba0800c26113ea1a7dfac2e16eeaf
new file mode 100644
index 0000000..3f266f6
Binary files /dev/null and b/tests/resources/merge-resolve/.gitted/objects/60/61fe116ecba0800c26113ea1a7dfac2e16eeaf differ
diff --git a/tests/resources/merge-resolve/.gitted/objects/62/33c6a0670228627f93c01cef32485a30403670 b/tests/resources/merge-resolve/.gitted/objects/62/33c6a0670228627f93c01cef32485a30403670
new file mode 100644
index 0000000..81428dd
Binary files /dev/null and b/tests/resources/merge-resolve/.gitted/objects/62/33c6a0670228627f93c01cef32485a30403670 differ
diff --git a/tests/resources/merge-resolve/.gitted/objects/67/110d77886b2af6309b9212961e72b8583e5fa9 b/tests/resources/merge-resolve/.gitted/objects/67/110d77886b2af6309b9212961e72b8583e5fa9
new file mode 100644
index 0000000..877bad7
--- /dev/null
+++ b/tests/resources/merge-resolve/.gitted/objects/67/110d77886b2af6309b9212961e72b8583e5fa9
@@ -0,0 +1 @@
+x=N1^r !J:.`'lP^gT343Ҕup*Z %l4irHz,곥[M]aJҐb5l8OX$XճEa")U$d2zODŽų>m'qZ渍O`lFO1!n'=-]A&e˯^o^
\ No newline at end of file
diff --git a/tests/resources/merge-resolve/.gitted/objects/6e/3b9eb35214d4e31ed5789afc7d520ac798ce55 b/tests/resources/merge-resolve/.gitted/objects/6e/3b9eb35214d4e31ed5789afc7d520ac798ce55
new file mode 100644
index 0000000..c6100cb
Binary files /dev/null and b/tests/resources/merge-resolve/.gitted/objects/6e/3b9eb35214d4e31ed5789afc7d520ac798ce55 differ
diff --git a/tests/resources/merge-resolve/.gitted/objects/72/cdb057b340205164478565e91eb71647e66891 b/tests/resources/merge-resolve/.gitted/objects/72/cdb057b340205164478565e91eb71647e66891
new file mode 100644
index 0000000..84aa833
Binary files /dev/null and b/tests/resources/merge-resolve/.gitted/objects/72/cdb057b340205164478565e91eb71647e66891 differ
diff --git a/tests/resources/merge-resolve/.gitted/objects/7a/f14d9c679baaef35555095f4f5d33e9a569ab9 b/tests/resources/merge-resolve/.gitted/objects/7a/f14d9c679baaef35555095f4f5d33e9a569ab9
new file mode 100644
index 0000000..b4c4ef7
Binary files /dev/null and b/tests/resources/merge-resolve/.gitted/objects/7a/f14d9c679baaef35555095f4f5d33e9a569ab9 differ
diff --git a/tests/resources/merge-resolve/.gitted/objects/7c/04ca611203ed320c5f495b9813054dd23be3be b/tests/resources/merge-resolve/.gitted/objects/7c/04ca611203ed320c5f495b9813054dd23be3be
new file mode 100644
index 0000000..e3ba605
--- /dev/null
+++ b/tests/resources/merge-resolve/.gitted/objects/7c/04ca611203ed320c5f495b9813054dd23be3be
@@ -0,0 +1,2 @@
+xQ D{
-,tc^`%b(K|ͼd&k)Dsl<f4a1B8zsCvŘEQdO>E#}%xuz{yV%rɐdžp֨tDŽ
+UrL
\ No newline at end of file
diff --git a/tests/resources/merge-resolve/.gitted/objects/81/1c70fcb6d5bbd022d04cc31836d30b436f9551 b/tests/resources/merge-resolve/.gitted/objects/81/1c70fcb6d5bbd022d04cc31836d30b436f9551
new file mode 100644
index 0000000..6d87024
Binary files /dev/null and b/tests/resources/merge-resolve/.gitted/objects/81/1c70fcb6d5bbd022d04cc31836d30b436f9551 differ
diff --git a/tests/resources/merge-resolve/.gitted/objects/83/6b8b82b26cab22eaaed8820877c76d6c8bca19 b/tests/resources/merge-resolve/.gitted/objects/83/6b8b82b26cab22eaaed8820877c76d6c8bca19
new file mode 100644
index 0000000..99f8286
Binary files /dev/null and b/tests/resources/merge-resolve/.gitted/objects/83/6b8b82b26cab22eaaed8820877c76d6c8bca19 differ
diff --git a/tests/resources/merge-resolve/.gitted/objects/8b/7cd60d49ce3a1a770ece43b7d29b5cf462a33a b/tests/resources/merge-resolve/.gitted/objects/8b/7cd60d49ce3a1a770ece43b7d29b5cf462a33a
new file mode 100644
index 0000000..790750c
Binary files /dev/null and b/tests/resources/merge-resolve/.gitted/objects/8b/7cd60d49ce3a1a770ece43b7d29b5cf462a33a differ
diff --git a/tests/resources/merge-resolve/.gitted/objects/91/f44111cb1cb1358ac6944ad356ca1738813ea1 b/tests/resources/merge-resolve/.gitted/objects/91/f44111cb1cb1358ac6944ad356ca1738813ea1
new file mode 100644
index 0000000..51a456f
Binary files /dev/null and b/tests/resources/merge-resolve/.gitted/objects/91/f44111cb1cb1358ac6944ad356ca1738813ea1 differ
diff --git a/tests/resources/merge-resolve/.gitted/objects/96/bca8d4f05cc4c5e33e4389f80a1309e86fe054 b/tests/resources/merge-resolve/.gitted/objects/96/bca8d4f05cc4c5e33e4389f80a1309e86fe054
new file mode 100644
index 0000000..8938d3e
Binary files /dev/null and b/tests/resources/merge-resolve/.gitted/objects/96/bca8d4f05cc4c5e33e4389f80a1309e86fe054 differ
diff --git a/tests/resources/merge-resolve/.gitted/objects/ad/01aebfdf2ac13145efafe3f9fcf798882f1730 b/tests/resources/merge-resolve/.gitted/objects/ad/01aebfdf2ac13145efafe3f9fcf798882f1730
new file mode 100644
index 0000000..ae3ef8c
Binary files /dev/null and b/tests/resources/merge-resolve/.gitted/objects/ad/01aebfdf2ac13145efafe3f9fcf798882f1730 differ
diff --git a/tests/resources/merge-resolve/.gitted/objects/ad/26b598134264fd284292cb233fc0b2f25851da b/tests/resources/merge-resolve/.gitted/objects/ad/26b598134264fd284292cb233fc0b2f25851da
new file mode 100644
index 0000000..5819a2e
Binary files /dev/null and b/tests/resources/merge-resolve/.gitted/objects/ad/26b598134264fd284292cb233fc0b2f25851da differ
diff --git a/tests/resources/merge-resolve/.gitted/objects/ca/ff6b7d44973f53e3e0cf31d0d695188b19aec6 b/tests/resources/merge-resolve/.gitted/objects/ca/ff6b7d44973f53e3e0cf31d0d695188b19aec6
new file mode 100644
index 0000000..6d0f600
Binary files /dev/null and b/tests/resources/merge-resolve/.gitted/objects/ca/ff6b7d44973f53e3e0cf31d0d695188b19aec6 differ
diff --git a/tests/resources/merge-resolve/.gitted/objects/cc/338e4710c9b257106b8d16d82f86458d5beaf1 b/tests/resources/merge-resolve/.gitted/objects/cc/338e4710c9b257106b8d16d82f86458d5beaf1
new file mode 100644
index 0000000..85b3b81
--- /dev/null
+++ b/tests/resources/merge-resolve/.gitted/objects/cc/338e4710c9b257106b8d16d82f86458d5beaf1
@@ -0,0 +1,2 @@
+xK!]s3`bo1gpWEGmx]6d
+eaΉ碵z.Dv [hD[JﱶwX[.2nuVƉZڳF!x88GPP_?KN
\ No newline at end of file
diff --git a/tests/resources/merge-resolve/.gitted/objects/d3/3cedf513c059e0515653fa2c2e386631387a05 b/tests/resources/merge-resolve/.gitted/objects/d3/3cedf513c059e0515653fa2c2e386631387a05
new file mode 100644
index 0000000..d6d4c2b
Binary files /dev/null and b/tests/resources/merge-resolve/.gitted/objects/d3/3cedf513c059e0515653fa2c2e386631387a05 differ
diff --git a/tests/resources/merge-resolve/.gitted/objects/d7/308cc367b2cc23f710834ec1fd8ffbacf1b460 b/tests/resources/merge-resolve/.gitted/objects/d7/308cc367b2cc23f710834ec1fd8ffbacf1b460
new file mode 100644
index 0000000..b02cda4
--- /dev/null
+++ b/tests/resources/merge-resolve/.gitted/objects/d7/308cc367b2cc23f710834ec1fd8ffbacf1b460
@@ -0,0 +1 @@
+xK @]s)Ё7]I(x{^,nлSo`/X)ٙB@GÔaD 4xwlCv?-79d,hF4Z
;ƝH}=
\ No newline at end of file
diff --git a/tests/resources/merge-resolve/.gitted/objects/d8/dec75ff2f8b41d1c5bfef0cd57b7300c834f66 b/tests/resources/merge-resolve/.gitted/objects/d8/dec75ff2f8b41d1c5bfef0cd57b7300c834f66
new file mode 100644
index 0000000..74f807e
Binary files /dev/null and b/tests/resources/merge-resolve/.gitted/objects/d8/dec75ff2f8b41d1c5bfef0cd57b7300c834f66 differ
diff --git a/tests/resources/merge-resolve/.gitted/objects/dd/2ae5ab264e5592aa754235d5ad5eac8f0ecdfd b/tests/resources/merge-resolve/.gitted/objects/dd/2ae5ab264e5592aa754235d5ad5eac8f0ecdfd
new file mode 100644
index 0000000..55626a5
Binary files /dev/null and b/tests/resources/merge-resolve/.gitted/objects/dd/2ae5ab264e5592aa754235d5ad5eac8f0ecdfd differ
diff --git a/tests/resources/merge-resolve/.gitted/objects/e5/060729746ca9888239cba08fdcf4bee907b406 b/tests/resources/merge-resolve/.gitted/objects/e5/060729746ca9888239cba08fdcf4bee907b406
new file mode 100644
index 0000000..33299c2
Binary files /dev/null and b/tests/resources/merge-resolve/.gitted/objects/e5/060729746ca9888239cba08fdcf4bee907b406 differ
diff --git a/tests/resources/merge-resolve/.gitted/objects/f2/e1550a0c9e53d5811175864a29536642ae3821 b/tests/resources/merge-resolve/.gitted/objects/f2/e1550a0c9e53d5811175864a29536642ae3821
new file mode 100644
index 0000000..1fdcbe2
Binary files /dev/null and b/tests/resources/merge-resolve/.gitted/objects/f2/e1550a0c9e53d5811175864a29536642ae3821 differ
diff --git a/tests/resources/merge-resolve/.gitted/objects/f6/65b45cde9b568009c6e6b7b568e89cfe717df8 b/tests/resources/merge-resolve/.gitted/objects/f6/65b45cde9b568009c6e6b7b568e89cfe717df8
new file mode 100644
index 0000000..7af50d7
Binary files /dev/null and b/tests/resources/merge-resolve/.gitted/objects/f6/65b45cde9b568009c6e6b7b568e89cfe717df8 differ
diff --git a/tests/resources/merge-resolve/.gitted/refs/heads/submodules b/tests/resources/merge-resolve/.gitted/refs/heads/submodules
new file mode 100644
index 0000000..e5511ec
--- /dev/null
+++ b/tests/resources/merge-resolve/.gitted/refs/heads/submodules
@@ -0,0 +1 @@
+d8dec75ff2f8b41d1c5bfef0cd57b7300c834f66
diff --git a/tests/resources/merge-resolve/.gitted/refs/heads/submodules-branch b/tests/resources/merge-resolve/.gitted/refs/heads/submodules-branch
new file mode 100644
index 0000000..7d47e07
--- /dev/null
+++ b/tests/resources/merge-resolve/.gitted/refs/heads/submodules-branch
@@ -0,0 +1 @@
+811c70fcb6d5bbd022d04cc31836d30b436f9551
diff --git a/tests/resources/merge-resolve/.gitted/refs/heads/submodules-branch2 b/tests/resources/merge-resolve/.gitted/refs/heads/submodules-branch2
new file mode 100644
index 0000000..ced60d8
--- /dev/null
+++ b/tests/resources/merge-resolve/.gitted/refs/heads/submodules-branch2
@@ -0,0 +1 @@
+7c04ca611203ed320c5f495b9813054dd23be3be
diff --git a/tests/resources/revert/.gitted/index b/tests/resources/revert/.gitted/index
index 87419ff..3513c04 100644
Binary files a/tests/resources/revert/.gitted/index and b/tests/resources/revert/.gitted/index differ
diff --git a/tests/resources/revert/.gitted/objects/0a/d19525be6d8cae5e5deb2770fc244b65255057 b/tests/resources/revert/.gitted/objects/0a/d19525be6d8cae5e5deb2770fc244b65255057
new file mode 100644
index 0000000..4aa0459
Binary files /dev/null and b/tests/resources/revert/.gitted/objects/0a/d19525be6d8cae5e5deb2770fc244b65255057 differ
diff --git a/tests/resources/revert/.gitted/objects/13/a6fdfd10bd74b1f258fb58801215985dd2e797 b/tests/resources/revert/.gitted/objects/13/a6fdfd10bd74b1f258fb58801215985dd2e797
new file mode 100644
index 0000000..3c54aab
Binary files /dev/null and b/tests/resources/revert/.gitted/objects/13/a6fdfd10bd74b1f258fb58801215985dd2e797 differ
diff --git a/tests/resources/revert/.gitted/objects/1b/c915c5cb7185a9438de28a7b1a7dfe8c01ee7f b/tests/resources/revert/.gitted/objects/1b/c915c5cb7185a9438de28a7b1a7dfe8c01ee7f
new file mode 100644
index 0000000..0a6955b
Binary files /dev/null and b/tests/resources/revert/.gitted/objects/1b/c915c5cb7185a9438de28a7b1a7dfe8c01ee7f differ
diff --git a/tests/resources/revert/.gitted/objects/1f/f0c423042b46cb1d617b81efb715defbe8054d b/tests/resources/revert/.gitted/objects/1f/f0c423042b46cb1d617b81efb715defbe8054d
new file mode 100644
index 0000000..2ed1a22
Binary files /dev/null and b/tests/resources/revert/.gitted/objects/1f/f0c423042b46cb1d617b81efb715defbe8054d differ
diff --git a/tests/resources/revert/.gitted/objects/21/a96a98ed84d45866e1de6e266fd3a61a4ae9dc b/tests/resources/revert/.gitted/objects/21/a96a98ed84d45866e1de6e266fd3a61a4ae9dc
new file mode 100644
index 0000000..95842db
Binary files /dev/null and b/tests/resources/revert/.gitted/objects/21/a96a98ed84d45866e1de6e266fd3a61a4ae9dc differ
diff --git a/tests/resources/revert/.gitted/objects/39/9fb3aba3d9d13f7d40a9254ce4402067ef3149 b/tests/resources/revert/.gitted/objects/39/9fb3aba3d9d13f7d40a9254ce4402067ef3149
new file mode 100644
index 0000000..6cb6839
--- /dev/null
+++ b/tests/resources/revert/.gitted/objects/39/9fb3aba3d9d13f7d40a9254ce4402067ef3149
@@ -0,0 +1,2 @@
+xK!]s
+.;@bozA\0m<֞C,3d@_D @K6ŗ5T=oS$T1.%@zQ["-D x]ry<o];\ ]1YQEĤ$l<,`aGN
\ No newline at end of file
diff --git a/tests/resources/revert/.gitted/objects/46/ff0854663aeb2182b9838c8da68e33ac23bc1e b/tests/resources/revert/.gitted/objects/46/ff0854663aeb2182b9838c8da68e33ac23bc1e
new file mode 100644
index 0000000..7064dab
Binary files /dev/null and b/tests/resources/revert/.gitted/objects/46/ff0854663aeb2182b9838c8da68e33ac23bc1e differ
diff --git a/tests/resources/revert/.gitted/objects/5c/f1d643f100d8112834e540264546ba2c159976 b/tests/resources/revert/.gitted/objects/5c/f1d643f100d8112834e540264546ba2c159976
new file mode 100644
index 0000000..dbbf711
Binary files /dev/null and b/tests/resources/revert/.gitted/objects/5c/f1d643f100d8112834e540264546ba2c159976 differ
diff --git a/tests/resources/revert/.gitted/objects/6b/ccd0dc58cea5ccff86014f3d64b31bd8c02a37 b/tests/resources/revert/.gitted/objects/6b/ccd0dc58cea5ccff86014f3d64b31bd8c02a37
new file mode 100644
index 0000000..2664da4
Binary files /dev/null and b/tests/resources/revert/.gitted/objects/6b/ccd0dc58cea5ccff86014f3d64b31bd8c02a37 differ
diff --git a/tests/resources/revert/.gitted/objects/71/eb9c2b53dbbf3c45fb28b27c850db4b7fb8011 b/tests/resources/revert/.gitted/objects/71/eb9c2b53dbbf3c45fb28b27c850db4b7fb8011
new file mode 100644
index 0000000..995a1e6
Binary files /dev/null and b/tests/resources/revert/.gitted/objects/71/eb9c2b53dbbf3c45fb28b27c850db4b7fb8011 differ
diff --git a/tests/resources/revert/.gitted/objects/87/59ad453cf01cf7daf14e2a668f8218f9a678eb b/tests/resources/revert/.gitted/objects/87/59ad453cf01cf7daf14e2a668f8218f9a678eb
new file mode 100644
index 0000000..ab19acf
Binary files /dev/null and b/tests/resources/revert/.gitted/objects/87/59ad453cf01cf7daf14e2a668f8218f9a678eb differ
diff --git a/tests/resources/revert/.gitted/objects/9a/95fd974e03c5b93828ceedd28755965b5d5c60 b/tests/resources/revert/.gitted/objects/9a/95fd974e03c5b93828ceedd28755965b5d5c60
new file mode 100644
index 0000000..bb93a34
Binary files /dev/null and b/tests/resources/revert/.gitted/objects/9a/95fd974e03c5b93828ceedd28755965b5d5c60 differ
diff --git a/tests/resources/revert/.gitted/objects/a8/c86221b400b836010567cc3593db6e96c1a83a b/tests/resources/revert/.gitted/objects/a8/c86221b400b836010567cc3593db6e96c1a83a
new file mode 100644
index 0000000..2965461
Binary files /dev/null and b/tests/resources/revert/.gitted/objects/a8/c86221b400b836010567cc3593db6e96c1a83a differ
diff --git a/tests/resources/revert/.gitted/objects/ac/c4d33902092efeb3b714aa0b1007c329e2f2e6 b/tests/resources/revert/.gitted/objects/ac/c4d33902092efeb3b714aa0b1007c329e2f2e6
new file mode 100644
index 0000000..91bb68b
--- /dev/null
+++ b/tests/resources/revert/.gitted/objects/ac/c4d33902092efeb3b714aa0b1007c329e2f2e6
@@ -0,0 +1,2 @@
+x[
+1@QJW
t6 F,LW8pe1llU.LiTB<dQuȉ#MTI"v?O7ঽ>dN0z"!:ML䮽$
\ No newline at end of file
diff --git a/tests/resources/revert/.gitted/objects/b6/9d88e177455579896e2be495046e2a51456a9a b/tests/resources/revert/.gitted/objects/b6/9d88e177455579896e2be495046e2a51456a9a
new file mode 100644
index 0000000..a5f69f2
--- /dev/null
+++ b/tests/resources/revert/.gitted/objects/b6/9d88e177455579896e2be495046e2a51456a9a
@@ -0,0 +1 @@
+x]j!*.yoљ{R
l@NFZԴ$@o 54@+z-FP2{Hn"zZR.<J|ˀ2Ț:VfR ´Xanc
>5VsNShuC4Yk;݇q߱
8ZF*W+B\ԡ=,uwd
\ No newline at end of file
diff --git a/tests/resources/revert/.gitted/objects/ca/f99de3a49827117bb66721010eac461b06a80c b/tests/resources/revert/.gitted/objects/ca/f99de3a49827117bb66721010eac461b06a80c
new file mode 100644
index 0000000..7f6f4e0
Binary files /dev/null and b/tests/resources/revert/.gitted/objects/ca/f99de3a49827117bb66721010eac461b06a80c differ
diff --git a/tests/resources/revert/.gitted/objects/de/03538407ed18914ff05657eeff70425c0f304d b/tests/resources/revert/.gitted/objects/de/03538407ed18914ff05657eeff70425c0f304d
new file mode 100644
index 0000000..e651676
--- /dev/null
+++ b/tests/resources/revert/.gitted/objects/de/03538407ed18914ff05657eeff70425c0f304d
@@ -0,0 +1,2 @@
+x]J1})}wIw~D|H:vlL;|)MPLeYuY}ԩ+mX2g0.{z,U5_'!ʂ5i!agǼ+ko{{i:3,u
H1"#=NGyON
+Zy2rvh(KabdV[uFrRW(1|_c&
\ No newline at end of file
diff --git a/tests/resources/revert/.gitted/objects/e3/4ef1afe54eb526fd92eec66084125f340f1d65 b/tests/resources/revert/.gitted/objects/e3/4ef1afe54eb526fd92eec66084125f340f1d65
new file mode 100644
index 0000000..fc19ebd
Binary files /dev/null and b/tests/resources/revert/.gitted/objects/e3/4ef1afe54eb526fd92eec66084125f340f1d65 differ
diff --git a/tests/resources/revert/.gitted/objects/ea/392a157085bc32daccd59aa1998fe2f5fb9fc0 b/tests/resources/revert/.gitted/objects/ea/392a157085bc32daccd59aa1998fe2f5fb9fc0
new file mode 100644
index 0000000..1451a6a
Binary files /dev/null and b/tests/resources/revert/.gitted/objects/ea/392a157085bc32daccd59aa1998fe2f5fb9fc0 differ
diff --git a/tests/resources/revert/.gitted/objects/ee/c6adcb2f3ceca0cadeccfe01b19382252ece9b b/tests/resources/revert/.gitted/objects/ee/c6adcb2f3ceca0cadeccfe01b19382252ece9b
new file mode 100644
index 0000000..f59f3d4
Binary files /dev/null and b/tests/resources/revert/.gitted/objects/ee/c6adcb2f3ceca0cadeccfe01b19382252ece9b differ
diff --git a/tests/resources/revert/.gitted/refs/heads/master b/tests/resources/revert/.gitted/refs/heads/master
index d3850da..180f407 100644
--- a/tests/resources/revert/.gitted/refs/heads/master
+++ b/tests/resources/revert/.gitted/refs/heads/master
@@ -1 +1 @@
-2d440f2b3147d3dc7ad1085813478d6d869d5a4d
+2d440f2b3147d3dc7ad1085813478d6d869d5a4d
diff --git a/tests/resources/revert/.gitted/refs/heads/two b/tests/resources/revert/.gitted/refs/heads/two
new file mode 100644
index 0000000..f31ec00
--- /dev/null
+++ b/tests/resources/revert/.gitted/refs/heads/two
@@ -0,0 +1 @@
+e34ef1afe54eb526fd92eec66084125f340f1d65
diff --git a/tests/revert/workdir.c b/tests/revert/workdir.c
index 9dc72a9..5be397c 100644
--- a/tests/revert/workdir.c
+++ b/tests/revert/workdir.c
@@ -137,6 +137,203 @@ void test_revert_workdir__orphan(void)
git_commit_free(head);
}
+/*
+ * revert the same commit twice (when the first reverts cleanly):
+ *
+ * git revert 2d440f2
+ * git revert 2d440f2
+ */
+void test_revert_workdir__again(void)
+{
+ git_reference *head_ref;
+ git_commit *orig_head;
+ git_tree *reverted_tree;
+ git_oid reverted_tree_oid, reverted_commit_oid;
+ git_signature *signature;
+
+ struct merge_index_entry merge_index_entries[] = {
+ { 0100644, "7731926a337c4eaba1e2187d90ebfa0a93659382", 0, "file1.txt" },
+ { 0100644, "0ab09ea6d4c3634bdf6c221626d8b6f7dd890767", 0, "file2.txt" },
+ { 0100644, "f4e107c230d08a60fb419d19869f1f282b272d9c", 0, "file3.txt" },
+ { 0100644, "0f5bfcf58c558d865da6be0281d7795993646cee", 0, "file6.txt" },
+ };
+
+ cl_git_pass(git_repository_head(&head_ref, repo));
+ cl_git_pass(git_reference_peel((git_object **)&orig_head, head_ref, GIT_OBJ_COMMIT));
+ cl_git_pass(git_reset(repo, (git_object *)orig_head, GIT_RESET_HARD));
+
+ cl_git_pass(git_revert(repo, orig_head, NULL));
+
+ cl_assert(merge_test_index(repo_index, merge_index_entries, 4));
+
+ cl_git_pass(git_index_write_tree(&reverted_tree_oid, repo_index));
+ cl_git_pass(git_tree_lookup(&reverted_tree, repo, &reverted_tree_oid));
+
+ cl_git_pass(git_signature_new(&signature, "Reverter", "reverter@example.org", time(NULL), 0));
+ cl_git_pass(git_commit_create(&reverted_commit_oid, repo, "HEAD", signature, signature, NULL, "Reverted!", reverted_tree, 1, (const git_commit **)&orig_head));
+
+ cl_git_pass(git_revert(repo, orig_head, NULL));
+ cl_assert(merge_test_index(repo_index, merge_index_entries, 4));
+
+ git_signature_free(signature);
+ git_tree_free(reverted_tree);
+ git_commit_free(orig_head);
+ git_reference_free(head_ref);
+}
+
+/* git reset --hard 72333f47d4e83616630ff3b0ffe4c0faebcc3c45
+ * git revert --no-commit d1d403d22cbe24592d725f442835cf46fe60c8ac */
+void test_revert_workdir__again_after_automerge(void)
+{
+ git_commit *head, *commit;
+ git_tree *reverted_tree;
+ git_oid head_oid, revert_oid, reverted_tree_oid, reverted_commit_oid;
+ git_signature *signature;
+
+ struct merge_index_entry merge_index_entries[] = {
+ { 0100644, "caf99de3a49827117bb66721010eac461b06a80c", 0, "file1.txt" },
+ { 0100644, "0ab09ea6d4c3634bdf6c221626d8b6f7dd890767", 0, "file2.txt" },
+ { 0100644, "f4e107c230d08a60fb419d19869f1f282b272d9c", 0, "file3.txt" },
+ { 0100644, "0f5bfcf58c558d865da6be0281d7795993646cee", 0, "file6.txt" },
+ };
+
+ struct merge_index_entry second_revert_entries[] = {
+ { 0100644, "3a3ef367eaf3fe79effbfb0a56b269c04c2b59fe", 1, "file1.txt" },
+ { 0100644, "caf99de3a49827117bb66721010eac461b06a80c", 2, "file1.txt" },
+ { 0100644, "747726e021bc5f44b86de60e3032fd6f9f1b8383", 3, "file1.txt" },
+ { 0100644, "0ab09ea6d4c3634bdf6c221626d8b6f7dd890767", 0, "file2.txt" },
+ { 0100644, "f4e107c230d08a60fb419d19869f1f282b272d9c", 0, "file3.txt" },
+ { 0100644, "0f5bfcf58c558d865da6be0281d7795993646cee", 0, "file6.txt" },
+ };
+
+ git_oid_fromstr(&head_oid, "72333f47d4e83616630ff3b0ffe4c0faebcc3c45");
+ cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
+ cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD));
+
+ git_oid_fromstr(&revert_oid, "d1d403d22cbe24592d725f442835cf46fe60c8ac");
+ cl_git_pass(git_commit_lookup(&commit, repo, &revert_oid));
+ cl_git_pass(git_revert(repo, commit, NULL));
+
+ cl_assert(merge_test_index(repo_index, merge_index_entries, 4));
+
+ cl_git_pass(git_index_write_tree(&reverted_tree_oid, repo_index));
+ cl_git_pass(git_tree_lookup(&reverted_tree, repo, &reverted_tree_oid));
+
+ cl_git_pass(git_signature_new(&signature, "Reverter", "reverter@example.org", time(NULL), 0));
+ cl_git_pass(git_commit_create(&reverted_commit_oid, repo, "HEAD", signature, signature, NULL, "Reverted!", reverted_tree, 1, (const git_commit **)&head));
+
+ cl_git_pass(git_revert(repo, commit, NULL));
+ cl_assert(merge_test_index(repo_index, second_revert_entries, 6));
+
+ git_signature_free(signature);
+ git_tree_free(reverted_tree);
+ git_commit_free(commit);
+ git_commit_free(head);
+}
+
+/*
+ * revert the same commit twice (when the first reverts cleanly):
+ *
+ * git revert 2d440f2
+ * git revert 2d440f2
+ */
+void test_revert_workdir__again_after_edit(void)
+{
+ git_reference *head_ref;
+ git_commit *orig_head, *commit;
+ git_tree *reverted_tree;
+ git_oid orig_head_oid, revert_oid, reverted_tree_oid, reverted_commit_oid;
+ git_signature *signature;
+
+ struct merge_index_entry merge_index_entries[] = {
+ { 0100644, "3721552e06c4bdc7d478e0674e6304888545d5fd", 0, "file1.txt" },
+ { 0100644, "0ab09ea6d4c3634bdf6c221626d8b6f7dd890767", 0, "file2.txt" },
+ { 0100644, "f4e107c230d08a60fb419d19869f1f282b272d9c", 0, "file3.txt" },
+ { 0100644, "0f5bfcf58c558d865da6be0281d7795993646cee", 0, "file6.txt" },
+ };
+
+ cl_git_pass(git_repository_head(&head_ref, repo));
+
+ cl_git_pass(git_oid_fromstr(&orig_head_oid, "399fb3aba3d9d13f7d40a9254ce4402067ef3149"));
+ cl_git_pass(git_commit_lookup(&orig_head, repo, &orig_head_oid));
+ cl_git_pass(git_reset(repo, (git_object *)orig_head, GIT_RESET_HARD));
+
+ cl_git_pass(git_oid_fromstr(&revert_oid, "2d440f2b3147d3dc7ad1085813478d6d869d5a4d"));
+ cl_git_pass(git_commit_lookup(&commit, repo, &revert_oid));
+
+ cl_git_pass(git_revert(repo, commit, NULL));
+
+ cl_assert(merge_test_index(repo_index, merge_index_entries, 4));
+
+ cl_git_pass(git_index_write_tree(&reverted_tree_oid, repo_index));
+ cl_git_pass(git_tree_lookup(&reverted_tree, repo, &reverted_tree_oid));
+
+ cl_git_pass(git_signature_new(&signature, "Reverter", "reverter@example.org", time(NULL), 0));
+ cl_git_pass(git_commit_create(&reverted_commit_oid, repo, "HEAD", signature, signature, NULL, "Reverted!", reverted_tree, 1, (const git_commit **)&orig_head));
+
+ cl_git_pass(git_revert(repo, commit, NULL));
+ cl_assert(merge_test_index(repo_index, merge_index_entries, 4));
+
+ git_signature_free(signature);
+ git_tree_free(reverted_tree);
+ git_commit_free(commit);
+ git_commit_free(orig_head);
+ git_reference_free(head_ref);
+}
+
+/*
+ * revert the same commit twice (when the first reverts cleanly):
+ *
+ * git reset --hard e34ef1a
+ * git revert 71eb9c2
+ */
+void test_revert_workdir__again_after_edit_two(void)
+{
+ git_buf diff_buf = GIT_BUF_INIT;
+ git_config *config;
+ git_oid head_commit_oid, revert_commit_oid;
+ git_commit *head_commit, *revert_commit;
+
+ struct merge_index_entry merge_index_entries[] = {
+ { 0100644, "1ff0c423042b46cb1d617b81efb715defbe8054d", 0, ".gitattributes" },
+ { 0100644, "1bc915c5cb7185a9438de28a7b1a7dfe8c01ee7f", 0, ".gitignore" },
+ { 0100644, "a8c86221b400b836010567cc3593db6e96c1a83a", 1, "file.txt" },
+ { 0100644, "46ff0854663aeb2182b9838c8da68e33ac23bc1e", 2, "file.txt" },
+ { 0100644, "21a96a98ed84d45866e1de6e266fd3a61a4ae9dc", 3, "file.txt" },
+ };
+
+ cl_git_pass(git_repository_config(&config, repo));
+ cl_git_pass(git_config_set_bool(config, "core.autocrlf", 0));
+
+ cl_git_pass(git_oid_fromstr(&head_commit_oid, "e34ef1afe54eb526fd92eec66084125f340f1d65"));
+ cl_git_pass(git_commit_lookup(&head_commit, repo, &head_commit_oid));
+ cl_git_pass(git_reset(repo, (git_object *)head_commit, GIT_RESET_HARD));
+
+ cl_git_pass(git_oid_fromstr(&revert_commit_oid, "71eb9c2b53dbbf3c45fb28b27c850db4b7fb8011"));
+ cl_git_pass(git_commit_lookup(&revert_commit, repo, &revert_commit_oid));
+
+ cl_git_pass(git_revert(repo, revert_commit, NULL));
+
+ cl_assert(merge_test_index(repo_index, merge_index_entries, 5));
+
+ cl_git_pass(git_futils_readbuffer(&diff_buf, "revert/file.txt"));
+ cl_assert(strcmp(diff_buf.ptr, "a\n" \
+ "<<<<<<< HEAD\n" \
+ "=======\n" \
+ "a\n" \
+ ">>>>>>> parent of 71eb9c2... revert me\n" \
+ "a\n" \
+ "a\n" \
+ "a\n" \
+ "a\n" \
+ "ab\n") == 0);
+
+ git_commit_free(revert_commit);
+ git_commit_free(head_commit);
+ git_config_free(config);
+ git_buf_free(&diff_buf);
+}
+
/* git reset --hard 72333f47d4e83616630ff3b0ffe4c0faebcc3c45
* git revert --no-commit d1d403d22cbe24592d725f442835cf46fe60c8ac */
void test_revert_workdir__conflict_use_ours(void)
@@ -146,22 +343,19 @@ void test_revert_workdir__conflict_use_ours(void)
git_revert_opts opts = GIT_REVERT_OPTS_INIT;
struct merge_index_entry merge_index_entries[] = {
- { 0100644, "3a3ef367eaf3fe79effbfb0a56b269c04c2b59fe", 1, "file1.txt" },
- { 0100644, "7731926a337c4eaba1e2187d90ebfa0a93659382", 2, "file1.txt" },
- { 0100644, "747726e021bc5f44b86de60e3032fd6f9f1b8383", 3, "file1.txt" },
+ { 0100644, "caf99de3a49827117bb66721010eac461b06a80c", 0, "file1.txt" },
{ 0100644, "0ab09ea6d4c3634bdf6c221626d8b6f7dd890767", 0, "file2.txt" },
{ 0100644, "f4e107c230d08a60fb419d19869f1f282b272d9c", 0, "file3.txt" },
{ 0100644, "0f5bfcf58c558d865da6be0281d7795993646cee", 0, "file6.txt" },
};
struct merge_index_entry merge_filesystem_entries[] = {
- { 0100644, "7731926a337c4eaba1e2187d90ebfa0a93659382", 0, "file1.txt" },
+ { 0100644, "caf99de3a49827117bb66721010eac461b06a80c", 0, "file1.txt" },
{ 0100644, "0ab09ea6d4c3634bdf6c221626d8b6f7dd890767", 0, "file2.txt" },
{ 0100644, "f4e107c230d08a60fb419d19869f1f282b272d9c", 0, "file3.txt" },
{ 0100644, "0f5bfcf58c558d865da6be0281d7795993646cee", 0, "file6.txt" },
};
- opts.merge_tree_opts.automerge_flags = GIT_MERGE_AUTOMERGE_NONE;
opts.checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_USE_OURS;
git_oid_fromstr(&head_oid, "72333f47d4e83616630ff3b0ffe4c0faebcc3c45");
@@ -172,7 +366,7 @@ void test_revert_workdir__conflict_use_ours(void)
cl_git_pass(git_commit_lookup(&commit, repo, &revert_oid));
cl_git_pass(git_revert(repo, commit, &opts));
- cl_assert(merge_test_index(repo_index, merge_index_entries, 6));
+ cl_assert(merge_test_index(repo_index, merge_index_entries, 4));
cl_assert(merge_test_workdir(repo, merge_filesystem_entries, 4));
git_commit_free(commit);