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
|
// Copyright 2022 The Jujutsu Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use std::path::Path;
use indoc::indoc;
use crate::common::create_commit_with_files;
use crate::common::CommandOutput;
use crate::common::TestEnvironment;
use crate::common::TestWorkDir;
#[must_use]
fn get_log_output(work_dir: &TestWorkDir) -> CommandOutput {
work_dir.run_jj(["log", "-T", "bookmarks"])
}
#[test]
fn test_resolution() {
let mut test_env = TestEnvironment::default();
let editor_script = test_env.set_up_fake_editor();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
create_commit_with_files(&work_dir, "base", &[], &[("file", "base\n")]);
create_commit_with_files(&work_dir, "a", &["base"], &[("file", "a\n")]);
create_commit_with_files(&work_dir, "b", &["base"], &[("file", "b\n")]);
create_commit_with_files(&work_dir, "conflict", &["a", "b"], &[]);
// Test the setup
insta::assert_snapshot!(get_log_output(&work_dir), @r"
@ conflict
├─╮
│ ○ b
○ │ a
├─╯
○ base
◆
[EOF]
");
insta::assert_snapshot!(work_dir.run_jj(["resolve", "--list"]), @r"
file 2-sided conflict
[EOF]
");
insta::assert_snapshot!(work_dir.read_file("file"), @r"
<<<<<<< Conflict 1 of 1
%%%%%%% Changes from base to side #1
-base
+a
+++++++ Contents of side #2
b
>>>>>>> Conflict 1 of 1 ends
");
// Check that output file starts out empty and resolve the conflict
std::fs::write(
&editor_script,
["dump editor0", "write\nresolution\n"].join("\0"),
)
.unwrap();
let output = work_dir.run_jj(["resolve"]);
insta::assert_snapshot!(output, @r"
------- stderr -------
Resolving conflicts in: file
Working copy (@) now at: vruxwmqv 741263c9 conflict | conflict
Parent commit (@-) : zsuskuln 45537d53 a | a
Parent commit (@-) : royxmykx 89d1b299 b | b
Added 0 files, modified 1 files, removed 0 files
[EOF]
");
insta::assert_snapshot!(
std::fs::read_to_string(test_env.env_root().join("editor0")).unwrap(), @"");
insta::assert_snapshot!(work_dir.run_jj(["diff", "--git"]), @r"
diff --git a/file b/file
index 0000000000..88425ec521 100644
--- a/file
+++ b/file
@@ -1,7 +1,1 @@
-<<<<<<< Conflict 1 of 1
-%%%%%%% Changes from base to side #1
--base
-+a
-+++++++ Contents of side #2
-b
->>>>>>> Conflict 1 of 1 ends
+resolution
[EOF]
");
insta::assert_snapshot!(work_dir.run_jj(["resolve", "--list"]), @r"
------- stderr -------
Error: No conflicts found at this revision
[EOF]
[exit status: 2]
");
// Try again with --tool=<name>
work_dir.run_jj(["undo"]).success();
std::fs::write(&editor_script, "write\nresolution\n").unwrap();
let output = work_dir.run_jj([
"resolve",
"--config=ui.merge-editor='false'",
"--tool=fake-editor",
]);
insta::assert_snapshot!(output, @r"
------- stderr -------
Resolving conflicts in: file
Working copy (@) now at: vruxwmqv 1f8a36f7 conflict | conflict
Parent commit (@-) : zsuskuln 45537d53 a | a
Parent commit (@-) : royxmykx 89d1b299 b | b
Added 0 files, modified 1 files, removed 0 files
[EOF]
");
insta::assert_snapshot!(work_dir.run_jj(["diff", "--git"]), @r"
diff --git a/file b/file
index 0000000000..88425ec521 100644
--- a/file
+++ b/file
@@ -1,7 +1,1 @@
-<<<<<<< Conflict 1 of 1
-%%%%%%% Changes from base to side #1
--base
-+a
-+++++++ Contents of side #2
-b
->>>>>>> Conflict 1 of 1 ends
+resolution
[EOF]
");
insta::assert_snapshot!(work_dir.run_jj(["resolve", "--list"]), @r"
------- stderr -------
Error: No conflicts found at this revision
[EOF]
[exit status: 2]
");
// Check that the output file starts with conflict markers if
// `merge-tool-edits-conflict-markers=true`
work_dir.run_jj(["undo"]).success();
insta::assert_snapshot!(work_dir.run_jj(["diff", "--git"]), @"");
std::fs::write(
&editor_script,
["dump editor1", "write\nresolution\n"].join("\0"),
)
.unwrap();
work_dir
.run_jj([
"resolve",
"--config=merge-tools.fake-editor.merge-tool-edits-conflict-markers=true",
])
.success();
insta::assert_snapshot!(
std::fs::read_to_string(test_env.env_root().join("editor1")).unwrap(), @r"
<<<<<<< Conflict 1 of 1
%%%%%%% Changes from base to side #1
-base
+a
+++++++ Contents of side #2
b
>>>>>>> Conflict 1 of 1 ends
");
insta::assert_snapshot!(work_dir.run_jj(["diff", "--git"]), @r"
diff --git a/file b/file
index 0000000000..88425ec521 100644
--- a/file
+++ b/file
@@ -1,7 +1,1 @@
-<<<<<<< Conflict 1 of 1
-%%%%%%% Changes from base to side #1
--base
-+a
-+++++++ Contents of side #2
-b
->>>>>>> Conflict 1 of 1 ends
+resolution
[EOF]
");
// Check that if merge tool leaves conflict markers in output file and
// `merge-tool-edits-conflict-markers=true`, these markers are properly parsed.
work_dir.run_jj(["undo"]).success();
insta::assert_snapshot!(work_dir.run_jj(["diff", "--git"]), @"");
std::fs::write(
&editor_script,
[
"dump editor2",
indoc! {"
write
<<<<<<<
%%%%%%%
-some
+fake
+++++++
conflict
>>>>>>>
"},
]
.join("\0"),
)
.unwrap();
let output = work_dir.run_jj([
"resolve",
"--config=merge-tools.fake-editor.merge-tool-edits-conflict-markers=true",
]);
insta::assert_snapshot!(output, @r###"
------- stderr -------
Resolving conflicts in: file
Working copy (@) now at: vruxwmqv 0d40d2b8 conflict | (conflict) conflict
Parent commit (@-) : zsuskuln 45537d53 a | a
Parent commit (@-) : royxmykx 89d1b299 b | b
Added 0 files, modified 1 files, removed 0 files
Warning: There are unresolved conflicts at these paths:
file 2-sided conflict
New conflicts appeared in 1 commits:
vruxwmqv 0d40d2b8 conflict | (conflict) conflict
Hint: To resolve the conflicts, start by creating a commit on top of
the conflicted commit:
jj new vruxwmqv
Then use `jj resolve`, or edit the conflict markers in the file directly.
Once the conflicts are resolved, you can inspect the result with `jj diff`.
Then run `jj squash` to move the resolution into the conflicted commit.
[EOF]
"###);
insta::assert_snapshot!(
std::fs::read_to_string(test_env.env_root().join("editor2")).unwrap(), @r"
<<<<<<< Conflict 1 of 1
%%%%%%% Changes from base to side #1
-base
+a
+++++++ Contents of side #2
b
>>>>>>> Conflict 1 of 1 ends
");
// Note the "Modified" below
insta::assert_snapshot!(work_dir.run_jj(["diff", "--git"]), @r"
diff --git a/file b/file
--- a/file
+++ b/file
@@ -1,7 +1,7 @@
<<<<<<< Conflict 1 of 1
%%%%%%% Changes from base to side #1
--base
-+a
+-some
++fake
+++++++ Contents of side #2
-b
+conflict
>>>>>>> Conflict 1 of 1 ends
[EOF]
");
insta::assert_snapshot!(work_dir.run_jj(["resolve", "--list"]), @r"
file 2-sided conflict
[EOF]
");
// Check that if merge tool leaves conflict markers in output file but
// `merge-tool-edits-conflict-markers=false` or is not specified,
// `jj` considers the conflict resolved.
work_dir.run_jj(["undo"]).success();
insta::assert_snapshot!(work_dir.run_jj(["diff", "--git"]), @"");
std::fs::write(
&editor_script,
[
"dump editor3",
indoc! {"
write
<<<<<<<
%%%%%%%
-some
+fake
+++++++
conflict
>>>>>>>
"},
]
.join("\0"),
)
.unwrap();
let output = work_dir.run_jj(["resolve"]);
insta::assert_snapshot!(output, @r"
------- stderr -------
Resolving conflicts in: file
Working copy (@) now at: vruxwmqv 2cc7f5e3 conflict | conflict
Parent commit (@-) : zsuskuln 45537d53 a | a
Parent commit (@-) : royxmykx 89d1b299 b | b
Added 0 files, modified 1 files, removed 0 files
[EOF]
");
insta::assert_snapshot!(
std::fs::read_to_string(test_env.env_root().join("editor3")).unwrap(), @"");
// Note the "Resolved" below
insta::assert_snapshot!(work_dir.run_jj(["diff", "--git"]), @r"
diff --git a/file b/file
index 0000000000..0610716cc1 100644
--- a/file
+++ b/file
@@ -1,7 +1,7 @@
-<<<<<<< Conflict 1 of 1
-%%%%%%% Changes from base to side #1
--base
-+a
-+++++++ Contents of side #2
-b
->>>>>>> Conflict 1 of 1 ends
+<<<<<<<
+%%%%%%%
+-some
++fake
++++++++
+conflict
+>>>>>>>
[EOF]
");
insta::assert_snapshot!(work_dir.run_jj(["resolve", "--list"]), @r"
------- stderr -------
Error: No conflicts found at this revision
[EOF]
[exit status: 2]
");
// Check that merge tool can override conflict marker style setting, and that
// the merge tool can output Git-style conflict markers
work_dir.run_jj(["undo"]).success();
insta::assert_snapshot!(work_dir.run_jj(["diff", "--git"]), @"");
std::fs::write(
&editor_script,
[
"dump editor4",
indoc! {"
write
<<<<<<<
some
|||||||
fake
=======
conflict
>>>>>>>
"},
]
.join("\0"),
)
.unwrap();
let output = work_dir.run_jj([
"resolve",
"--config=merge-tools.fake-editor.merge-tool-edits-conflict-markers=true",
"--config=merge-tools.fake-editor.conflict-marker-style=git",
]);
insta::assert_snapshot!(output, @r###"
------- stderr -------
Resolving conflicts in: file
Working copy (@) now at: vruxwmqv d5f058ec conflict | (conflict) conflict
Parent commit (@-) : zsuskuln 45537d53 a | a
Parent commit (@-) : royxmykx 89d1b299 b | b
Added 0 files, modified 1 files, removed 0 files
Warning: There are unresolved conflicts at these paths:
file 2-sided conflict
New conflicts appeared in 1 commits:
vruxwmqv d5f058ec conflict | (conflict) conflict
Hint: To resolve the conflicts, start by creating a commit on top of
the conflicted commit:
jj new vruxwmqv
Then use `jj resolve`, or edit the conflict markers in the file directly.
Once the conflicts are resolved, you can inspect the result with `jj diff`.
Then run `jj squash` to move the resolution into the conflicted commit.
[EOF]
"###);
insta::assert_snapshot!(
std::fs::read_to_string(test_env.env_root().join("editor4")).unwrap(), @r"
<<<<<<< Side #1 (Conflict 1 of 1)
a
||||||| Base
base
=======
b
>>>>>>> Side #2 (Conflict 1 of 1 ends)
");
insta::assert_snapshot!(work_dir.run_jj(["diff", "--git"]), @r"
diff --git a/file b/file
--- a/file
+++ b/file
@@ -1,7 +1,7 @@
<<<<<<< Conflict 1 of 1
%%%%%%% Changes from base to side #1
--base
-+a
+-fake
++some
+++++++ Contents of side #2
-b
+conflict
>>>>>>> Conflict 1 of 1 ends
[EOF]
");
insta::assert_snapshot!(work_dir.run_jj(["resolve", "--list"]), @r"
file 2-sided conflict
[EOF]
");
// Check that merge tool can leave conflict markers by returning exit code 1
// when using `merge-conflict-exit-codes = [1]`. The Git "diff3" conflict
// markers should also be parsed correctly.
work_dir.run_jj(["undo"]).success();
insta::assert_snapshot!(work_dir.run_jj(["diff", "--git"]), @"");
std::fs::write(
&editor_script,
[
"dump editor5",
indoc! {"
write
<<<<<<<
some
|||||||
fake
=======
conflict
>>>>>>>
"},
"fail",
]
.join("\0"),
)
.unwrap();
let output = work_dir.run_jj([
"resolve",
"--config=merge-tools.fake-editor.merge-conflict-exit-codes=[1]",
]);
insta::assert_snapshot!(output, @r###"
------- stderr -------
Resolving conflicts in: file
Working copy (@) now at: vruxwmqv 6c205356 conflict | (conflict) conflict
Parent commit (@-) : zsuskuln 45537d53 a | a
Parent commit (@-) : royxmykx 89d1b299 b | b
Added 0 files, modified 1 files, removed 0 files
Warning: There are unresolved conflicts at these paths:
file 2-sided conflict
New conflicts appeared in 1 commits:
vruxwmqv 6c205356 conflict | (conflict) conflict
Hint: To resolve the conflicts, start by creating a commit on top of
the conflicted commit:
jj new vruxwmqv
Then use `jj resolve`, or edit the conflict markers in the file directly.
Once the conflicts are resolved, you can inspect the result with `jj diff`.
Then run `jj squash` to move the resolution into the conflicted commit.
[EOF]
"###);
insta::assert_snapshot!(
std::fs::read_to_string(test_env.env_root().join("editor5")).unwrap(), @"");
insta::assert_snapshot!(work_dir.run_jj(["diff", "--git"]), @r"
diff --git a/file b/file
--- a/file
+++ b/file
@@ -1,7 +1,7 @@
<<<<<<< Conflict 1 of 1
%%%%%%% Changes from base to side #1
--base
-+a
+-fake
++some
+++++++ Contents of side #2
-b
+conflict
>>>>>>> Conflict 1 of 1 ends
[EOF]
");
insta::assert_snapshot!(work_dir.run_jj(["resolve", "--list"]), @r"
file 2-sided conflict
[EOF]
");
// Check that an error is reported if a merge tool indicated it would leave
// conflict markers, but the output file didn't contain valid conflict markers.
work_dir.run_jj(["undo"]).success();
insta::assert_snapshot!(work_dir.run_jj(["diff", "--git"]), @"");
std::fs::write(
&editor_script,
[
indoc! {"
write
<<<<<<< this isn't diff3 style!
some
=======
conflict
>>>>>>>
"},
"fail",
]
.join("\0"),
)
.unwrap();
let output = work_dir.run_jj([
"resolve",
"--config=merge-tools.fake-editor.merge-conflict-exit-codes=[1]",
]);
insta::assert_snapshot!(output.normalize_stderr_exit_status(), @r"
------- stderr -------
Resolving conflicts in: file
Error: Failed to resolve conflicts
Caused by: Tool exited with exit status: 1, but did not produce valid conflict markers (run with --debug to see the exact invocation)
[EOF]
[exit status: 1]
");
// TODO: Check that running `jj new` and then `jj resolve -r conflict` works
// correctly.
}
fn check_resolve_produces_input_file(
test_env: &mut TestEnvironment,
root: impl AsRef<Path>,
filename: &str,
role: &str,
expected_content: &str,
) {
let editor_script = test_env.set_up_fake_editor();
let work_dir = test_env.work_dir(root);
std::fs::write(editor_script, format!("expect\n{expected_content}")).unwrap();
let merge_arg_config = format!(r#"merge-tools.fake-editor.merge-args=["${role}"]"#);
// This error means that fake-editor exited successfully but did not modify the
// output file.
let output = work_dir.run_jj(["resolve", "--config", &merge_arg_config, filename]);
insta::allow_duplicates! {
insta::assert_snapshot!(
output.normalize_stderr_with(|s| s.replacen(filename, "$FILENAME", 1)), @r"
------- stderr -------
Resolving conflicts in: $FILENAME
Error: Failed to resolve conflicts
Caused by: The output file is either unchanged or empty after the editor quit (run with --debug to see the exact invocation).
[EOF]
[exit status: 1]
");
}
}
#[test]
fn test_normal_conflict_input_files() {
let mut test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
create_commit_with_files(&work_dir, "base", &[], &[("file", "base\n")]);
create_commit_with_files(&work_dir, "a", &["base"], &[("file", "a\n")]);
create_commit_with_files(&work_dir, "b", &["base"], &[("file", "b\n")]);
create_commit_with_files(&work_dir, "conflict", &["a", "b"], &[]);
// Test the setup
insta::assert_snapshot!(get_log_output(&work_dir), @r"
@ conflict
├─╮
│ ○ b
○ │ a
├─╯
○ base
◆
[EOF]
");
insta::assert_snapshot!(work_dir.run_jj(["resolve", "--list"]), @r"
file 2-sided conflict
[EOF]
");
insta::assert_snapshot!(work_dir.read_file("file"), @r"
<<<<<<< Conflict 1 of 1
%%%%%%% Changes from base to side #1
-base
+a
+++++++ Contents of side #2
b
>>>>>>> Conflict 1 of 1 ends
");
check_resolve_produces_input_file(&mut test_env, "repo", "file", "base", "base\n");
check_resolve_produces_input_file(&mut test_env, "repo", "file", "left", "a\n");
check_resolve_produces_input_file(&mut test_env, "repo", "file", "right", "b\n");
}
#[test]
fn test_baseless_conflict_input_files() {
let mut test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
create_commit_with_files(&work_dir, "base", &[], &[]);
create_commit_with_files(&work_dir, "a", &["base"], &[("file", "a\n")]);
create_commit_with_files(&work_dir, "b", &["base"], &[("file", "b\n")]);
create_commit_with_files(&work_dir, "conflict", &["a", "b"], &[]);
// Test the setup
insta::assert_snapshot!(get_log_output(&work_dir), @r"
@ conflict
├─╮
│ ○ b
○ │ a
├─╯
○ base
◆
[EOF]
");
insta::assert_snapshot!(work_dir.run_jj(["resolve", "--list"]), @r"
file 2-sided conflict
[EOF]
");
insta::assert_snapshot!(work_dir.read_file("file"), @r"
<<<<<<< Conflict 1 of 1
%%%%%%% Changes from base to side #1
+a
+++++++ Contents of side #2
b
>>>>>>> Conflict 1 of 1 ends
");
check_resolve_produces_input_file(&mut test_env, "repo", "file", "base", "");
check_resolve_produces_input_file(&mut test_env, "repo", "file", "left", "a\n");
check_resolve_produces_input_file(&mut test_env, "repo", "file", "right", "b\n");
}
#[test]
fn test_too_many_parents() {
let test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
create_commit_with_files(&work_dir, "base", &[], &[("file", "base\n")]);
create_commit_with_files(&work_dir, "a", &["base"], &[("file", "a\n")]);
create_commit_with_files(&work_dir, "b", &["base"], &[("file", "b\n")]);
create_commit_with_files(&work_dir, "c", &["base"], &[("file", "c\n")]);
create_commit_with_files(&work_dir, "conflict", &["a", "b", "c"], &[]);
insta::assert_snapshot!(work_dir.run_jj(["resolve", "--list"]), @r"
file 3-sided conflict
[EOF]
");
// Test warning color
insta::assert_snapshot!(work_dir.run_jj(["resolve", "--list", "--color=always"]), @r"
file [38;5;1m3-sided[38;5;3m conflict[39m
[EOF]
");
let output = work_dir.run_jj(["resolve"]);
insta::assert_snapshot!(output, @r#"
------- stderr -------
Hint: Using default editor ':builtin'; run `jj config set --user ui.merge-editor :builtin` to disable this message.
Error: Failed to resolve conflicts
Caused by: The conflict at "file" has 3 sides. At most 2 sides are supported.
Hint: Edit the conflict markers manually to resolve this.
[EOF]
[exit status: 1]
"#);
}
#[test]
fn test_simplify_conflict_sides() {
let mut test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
// Creates a 4-sided conflict, with fileA and fileB having different conflicts:
// fileA: A - B + C - B + B - B + B
// fileB: A - A + A - A + B - C + D
create_commit_with_files(
&work_dir,
"base",
&[],
&[("fileA", "base\n"), ("fileB", "base\n")],
);
create_commit_with_files(&work_dir, "a1", &["base"], &[("fileA", "1\n")]);
create_commit_with_files(&work_dir, "a2", &["base"], &[("fileA", "2\n")]);
create_commit_with_files(&work_dir, "b1", &["base"], &[("fileB", "1\n")]);
create_commit_with_files(&work_dir, "b2", &["base"], &[("fileB", "2\n")]);
create_commit_with_files(&work_dir, "conflictA", &["a1", "a2"], &[]);
create_commit_with_files(&work_dir, "conflictB", &["b1", "b2"], &[]);
create_commit_with_files(&work_dir, "conflict", &["conflictA", "conflictB"], &[]);
// Even though the tree-level conflict is a 4-sided conflict, each file is
// materialized as a 2-sided conflict.
insta::assert_snapshot!(work_dir.run_jj(["debug", "tree"]), @r#"
fileA: Ok(Conflicted([Some(File { id: FileId("d00491fd7e5bb6fa28c517a0bb32b8b506539d4d"), executable: false, copy_id: CopyId("") }), Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: false, copy_id: CopyId("") }), Some(File { id: FileId("0cfbf08886fca9a91cb753ec8734c84fcbe52c9f"), executable: false, copy_id: CopyId("") }), Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: false, copy_id: CopyId("") }), Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: false, copy_id: CopyId("") }), Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: false, copy_id: CopyId("") }), Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: false, copy_id: CopyId("") })]))
fileB: Ok(Conflicted([Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: false, copy_id: CopyId("") }), Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: false, copy_id: CopyId("") }), Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: false, copy_id: CopyId("") }), Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: false, copy_id: CopyId("") }), Some(File { id: FileId("d00491fd7e5bb6fa28c517a0bb32b8b506539d4d"), executable: false, copy_id: CopyId("") }), Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: false, copy_id: CopyId("") }), Some(File { id: FileId("0cfbf08886fca9a91cb753ec8734c84fcbe52c9f"), executable: false, copy_id: CopyId("") })]))
[EOF]
"#);
insta::assert_snapshot!(work_dir.run_jj(["resolve", "--list"]), @r"
fileA 2-sided conflict
fileB 2-sided conflict
[EOF]
");
insta::assert_snapshot!(work_dir.read_file("fileA"), @r"
<<<<<<< Conflict 1 of 1
%%%%%%% Changes from base to side #1
-base
+1
+++++++ Contents of side #2
2
>>>>>>> Conflict 1 of 1 ends
");
insta::assert_snapshot!(work_dir.read_file("fileB"), @r"
<<<<<<< Conflict 1 of 1
%%%%%%% Changes from base to side #1
-base
+1
+++++++ Contents of side #2
2
>>>>>>> Conflict 1 of 1 ends
");
// Conflict should be simplified before being handled by external merge tool.
check_resolve_produces_input_file(&mut test_env, "repo", "fileA", "base", "base\n");
check_resolve_produces_input_file(&mut test_env, "repo", "fileA", "left", "1\n");
check_resolve_produces_input_file(&mut test_env, "repo", "fileA", "right", "2\n");
check_resolve_produces_input_file(&mut test_env, "repo", "fileB", "base", "base\n");
check_resolve_produces_input_file(&mut test_env, "repo", "fileB", "left", "1\n");
check_resolve_produces_input_file(&mut test_env, "repo", "fileB", "right", "2\n");
// Check that simplified conflicts are still parsed as conflicts after editing
// when `merge-tool-edits-conflict-markers=true`.
let editor_script = test_env.set_up_fake_editor();
std::fs::write(
editor_script,
indoc! {"
write
<<<<<<< Conflict 1 of 1
%%%%%%% Changes from base to side #1
-base_edited
+1_edited
+++++++ Contents of side #2
2_edited
>>>>>>> Conflict 1 of 1 ends
"},
)
.unwrap();
let work_dir = test_env.work_dir("repo");
let output = work_dir.run_jj([
"resolve",
"--config=merge-tools.fake-editor.merge-tool-edits-conflict-markers=true",
"fileB",
]);
insta::assert_snapshot!(output, @r###"
------- stderr -------
Resolving conflicts in: fileB
Working copy (@) now at: nkmrtpmo 25c5dd0b conflict | (conflict) conflict
Parent commit (@-) : kmkuslsw ccb05364 conflictA | (conflict) (empty) conflictA
Parent commit (@-) : lylxulpl d9bc60cb conflictB | (conflict) (empty) conflictB
Added 0 files, modified 1 files, removed 0 files
Warning: There are unresolved conflicts at these paths:
fileA 2-sided conflict
fileB 2-sided conflict
New conflicts appeared in 1 commits:
nkmrtpmo 25c5dd0b conflict | (conflict) conflict
Hint: To resolve the conflicts, start by creating a commit on top of
the conflicted commit:
jj new nkmrtpmo
Then use `jj resolve`, or edit the conflict markers in the file directly.
Once the conflicts are resolved, you can inspect the result with `jj diff`.
Then run `jj squash` to move the resolution into the conflicted commit.
[EOF]
"###);
insta::assert_snapshot!(work_dir.read_file("fileB"), @r"
<<<<<<< Conflict 1 of 1
%%%%%%% Changes from base to side #1
-base_edited
+1_edited
+++++++ Contents of side #2
2_edited
>>>>>>> Conflict 1 of 1 ends
");
insta::assert_snapshot!(work_dir.run_jj(["resolve", "--list"]), @r"
fileA 2-sided conflict
fileB 2-sided conflict
[EOF]
");
}
#[test]
fn test_edit_delete_conflict_input_files() {
let mut test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
create_commit_with_files(&work_dir, "base", &[], &[("file", "base\n")]);
create_commit_with_files(&work_dir, "a", &["base"], &[("file", "a\n")]);
create_commit_with_files(&work_dir, "b", &["base"], &[]);
work_dir.remove_file("file");
create_commit_with_files(&work_dir, "conflict", &["a", "b"], &[]);
// Test the setup
insta::assert_snapshot!(get_log_output(&work_dir), @r"
@ conflict
├─╮
│ ○ b
○ │ a
├─╯
○ base
◆
[EOF]
");
insta::assert_snapshot!(work_dir.run_jj(["resolve", "--list"]), @r"
file 2-sided conflict including 1 deletion
[EOF]
");
insta::assert_snapshot!(work_dir.read_file("file"), @r"
<<<<<<< Conflict 1 of 1
+++++++ Contents of side #1
a
%%%%%%% Changes from base to side #2
-base
>>>>>>> Conflict 1 of 1 ends
");
check_resolve_produces_input_file(&mut test_env, "repo", "file", "base", "base\n");
check_resolve_produces_input_file(&mut test_env, "repo", "file", "left", "a\n");
check_resolve_produces_input_file(&mut test_env, "repo", "file", "right", "");
}
#[test]
fn test_file_vs_dir() {
let test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
create_commit_with_files(&work_dir, "base", &[], &[("file", "base\n")]);
create_commit_with_files(&work_dir, "a", &["base"], &[("file", "a\n")]);
create_commit_with_files(&work_dir, "b", &["base"], &[]);
work_dir.remove_file("file");
work_dir.create_dir("file");
// Without a placeholder file, `jj` ignores an empty directory
work_dir.write_file("file/placeholder", "");
create_commit_with_files(&work_dir, "conflict", &["a", "b"], &[]);
insta::assert_snapshot!(get_log_output(&work_dir), @r"
@ conflict
├─╮
│ ○ b
○ │ a
├─╯
○ base
◆
[EOF]
");
insta::assert_snapshot!(work_dir.run_jj(["resolve", "--list"]), @r"
file 2-sided conflict including a directory
[EOF]
");
let output = work_dir.run_jj(["resolve"]);
insta::assert_snapshot!(output, @r#"
------- stderr -------
Hint: Using default editor ':builtin'; run `jj config set --user ui.merge-editor :builtin` to disable this message.
Error: Failed to resolve conflicts
Caused by: Only conflicts that involve normal files (not symlinks, etc.) are supported. Conflict summary for "file":
Conflict:
Removing file with id df967b96a579e45a18b8251732d16804b2e56a55
Adding file with id 78981922613b2afb6025042ff6bd878ac1994e85
Adding tree with id 133bb38fc4e4bf6b551f1f04db7e48f04cac2877
[EOF]
[exit status: 1]
"#);
}
#[test]
fn test_description_with_dir_and_deletion() {
let test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
create_commit_with_files(&work_dir, "base", &[], &[("file", "base\n")]);
create_commit_with_files(&work_dir, "edit", &["base"], &[("file", "b\n")]);
create_commit_with_files(&work_dir, "dir", &["base"], &[]);
work_dir.remove_file("file");
work_dir.create_dir("file");
// Without a placeholder file, `jj` ignores an empty directory
work_dir.write_file("file/placeholder", "");
create_commit_with_files(&work_dir, "del", &["base"], &[]);
work_dir.remove_file("file");
create_commit_with_files(&work_dir, "conflict", &["edit", "dir", "del"], &[]);
insta::assert_snapshot!(get_log_output(&work_dir), @r"
@ conflict
├─┬─╮
│ │ ○ del
│ ○ │ dir
│ ├─╯
○ │ edit
├─╯
○ base
◆
[EOF]
");
insta::assert_snapshot!(work_dir.run_jj(["resolve", "--list"]), @r"
file 3-sided conflict including 1 deletion and a directory
[EOF]
");
// Test warning color. The deletion is fine, so it's not highlighted
insta::assert_snapshot!(work_dir.run_jj(["resolve", "--list", "--color=always"]), @r"
file [38;5;1m3-sided[38;5;3m conflict including 1 deletion and [38;5;1ma directory[39m
[EOF]
");
let output = work_dir.run_jj(["resolve"]);
insta::assert_snapshot!(output, @r#"
------- stderr -------
Hint: Using default editor ':builtin'; run `jj config set --user ui.merge-editor :builtin` to disable this message.
Error: Failed to resolve conflicts
Caused by: Only conflicts that involve normal files (not symlinks, etc.) are supported. Conflict summary for "file":
Conflict:
Removing file with id df967b96a579e45a18b8251732d16804b2e56a55
Removing file with id df967b96a579e45a18b8251732d16804b2e56a55
Adding file with id 61780798228d17af2d34fce4cfbdf35556832472
Adding tree with id 133bb38fc4e4bf6b551f1f04db7e48f04cac2877
[EOF]
[exit status: 1]
"#);
}
#[test]
fn test_resolve_conflicts_with_executable() {
let mut test_env = TestEnvironment::default();
let editor_script = test_env.set_up_fake_editor();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
// Create a conflict in "file1" where all 3 terms are executables, and create a
// conflict in "file2" where one side set the executable bit.
create_commit_with_files(
&work_dir,
"base",
&[],
&[("file1", "base1\n"), ("file2", "base2\n")],
);
work_dir.run_jj(["file", "chmod", "x", "file1"]).success();
create_commit_with_files(
&work_dir,
"a",
&["base"],
&[("file1", "a1\n"), ("file2", "a2\n")],
);
create_commit_with_files(
&work_dir,
"b",
&["base"],
&[("file1", "b1\n"), ("file2", "b2\n")],
);
work_dir.run_jj(["file", "chmod", "x", "file2"]).success();
create_commit_with_files(&work_dir, "conflict", &["a", "b"], &[]);
insta::assert_snapshot!(work_dir.run_jj(["resolve", "--list"]), @r"
file1 2-sided conflict including an executable
file2 2-sided conflict including an executable
[EOF]
");
insta::assert_snapshot!(work_dir.read_file("file1"), @r"
<<<<<<< Conflict 1 of 1
%%%%%%% Changes from base to side #1
-base1
+a1
+++++++ Contents of side #2
b1
>>>>>>> Conflict 1 of 1 ends
"
);
insta::assert_snapshot!(work_dir.read_file("file2"), @r"
<<<<<<< Conflict 1 of 1
%%%%%%% Changes from base to side #1
-base2
+a2
+++++++ Contents of side #2
b2
>>>>>>> Conflict 1 of 1 ends
"
);
// Test resolving the conflict in "file1", which should produce an executable
std::fs::write(&editor_script, b"write\nresolution1\n").unwrap();
let output = work_dir.run_jj(["resolve", "file1"]);
insta::assert_snapshot!(output, @r###"
------- stderr -------
Resolving conflicts in: file1
Working copy (@) now at: znkkpsqq 8ab9c54e conflict | (conflict) conflict
Parent commit (@-) : mzvwutvl 86f7f0e3 a | a
Parent commit (@-) : yqosqzyt 36361412 b | b
Added 0 files, modified 1 files, removed 0 files
Warning: There are unresolved conflicts at these paths:
file2 2-sided conflict including an executable
New conflicts appeared in 1 commits:
znkkpsqq 8ab9c54e conflict | (conflict) conflict
Hint: To resolve the conflicts, start by creating a commit on top of
the conflicted commit:
jj new znkkpsqq
Then use `jj resolve`, or edit the conflict markers in the file directly.
Once the conflicts are resolved, you can inspect the result with `jj diff`.
Then run `jj squash` to move the resolution into the conflicted commit.
[EOF]
"###);
insta::assert_snapshot!(work_dir.run_jj(["diff", "--git"]), @r"
diff --git a/file1 b/file1
index 0000000000..95cc18629d 100755
--- a/file1
+++ b/file1
@@ -1,7 +1,1 @@
-<<<<<<< Conflict 1 of 1
-%%%%%%% Changes from base to side #1
--base1
-+a1
-+++++++ Contents of side #2
-b1
->>>>>>> Conflict 1 of 1 ends
+resolution1
[EOF]
");
insta::assert_snapshot!(work_dir.run_jj(["resolve", "--list"]), @r"
file2 2-sided conflict including an executable
[EOF]
");
// Test resolving the conflict in "file2", which should produce an executable
work_dir.run_jj(["undo"]).success();
std::fs::write(&editor_script, b"write\nresolution2\n").unwrap();
let output = work_dir.run_jj(["resolve", "file2"]);
insta::assert_snapshot!(output, @r###"
------- stderr -------
Resolving conflicts in: file2
Working copy (@) now at: znkkpsqq d47830a6 conflict | (conflict) conflict
Parent commit (@-) : mzvwutvl 86f7f0e3 a | a
Parent commit (@-) : yqosqzyt 36361412 b | b
Added 0 files, modified 1 files, removed 0 files
Warning: There are unresolved conflicts at these paths:
file1 2-sided conflict including an executable
New conflicts appeared in 1 commits:
znkkpsqq d47830a6 conflict | (conflict) conflict
Hint: To resolve the conflicts, start by creating a commit on top of
the conflicted commit:
jj new znkkpsqq
Then use `jj resolve`, or edit the conflict markers in the file directly.
Once the conflicts are resolved, you can inspect the result with `jj diff`.
Then run `jj squash` to move the resolution into the conflicted commit.
[EOF]
"###);
insta::assert_snapshot!(work_dir.run_jj(["diff", "--git"]), @r"
diff --git a/file2 b/file2
index 0000000000..775f078581 100755
--- a/file2
+++ b/file2
@@ -1,7 +1,1 @@
-<<<<<<< Conflict 1 of 1
-%%%%%%% Changes from base to side #1
--base2
-+a2
-+++++++ Contents of side #2
-b2
->>>>>>> Conflict 1 of 1 ends
+resolution2
[EOF]
");
insta::assert_snapshot!(work_dir.run_jj(["resolve", "--list"]), @r"
file1 2-sided conflict including an executable
[EOF]
");
// Pick "our" contents, but merges executable bits
work_dir.run_jj(["undo"]).success();
let output = work_dir.run_jj(["resolve", "--tool=:ours"]);
insta::assert_snapshot!(output, @r"
------- stderr -------
Working copy (@) now at: znkkpsqq d902c14b conflict | conflict
Parent commit (@-) : mzvwutvl 86f7f0e3 a | a
Parent commit (@-) : yqosqzyt 36361412 b | b
Added 0 files, modified 2 files, removed 0 files
[EOF]
");
insta::assert_snapshot!(work_dir.run_jj(["diff", "--git"]), @r"
diff --git a/file1 b/file1
index 0000000000..da0f8ed91a 100755
--- a/file1
+++ b/file1
@@ -1,7 +1,1 @@
-<<<<<<< Conflict 1 of 1
-%%%%%%% Changes from base to side #1
--base1
-+a1
-+++++++ Contents of side #2
-b1
->>>>>>> Conflict 1 of 1 ends
+a1
diff --git a/file2 b/file2
index 0000000000..c1827f07e1 100755
--- a/file2
+++ b/file2
@@ -1,7 +1,1 @@
-<<<<<<< Conflict 1 of 1
-%%%%%%% Changes from base to side #1
--base2
-+a2
-+++++++ Contents of side #2
-b2
->>>>>>> Conflict 1 of 1 ends
+a2
[EOF]
");
// Pick "their" contents, but merges executable bits
work_dir.run_jj(["undo"]).success();
let output = work_dir.run_jj(["resolve", "--tool=:theirs"]);
insta::assert_snapshot!(output, @r"
------- stderr -------
Working copy (@) now at: znkkpsqq a340ca5f conflict | conflict
Parent commit (@-) : mzvwutvl 86f7f0e3 a | a
Parent commit (@-) : yqosqzyt 36361412 b | b
Added 0 files, modified 2 files, removed 0 files
[EOF]
");
insta::assert_snapshot!(work_dir.run_jj(["diff", "--git"]), @r"
diff --git a/file1 b/file1
index 0000000000..c9c6af7f78 100755
--- a/file1
+++ b/file1
@@ -1,7 +1,1 @@
-<<<<<<< Conflict 1 of 1
-%%%%%%% Changes from base to side #1
--base1
-+a1
-+++++++ Contents of side #2
b1
->>>>>>> Conflict 1 of 1 ends
diff --git a/file2 b/file2
index 0000000000..e6bfff5c1d 100755
--- a/file2
+++ b/file2
@@ -1,7 +1,1 @@
-<<<<<<< Conflict 1 of 1
-%%%%%%% Changes from base to side #1
--base2
-+a2
-+++++++ Contents of side #2
b2
->>>>>>> Conflict 1 of 1 ends
[EOF]
");
}
#[test]
fn test_resolve_change_delete_executable() {
let mut test_env = TestEnvironment::default();
let editor_script = test_env.set_up_fake_editor();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
let file_template =
r#"separate(' ', path, if(conflict, "c", "-"), if(executable, "x", "-")) ++ "\n""#;
let file_list = |path: &str| work_dir.run_jj(["file", "list", "-T", file_template, path]);
// base a b
// file1: normal -> { exec, absent }
// file2: exec -> { absent, normal } (with content change)
// file3: absent -> { normal, exec }
// file4: normal -> { normal, absent } (with content change)
// file5: exec -> { absent, exec } (with content change)
create_commit_with_files(
&work_dir,
"base",
&[],
&[("file1", ""), ("file2", ""), ("file4", ""), ("file5", "")],
);
work_dir
.run_jj(["file", "chmod", "x", "file2", "file5"])
.success();
create_commit_with_files(
&work_dir,
"a",
&["base"],
&[("file1", ""), ("file3", ""), ("file4", "a4\n")],
);
work_dir.remove_file("file2");
work_dir.remove_file("file5");
work_dir.run_jj(["file", "chmod", "x", "file1"]).success();
create_commit_with_files(
&work_dir,
"b",
&["base"],
&[("file2", "b2\n"), ("file3", ""), ("file5", "b5\n")],
);
work_dir.remove_file("file1");
work_dir.remove_file("file4");
work_dir.run_jj(["file", "chmod", "n", "file2"]).success();
work_dir.run_jj(["file", "chmod", "x", "file3"]).success();
create_commit_with_files(&work_dir, "conflict", &["a", "b"], &[]);
// Test the setup
insta::assert_snapshot!(work_dir.run_jj(["resolve", "--list"]), @r"
file1 2-sided conflict including 1 deletion and an executable
file2 2-sided conflict including 1 deletion and an executable
file3 2-sided conflict including an executable
file4 2-sided conflict including 1 deletion
file5 2-sided conflict including 1 deletion and an executable
[EOF]
");
insta::assert_snapshot!(file_list("all()"), @r"
file1 c -
file2 c -
file3 c -
file4 c -
file5 c x
[EOF]
");
insta::assert_snapshot!(work_dir.run_jj(["log", "--git"]), @r"
@ kmkuslsw test.user@example.com 2001-02-03 08:05:18 conflict 7a7ac759 conflict
├─╮ (empty) conflict
│ ○ vruxwmqv test.user@example.com 2001-02-03 08:05:17 b 888b6cc3
│ │ b
│ │ diff --git a/file1 b/file1
│ │ deleted file mode 100644
│ │ index e69de29bb2..0000000000
│ │ diff --git a/file2 b/file2
│ │ old mode 100755
│ │ new mode 100644
│ │ index e69de29bb2..e6bfff5c1d
│ │ --- a/file2
│ │ +++ b/file2
│ │ @@ -0,0 +1,1 @@
│ │ +b2
│ │ diff --git a/file3 b/file3
│ │ new file mode 100755
│ │ index 0000000000..e69de29bb2
│ │ diff --git a/file4 b/file4
│ │ deleted file mode 100644
│ │ index e69de29bb2..0000000000
│ │ diff --git a/file5 b/file5
│ │ index e69de29bb2..90a5159bf0 100755
│ │ --- a/file5
│ │ +++ b/file5
│ │ @@ -0,0 +1,1 @@
│ │ +b5
○ │ mzvwutvl test.user@example.com 2001-02-03 08:05:13 a e2d3924b
├─╯ a
│ diff --git a/file1 b/file1
│ old mode 100644
│ new mode 100755
│ diff --git a/file2 b/file2
│ deleted file mode 100755
│ index e69de29bb2..0000000000
│ diff --git a/file3 b/file3
│ new file mode 100644
│ index 0000000000..e69de29bb2
│ diff --git a/file4 b/file4
│ index e69de29bb2..88ba23dca8 100644
│ --- a/file4
│ +++ b/file4
│ @@ -0,0 +1,1 @@
│ +a4
│ diff --git a/file5 b/file5
│ deleted file mode 100755
│ index e69de29bb2..0000000000
○ rlvkpnrz test.user@example.com 2001-02-03 08:05:10 base f747aa1f
│ base
│ diff --git a/file1 b/file1
│ new file mode 100644
│ index 0000000000..e69de29bb2
│ diff --git a/file2 b/file2
│ new file mode 100755
│ index 0000000000..e69de29bb2
│ diff --git a/file4 b/file4
│ new file mode 100644
│ index 0000000000..e69de29bb2
│ diff --git a/file5 b/file5
│ new file mode 100755
│ index 0000000000..e69de29bb2
◆ zzzzzzzz root() 00000000
[EOF]
");
// Exec bit conflict can be resolved by chmod
let output = work_dir.run_jj(["resolve", "file1"]);
insta::assert_snapshot!(output, @r#"
------- stderr -------
Error: Failed to resolve conflicts
Caused by: "file1" has conflicts in executable bit
Conflict:
Removing file with id e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
Adding executable file with id e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
Hint: Use `jj file chmod` to update the executable bit.
[EOF]
[exit status: 1]
"#);
let output = work_dir.run_jj(["file", "chmod", "--quiet", "x", "file1"]);
insta::assert_snapshot!(output, @"");
// Exec bit conflict can be resolved by chmod, then content conflict
let output = work_dir.run_jj(["resolve", "file2"]);
insta::assert_snapshot!(output, @r#"
------- stderr -------
Error: Failed to resolve conflicts
Caused by: "file2" has conflicts in executable bit
Conflict:
Removing executable file with id e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
Adding file with id e6bfff5c1d0f0ecd501552b43a1e13d8008abc31
Hint: Use `jj file chmod` to update the executable bit.
[EOF]
[exit status: 1]
"#);
let output = work_dir.run_jj(["file", "chmod", "--quiet", "n", "file2"]);
insta::assert_snapshot!(output, @"");
std::fs::write(&editor_script, "write\nresolved\n").unwrap();
let output = work_dir.run_jj(["resolve", "file2"]);
insta::assert_snapshot!(output, @r"
------- stderr -------
Resolving conflicts in: file2
Working copy (@) now at: kmkuslsw 1323520e conflict | (conflict) conflict
Parent commit (@-) : mzvwutvl e2d3924b a | a
Parent commit (@-) : vruxwmqv 888b6cc3 b | b
Added 0 files, modified 1 files, removed 0 files
Warning: There are unresolved conflicts at these paths:
file3 2-sided conflict including an executable
file4 2-sided conflict including 1 deletion
file5 2-sided conflict including 1 deletion and an executable
[EOF]
");
// Exec bit conflict can be resolved by chmod
let output = work_dir.run_jj(["resolve", "file3"]);
insta::assert_snapshot!(output, @r#"
------- stderr -------
Error: Failed to resolve conflicts
Caused by: "file3" has conflicts in executable bit
Conflict:
Adding file with id e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
Adding executable file with id e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
Hint: Use `jj file chmod` to update the executable bit.
[EOF]
[exit status: 1]
"#);
let output = work_dir.run_jj(["file", "chmod", "--quiet", "x", "file3"]);
insta::assert_snapshot!(output, @"");
// Take modified content, the executable bit should be kept as "-"
let output = work_dir.run_jj(["resolve", "file4", "--tool=:ours"]);
insta::assert_snapshot!(output, @r"
------- stderr -------
Working copy (@) now at: kmkuslsw 630e8689 conflict | (conflict) conflict
Parent commit (@-) : mzvwutvl e2d3924b a | a
Parent commit (@-) : vruxwmqv 888b6cc3 b | b
Added 0 files, modified 1 files, removed 0 files
Warning: There are unresolved conflicts at these paths:
file5 2-sided conflict including 1 deletion and an executable
[EOF]
");
// Take modified content, the executable bit should be kept as "x"
let output = work_dir.run_jj(["resolve", "file5", "--tool=:theirs"]);
insta::assert_snapshot!(output, @r"
------- stderr -------
Working copy (@) now at: kmkuslsw 7337267a conflict | conflict
Parent commit (@-) : mzvwutvl e2d3924b a | a
Parent commit (@-) : vruxwmqv 888b6cc3 b | b
Added 0 files, modified 1 files, removed 0 files
Existing conflicts were resolved or abandoned from 1 commits.
[EOF]
");
insta::assert_snapshot!(file_list("all()"), @r"
file2 - -
file3 - x
file4 - -
file5 - x
[EOF]
");
}
#[test]
fn test_resolve_long_conflict_markers() {
let mut test_env = TestEnvironment::default();
let editor_script = test_env.set_up_fake_editor();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
// Makes it easier to read the diffs between conflicts
test_env.add_config("ui.conflict-marker-style = 'snapshot'");
// Create a conflict which requires long conflict markers to be materialized
create_commit_with_files(&work_dir, "base", &[], &[("file", "======= base\n")]);
create_commit_with_files(&work_dir, "a", &["base"], &[("file", "<<<<<<< a\n")]);
create_commit_with_files(&work_dir, "b", &["base"], &[("file", ">>>>>>> b\n")]);
create_commit_with_files(&work_dir, "conflict", &["a", "b"], &[]);
insta::assert_snapshot!(work_dir.run_jj(["resolve", "--list"]), @r"
file 2-sided conflict
[EOF]
");
insta::assert_snapshot!(work_dir.read_file("file"), @r"
<<<<<<<<<<< Conflict 1 of 1
+++++++++++ Contents of side #1
<<<<<<< a
----------- Contents of base
======= base
+++++++++++ Contents of side #2
>>>>>>> b
>>>>>>>>>>> Conflict 1 of 1 ends
"
);
// Allow signaling that conflict markers were produced even if not editing
// conflict markers materialized in the output file
test_env.add_config("merge-tools.fake-editor.merge-conflict-exit-codes = [1]");
// By default, conflict markers of length 7 or longer are parsed for
// compatibility with Git merge tools
std::fs::write(
&editor_script,
indoc! {b"
write
<<<<<<<
A
|||||||
BASE
=======
B
>>>>>>>
\0fail
"},
)
.unwrap();
let output = work_dir.run_jj(["resolve"]);
insta::assert_snapshot!(output, @r###"
------- stderr -------
Resolving conflicts in: file
Working copy (@) now at: vruxwmqv 1e254ee3 conflict | (conflict) conflict
Parent commit (@-) : zsuskuln 10d994ef a | a
Parent commit (@-) : royxmykx 7f215575 b | b
Added 0 files, modified 1 files, removed 0 files
Warning: There are unresolved conflicts at these paths:
file 2-sided conflict
New conflicts appeared in 1 commits:
vruxwmqv 1e254ee3 conflict | (conflict) conflict
Hint: To resolve the conflicts, start by creating a commit on top of
the conflicted commit:
jj new vruxwmqv
Then use `jj resolve`, or edit the conflict markers in the file directly.
Once the conflicts are resolved, you can inspect the result with `jj diff`.
Then run `jj squash` to move the resolution into the conflicted commit.
[EOF]
"###);
insta::assert_snapshot!(work_dir.run_jj(["diff", "--git"]), @r"
diff --git a/file b/file
--- a/file
+++ b/file
@@ -1,8 +1,8 @@
-<<<<<<<<<<< Conflict 1 of 1
-+++++++++++ Contents of side #1
-<<<<<<< a
------------ Contents of base
-======= base
-+++++++++++ Contents of side #2
->>>>>>> b
->>>>>>>>>>> Conflict 1 of 1 ends
+<<<<<<< Conflict 1 of 1
++++++++ Contents of side #1
+A
+------- Contents of base
+BASE
++++++++ Contents of side #2
+B
+>>>>>>> Conflict 1 of 1 ends
[EOF]
");
insta::assert_snapshot!(work_dir.run_jj(["resolve", "--list"]), @r"
file 2-sided conflict
[EOF]
");
// If the merge tool edits the output file with materialized markers, the
// markers must match the length of the materialized markers to be parsed
work_dir.run_jj(["undo"]).success();
std::fs::write(
&editor_script,
indoc! {b"
dump editor
\0write
<<<<<<<<<<<
<<<<<<< A
|||||||||||
======= BASE
===========
>>>>>>> B
>>>>>>>>>>>
\0fail
"},
)
.unwrap();
let output = work_dir.run_jj([
"resolve",
"--config=merge-tools.fake-editor.merge-tool-edits-conflict-markers=true",
]);
insta::assert_snapshot!(output, @r###"
------- stderr -------
Resolving conflicts in: file
Working copy (@) now at: vruxwmqv 2481a401 conflict | (conflict) conflict
Parent commit (@-) : zsuskuln 10d994ef a | a
Parent commit (@-) : royxmykx 7f215575 b | b
Added 0 files, modified 1 files, removed 0 files
Warning: There are unresolved conflicts at these paths:
file 2-sided conflict
New conflicts appeared in 1 commits:
vruxwmqv 2481a401 conflict | (conflict) conflict
Hint: To resolve the conflicts, start by creating a commit on top of
the conflicted commit:
jj new vruxwmqv
Then use `jj resolve`, or edit the conflict markers in the file directly.
Once the conflicts are resolved, you can inspect the result with `jj diff`.
Then run `jj squash` to move the resolution into the conflicted commit.
[EOF]
"###);
insta::assert_snapshot!(
std::fs::read_to_string(test_env.env_root().join("editor")).unwrap(), @r"
<<<<<<<<<<< Conflict 1 of 1
+++++++++++ Contents of side #1
<<<<<<< a
----------- Contents of base
======= base
+++++++++++ Contents of side #2
>>>>>>> b
>>>>>>>>>>> Conflict 1 of 1 ends
");
insta::assert_snapshot!(work_dir.run_jj(["diff", "--git"]), @r"
diff --git a/file b/file
--- a/file
+++ b/file
@@ -1,8 +1,8 @@
<<<<<<<<<<< Conflict 1 of 1
+++++++++++ Contents of side #1
-<<<<<<< a
+<<<<<<< A
----------- Contents of base
-======= base
+======= BASE
+++++++++++ Contents of side #2
->>>>>>> b
+>>>>>>> B
>>>>>>>>>>> Conflict 1 of 1 ends
[EOF]
");
insta::assert_snapshot!(work_dir.run_jj(["resolve", "--list"]), @r"
file 2-sided conflict
[EOF]
");
// If the merge tool accepts the marker length as an argument, then the conflict
// markers should be at least as long as "$marker_length"
work_dir.run_jj(["undo"]).success();
std::fs::write(
&editor_script,
indoc! {b"
expect-arg 0
11\0write
<<<<<<<<<<<
<<<<<<< A
|||||||||||
======= BASE
===========
>>>>>>> B
>>>>>>>>>>>
\0fail
"},
)
.unwrap();
let output = work_dir.run_jj([
"resolve",
r#"--config=merge-tools.fake-editor.merge-args=["$output", "$marker_length"]"#,
]);
insta::assert_snapshot!(output, @r###"
------- stderr -------
Resolving conflicts in: file
Working copy (@) now at: vruxwmqv 2cf0bfd3 conflict | (conflict) conflict
Parent commit (@-) : zsuskuln 10d994ef a | a
Parent commit (@-) : royxmykx 7f215575 b | b
Added 0 files, modified 1 files, removed 0 files
Warning: There are unresolved conflicts at these paths:
file 2-sided conflict
New conflicts appeared in 1 commits:
vruxwmqv 2cf0bfd3 conflict | (conflict) conflict
Hint: To resolve the conflicts, start by creating a commit on top of
the conflicted commit:
jj new vruxwmqv
Then use `jj resolve`, or edit the conflict markers in the file directly.
Once the conflicts are resolved, you can inspect the result with `jj diff`.
Then run `jj squash` to move the resolution into the conflicted commit.
[EOF]
"###);
insta::assert_snapshot!(work_dir.run_jj(["diff", "--git"]), @r"
diff --git a/file b/file
--- a/file
+++ b/file
@@ -1,8 +1,8 @@
<<<<<<<<<<< Conflict 1 of 1
+++++++++++ Contents of side #1
-<<<<<<< a
+<<<<<<< A
----------- Contents of base
-======= base
+======= BASE
+++++++++++ Contents of side #2
->>>>>>> b
+>>>>>>> B
>>>>>>>>>>> Conflict 1 of 1 ends
[EOF]
");
insta::assert_snapshot!(work_dir.run_jj(["resolve", "--list"]), @r"
file 2-sided conflict
[EOF]
");
}
#[test]
fn test_multiple_conflicts() {
let mut test_env = TestEnvironment::default();
let editor_script = test_env.set_up_fake_editor();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
create_commit_with_files(
&work_dir,
"base",
&[],
&[
(
"this_file_has_a_very_long_name_to_test_padding",
"first base\n",
),
("another_file", "second base\n"),
],
);
create_commit_with_files(
&work_dir,
"a",
&["base"],
&[
(
"this_file_has_a_very_long_name_to_test_padding",
"first a\n",
),
("another_file", "second a\n"),
],
);
create_commit_with_files(
&work_dir,
"b",
&["base"],
&[
(
"this_file_has_a_very_long_name_to_test_padding",
"first b\n",
),
("another_file", "second b\n"),
],
);
create_commit_with_files(&work_dir, "conflict", &["a", "b"], &[]);
// Test the setup
insta::assert_snapshot!(get_log_output(&work_dir), @r"
@ conflict
├─╮
│ ○ b
○ │ a
├─╯
○ base
◆
[EOF]
");
insta::assert_snapshot!(
work_dir.read_file("this_file_has_a_very_long_name_to_test_padding"), @r"
<<<<<<< Conflict 1 of 1
%%%%%%% Changes from base to side #1
-first base
+first a
+++++++ Contents of side #2
first b
>>>>>>> Conflict 1 of 1 ends
");
insta::assert_snapshot!(work_dir.read_file("another_file"), @r"
<<<<<<< Conflict 1 of 1
%%%%%%% Changes from base to side #1
-second base
+second a
+++++++ Contents of side #2
second b
>>>>>>> Conflict 1 of 1 ends
");
insta::assert_snapshot!(work_dir.run_jj(["resolve", "--list"]), @r"
another_file 2-sided conflict
this_file_has_a_very_long_name_to_test_padding 2-sided conflict
[EOF]
");
// Test colors
insta::assert_snapshot!(work_dir.run_jj(["resolve", "--list", "--color=always"]), @r"
another_file [38;5;3m2-sided conflict[39m
this_file_has_a_very_long_name_to_test_padding [38;5;3m2-sided conflict[39m
[EOF]
");
// Check that we can manually pick which of the conflicts to resolve first
std::fs::write(&editor_script, "expect\n\0write\nresolution another_file\n").unwrap();
let output = work_dir.run_jj(["resolve", "another_file"]);
insta::assert_snapshot!(output, @r###"
------- stderr -------
Resolving conflicts in: another_file
Working copy (@) now at: vruxwmqv d3584f6e conflict | (conflict) conflict
Parent commit (@-) : zsuskuln 2c821f70 a | a
Parent commit (@-) : royxmykx 4c2029de b | b
Added 0 files, modified 1 files, removed 0 files
Warning: There are unresolved conflicts at these paths:
this_file_has_a_very_long_name_to_test_padding 2-sided conflict
New conflicts appeared in 1 commits:
vruxwmqv d3584f6e conflict | (conflict) conflict
Hint: To resolve the conflicts, start by creating a commit on top of
the conflicted commit:
jj new vruxwmqv
Then use `jj resolve`, or edit the conflict markers in the file directly.
Once the conflicts are resolved, you can inspect the result with `jj diff`.
Then run `jj squash` to move the resolution into the conflicted commit.
[EOF]
"###);
insta::assert_snapshot!(work_dir.run_jj(["diff", "--git"]), @r"
diff --git a/another_file b/another_file
index 0000000000..a9fcc7d486 100644
--- a/another_file
+++ b/another_file
@@ -1,7 +1,1 @@
-<<<<<<< Conflict 1 of 1
-%%%%%%% Changes from base to side #1
--second base
-+second a
-+++++++ Contents of side #2
-second b
->>>>>>> Conflict 1 of 1 ends
+resolution another_file
[EOF]
");
insta::assert_snapshot!(work_dir.run_jj(["resolve", "--list"]), @r"
this_file_has_a_very_long_name_to_test_padding 2-sided conflict
[EOF]
");
// Repeat the above with the `--quiet` option.
work_dir.run_jj(["undo"]).success();
std::fs::write(&editor_script, "expect\n\0write\nresolution another_file\n").unwrap();
let output = work_dir.run_jj(["resolve", "--quiet", "another_file"]);
insta::assert_snapshot!(output, @"");
// Without a path, `jj resolve` should call the merge tool multiple times
work_dir.run_jj(["undo"]).success();
insta::assert_snapshot!(work_dir.run_jj(["diff", "--git"]), @"");
std::fs::write(
&editor_script,
[
"expect\n",
"write\nfirst resolution for auto-chosen file\n",
"next invocation\n",
"expect\n",
"write\nsecond resolution for auto-chosen file\n",
]
.join("\0"),
)
.unwrap();
work_dir.run_jj(["resolve"]).success();
insta::assert_snapshot!(work_dir.run_jj(["diff", "--git"]), @r"
diff --git a/another_file b/another_file
index 0000000000..7903e1c1c7 100644
--- a/another_file
+++ b/another_file
@@ -1,7 +1,1 @@
-<<<<<<< Conflict 1 of 1
-%%%%%%% Changes from base to side #1
--second base
-+second a
-+++++++ Contents of side #2
-second b
->>>>>>> Conflict 1 of 1 ends
+first resolution for auto-chosen file
diff --git a/this_file_has_a_very_long_name_to_test_padding b/this_file_has_a_very_long_name_to_test_padding
index 0000000000..f8c72adf17 100644
--- a/this_file_has_a_very_long_name_to_test_padding
+++ b/this_file_has_a_very_long_name_to_test_padding
@@ -1,7 +1,1 @@
-<<<<<<< Conflict 1 of 1
-%%%%%%% Changes from base to side #1
--first base
-+first a
-+++++++ Contents of side #2
-first b
->>>>>>> Conflict 1 of 1 ends
+second resolution for auto-chosen file
[EOF]
");
insta::assert_snapshot!(work_dir.run_jj(["resolve", "--list"]), @r"
------- stderr -------
Error: No conflicts found at this revision
[EOF]
[exit status: 2]
");
insta::assert_snapshot!(work_dir.run_jj(["resolve"]), @r"
------- stderr -------
Error: No conflicts found at this revision
[EOF]
[exit status: 2]
");
}
#[test]
fn test_multiple_conflicts_with_error() {
let mut test_env = TestEnvironment::default();
let editor_script = test_env.set_up_fake_editor();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
// Create two conflicted files, and one non-conflicted file
create_commit_with_files(
&work_dir,
"base",
&[],
&[
("file1", "base1\n"),
("file2", "base2\n"),
("file3", "base3\n"),
],
);
create_commit_with_files(
&work_dir,
"a",
&["base"],
&[("file1", "a1\n"), ("file2", "a2\n")],
);
create_commit_with_files(
&work_dir,
"b",
&["base"],
&[("file1", "b1\n"), ("file2", "b2\n")],
);
create_commit_with_files(&work_dir, "conflict", &["a", "b"], &[]);
insta::assert_snapshot!(work_dir.run_jj(["resolve", "--list"]), @r"
file1 2-sided conflict
file2 2-sided conflict
[EOF]
");
insta::assert_snapshot!(work_dir.read_file("file1"), @r"
<<<<<<< Conflict 1 of 1
%%%%%%% Changes from base to side #1
-base1
+a1
+++++++ Contents of side #2
b1
>>>>>>> Conflict 1 of 1 ends
"
);
insta::assert_snapshot!(work_dir.read_file("file2"), @r"
<<<<<<< Conflict 1 of 1
%%%%%%% Changes from base to side #1
-base2
+a2
+++++++ Contents of side #2
b2
>>>>>>> Conflict 1 of 1 ends
"
);
// Test resolving one conflict, then exiting without resolving the second one
std::fs::write(
&editor_script,
["write\nresolution1\n", "next invocation\n"].join("\0"),
)
.unwrap();
let output = work_dir.run_jj(["resolve"]);
insta::assert_snapshot!(output.normalize_stderr_exit_status(), @r###"
------- stderr -------
Resolving conflicts in: file1
Resolving conflicts in: file2
Working copy (@) now at: vruxwmqv 98296abe conflict | (conflict) conflict
Parent commit (@-) : zsuskuln 6c31698c a | a
Parent commit (@-) : royxmykx ba0a5538 b | b
Added 0 files, modified 1 files, removed 0 files
Warning: There are unresolved conflicts at these paths:
file2 2-sided conflict
New conflicts appeared in 1 commits:
vruxwmqv 98296abe conflict | (conflict) conflict
Hint: To resolve the conflicts, start by creating a commit on top of
the conflicted commit:
jj new vruxwmqv
Then use `jj resolve`, or edit the conflict markers in the file directly.
Once the conflicts are resolved, you can inspect the result with `jj diff`.
Then run `jj squash` to move the resolution into the conflicted commit.
Error: Stopped due to error after resolving 1 conflicts
Caused by: The output file is either unchanged or empty after the editor quit (run with --debug to see the exact invocation).
[EOF]
[exit status: 1]
"###);
insta::assert_snapshot!(work_dir.run_jj(["diff", "--git"]), @r"
diff --git a/file1 b/file1
index 0000000000..95cc18629d 100644
--- a/file1
+++ b/file1
@@ -1,7 +1,1 @@
-<<<<<<< Conflict 1 of 1
-%%%%%%% Changes from base to side #1
--base1
-+a1
-+++++++ Contents of side #2
-b1
->>>>>>> Conflict 1 of 1 ends
+resolution1
[EOF]
");
insta::assert_snapshot!(work_dir.run_jj(["resolve", "--list"]), @r"
file2 2-sided conflict
[EOF]
");
// Test resolving one conflict, then failing during the second resolution
work_dir.run_jj(["undo"]).success();
std::fs::write(
&editor_script,
["write\nresolution1\n", "next invocation\n", "fail"].join("\0"),
)
.unwrap();
let output = work_dir.run_jj(["resolve"]);
insta::assert_snapshot!(output.normalize_stderr_exit_status(), @r###"
------- stderr -------
Resolving conflicts in: file1
Resolving conflicts in: file2
Working copy (@) now at: vruxwmqv 7daa6406 conflict | (conflict) conflict
Parent commit (@-) : zsuskuln 6c31698c a | a
Parent commit (@-) : royxmykx ba0a5538 b | b
Added 0 files, modified 1 files, removed 0 files
Warning: There are unresolved conflicts at these paths:
file2 2-sided conflict
New conflicts appeared in 1 commits:
vruxwmqv 7daa6406 conflict | (conflict) conflict
Hint: To resolve the conflicts, start by creating a commit on top of
the conflicted commit:
jj new vruxwmqv
Then use `jj resolve`, or edit the conflict markers in the file directly.
Once the conflicts are resolved, you can inspect the result with `jj diff`.
Then run `jj squash` to move the resolution into the conflicted commit.
Error: Stopped due to error after resolving 1 conflicts
Caused by: Tool exited with exit status: 1 (run with --debug to see the exact invocation)
[EOF]
[exit status: 1]
"###);
insta::assert_snapshot!(work_dir.run_jj(["diff", "--git"]), @r"
diff --git a/file1 b/file1
index 0000000000..95cc18629d 100644
--- a/file1
+++ b/file1
@@ -1,7 +1,1 @@
-<<<<<<< Conflict 1 of 1
-%%%%%%% Changes from base to side #1
--base1
-+a1
-+++++++ Contents of side #2
-b1
->>>>>>> Conflict 1 of 1 ends
+resolution1
[EOF]
");
insta::assert_snapshot!(work_dir.run_jj(["resolve", "--list"]), @r"
file2 2-sided conflict
[EOF]
");
// Test immediately failing to resolve any conflict
work_dir.run_jj(["undo"]).success();
std::fs::write(&editor_script, "fail").unwrap();
let output = work_dir.run_jj(["resolve"]);
insta::assert_snapshot!(output.normalize_stderr_exit_status(), @r"
------- stderr -------
Resolving conflicts in: file1
Error: Failed to resolve conflicts
Caused by: Tool exited with exit status: 1 (run with --debug to see the exact invocation)
[EOF]
[exit status: 1]
");
insta::assert_snapshot!(work_dir.run_jj(["diff", "--git"]), @"");
insta::assert_snapshot!(work_dir.run_jj(["resolve", "--list"]), @r"
file1 2-sided conflict
file2 2-sided conflict
[EOF]
");
}
#[test]
fn test_resolve_with_contents_of_side() {
let test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
create_commit_with_files(
&work_dir,
"base",
&[],
&[("file", "base\n"), ("other", "base\n")],
);
create_commit_with_files(
&work_dir,
"a",
&["base"],
&[("file", "a\n"), ("other", "base\n")],
);
create_commit_with_files(
&work_dir,
"b",
&["base"],
&[("file", "base\n"), ("other", "left\n")],
);
create_commit_with_files(
&work_dir,
"c",
&["base"],
&[("file", "b\n"), ("other", "right\n")],
);
create_commit_with_files(&work_dir, "conflict", &["a", "b", "c"], &[]);
// Test the setup
insta::assert_snapshot!(get_log_output(&work_dir), @r"
@ conflict
├─┬─╮
│ │ ○ c
│ ○ │ b
│ ├─╯
○ │ a
├─╯
○ base
◆
[EOF]
");
insta::assert_snapshot!(work_dir.run_jj(["resolve", "--list"]), @r"
file 2-sided conflict
other 2-sided conflict
[EOF]
");
insta::assert_snapshot!(work_dir.read_file("file"), @r"
<<<<<<< Conflict 1 of 1
%%%%%%% Changes from base to side #1
-base
+a
+++++++ Contents of side #2
b
>>>>>>> Conflict 1 of 1 ends
");
insta::assert_snapshot!(work_dir.read_file("other"), @r"
<<<<<<< Conflict 1 of 1
%%%%%%% Changes from base to side #1
-base
+left
+++++++ Contents of side #2
right
>>>>>>> Conflict 1 of 1 ends
");
// Check that ":ours" merge tool works correctly
insta::assert_snapshot!(work_dir.run_jj(["diff", "--git"]), @"");
let output = work_dir.run_jj(["resolve", "--tool", ":ours"]);
insta::assert_snapshot!(output, @r"
------- stderr -------
Working copy (@) now at: znkkpsqq 5410a03a conflict | conflict
Parent commit (@-) : zsuskuln 72dced6e a | a
Parent commit (@-) : royxmykx e5747f42 b | b
Parent commit (@-) : vruxwmqv dd35236a c | c
Added 0 files, modified 2 files, removed 0 files
[EOF]
");
insta::assert_snapshot!(work_dir.read_file("file"), @"a");
insta::assert_snapshot!(work_dir.read_file("other"), @"left");
insta::assert_snapshot!(work_dir.run_jj(["resolve", "--list"]), @r#"
------- stderr -------
Error: No conflicts found at this revision
[EOF]
[exit status: 2]
"#);
// Check that ":theirs" merge tool works correctly
work_dir.run_jj(["undo"]).success();
insta::assert_snapshot!(work_dir.run_jj(["diff", "--git"]), @"");
let output = work_dir.run_jj(["resolve", "--tool", ":theirs"]);
insta::assert_snapshot!(output, @r"
------- stderr -------
Working copy (@) now at: znkkpsqq c07b2e9e conflict | conflict
Parent commit (@-) : zsuskuln 72dced6e a | a
Parent commit (@-) : royxmykx e5747f42 b | b
Parent commit (@-) : vruxwmqv dd35236a c | c
Added 0 files, modified 2 files, removed 0 files
[EOF]
");
insta::assert_snapshot!(work_dir.read_file("file"), @"b");
insta::assert_snapshot!(work_dir.read_file("other"), @"right");
insta::assert_snapshot!(work_dir.run_jj(["resolve", "--list"]), @r#"
------- stderr -------
Error: No conflicts found at this revision
[EOF]
[exit status: 2]
"#);
}
|