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
|
// Copyright 2023 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 indoc::indoc;
use regex::Regex;
use testutils::git;
use crate::common::TestEnvironment;
#[test]
fn test_log_parents() {
let test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
work_dir.run_jj(["new"]).success();
work_dir.run_jj(["new", "@-"]).success();
work_dir.run_jj(["new", "@", "@-"]).success();
let template =
r#"commit_id ++ "\nP: " ++ parents.len() ++ " " ++ parents.map(|c| c.commit_id()) ++ "\n""#;
let output = work_dir.run_jj(["log", "-T", template]);
insta::assert_snapshot!(output, @r"
@ 8b93ef7a3ceefa4e4b1a506945588dd0da2d9e3e
├─╮ P: 2 1c1c95df80e53b1e654608d7589f5baabb10ebb2 e8849ae12c709f2321908879bc724fdb2ab8a781
○ │ 1c1c95df80e53b1e654608d7589f5baabb10ebb2
├─╯ P: 1 e8849ae12c709f2321908879bc724fdb2ab8a781
○ e8849ae12c709f2321908879bc724fdb2ab8a781
│ P: 1 0000000000000000000000000000000000000000
◆ 0000000000000000000000000000000000000000
P: 0
[EOF]
");
// List<Commit> can be filtered
let template =
r#""P: " ++ parents.filter(|c| !c.root()).map(|c| c.commit_id().short()) ++ "\n""#;
let output = work_dir.run_jj(["log", "-T", template]);
insta::assert_snapshot!(output, @r"
@ P: 1c1c95df80e5 e8849ae12c70
├─╮
○ │ P: e8849ae12c70
├─╯
○ P:
◆ P:
[EOF]
");
let template = r#"parents.map(|c| c.commit_id().shortest(4))"#;
let output = work_dir.run_jj(["log", "-T", template, "-r@", "--color=always"]);
insta::assert_snapshot!(output, @r"
[1m[38;5;2m@[0m [1m[38;5;4m1[0m[38;5;8mc1c[39m [1m[38;5;4me[0m[38;5;8m884[39m
│
~
[EOF]
");
// Commit object isn't printable
let output = work_dir.run_jj(["log", "-T", "parents"]);
insta::assert_snapshot!(output, @r"
------- stderr -------
Error: Failed to parse template: Expected expression of type `Template`, but actual type is `List<Commit>`
Caused by: --> 1:1
|
1 | parents
| ^-----^
|
= Expected expression of type `Template`, but actual type is `List<Commit>`
[EOF]
[exit status: 1]
");
// Redundant argument passed to keyword method
let template = r#"parents.map(|c| c.commit_id(""))"#;
let output = work_dir.run_jj(["log", "-T", template]);
insta::assert_snapshot!(output, @r#"
------- stderr -------
Error: Failed to parse template: Function `commit_id`: Expected 0 arguments
Caused by: --> 1:29
|
1 | parents.map(|c| c.commit_id(""))
| ^^
|
= Function `commit_id`: Expected 0 arguments
[EOF]
[exit status: 1]
"#);
}
#[test]
fn test_log_author_timestamp() {
let test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
work_dir.run_jj(["describe", "-m", "first"]).success();
work_dir.run_jj(["new", "-m", "second"]).success();
let output = work_dir.run_jj(["log", "-T", "author.timestamp()"]);
insta::assert_snapshot!(output, @r"
@ 2001-02-03 04:05:09.000 +07:00
○ 2001-02-03 04:05:08.000 +07:00
◆ 1970-01-01 00:00:00.000 +00:00
[EOF]
");
}
#[test]
fn test_log_author_timestamp_ago() {
let test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
work_dir.run_jj(["describe", "-m", "first"]).success();
work_dir.run_jj(["new", "-m", "second"]).success();
let template = r#"author.timestamp().ago() ++ "\n""#;
let output = work_dir
.run_jj(&["log", "--no-graph", "-T", template])
.success();
let line_re = Regex::new(r"[0-9]+ years ago").unwrap();
assert!(
output.stdout.raw().lines().all(|x| line_re.is_match(x)),
"expected every line to match regex"
);
}
#[test]
fn test_log_author_timestamp_utc() {
let test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
let output = work_dir.run_jj(["log", "-T", "author.timestamp().utc()"]);
insta::assert_snapshot!(output, @r"
@ 2001-02-02 21:05:07.000 +00:00
◆ 1970-01-01 00:00:00.000 +00:00
[EOF]
");
}
#[cfg(unix)]
#[test]
fn test_log_author_timestamp_local() {
let mut test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
test_env.add_env_var("TZ", "UTC-05:30");
let work_dir = test_env.work_dir("repo");
let output = work_dir.run_jj(["log", "-T", "author.timestamp().local()"]);
insta::assert_snapshot!(output, @r"
@ 2001-02-03 08:05:07.000 +11:00
◆ 1970-01-01 11:00:00.000 +11:00
[EOF]
");
test_env.add_env_var("TZ", "UTC+10:00");
let work_dir = test_env.work_dir("repo");
let output = work_dir.run_jj(["log", "-T", "author.timestamp().local()"]);
insta::assert_snapshot!(output, @r"
@ 2001-02-03 08:05:07.000 +11:00
◆ 1970-01-01 11:00:00.000 +11:00
[EOF]
");
}
#[test]
fn test_log_author_timestamp_after_before() {
let test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
work_dir.run_jj(["describe", "-m", "first"]).success();
let template = r#"
separate(" ",
author.timestamp(),
":",
if(author.timestamp().after("1969"), "(after 1969)", "(before 1969)"),
if(author.timestamp().before("1975"), "(before 1975)", "(after 1975)"),
if(author.timestamp().before("now"), "(before now)", "(after now)")
) ++ "\n""#;
let output = work_dir.run_jj(["log", "--no-graph", "-T", template]);
insta::assert_snapshot!(output, @r"
2001-02-03 04:05:08.000 +07:00 : (after 1969) (after 1975) (before now)
1970-01-01 00:00:00.000 +00:00 : (after 1969) (before 1975) (before now)
[EOF]
");
// Should display error with invalid date.
let template = r#"author.timestamp().after("invalid date")"#;
let output = work_dir.run_jj(["log", "-r@", "--no-graph", "-T", template]);
insta::assert_snapshot!(output, @r#"
------- stderr -------
Error: Failed to parse template: Invalid date pattern
Caused by:
1: --> 1:26
|
1 | author.timestamp().after("invalid date")
| ^------------^
|
= Invalid date pattern
2: expected unsupported identifier as position 0..7
[EOF]
[exit status: 1]
"#);
}
#[test]
fn test_mine_is_true_when_author_is_user() {
let test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
work_dir
.run_jj([
"--config=user.email=johndoe@example.com",
"--config=user.name=John Doe",
"new",
])
.success();
let output = work_dir.run_jj([
"log",
"-T",
r#"coalesce(if(mine, "mine"), author.email(), email_placeholder)"#,
]);
insta::assert_snapshot!(output, @r"
@ johndoe@example.com
○ mine
◆ (no email set)
[EOF]
");
}
#[test]
fn test_log_default() {
let test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
work_dir.write_file("file1", "foo\n");
work_dir.run_jj(["describe", "-m", "add a file"]).success();
work_dir.run_jj(["new", "-m", "description 1"]).success();
work_dir
.run_jj(["bookmark", "create", "-r@", "my-bookmark"])
.success();
// Test default log output format
let output = work_dir.run_jj(["log"]);
insta::assert_snapshot!(output, @r"
@ kkmpptxz test.user@example.com 2001-02-03 08:05:09 my-bookmark c938c088
│ (empty) description 1
○ qpvuntsm test.user@example.com 2001-02-03 08:05:08 007859d3
│ add a file
◆ zzzzzzzz root() 00000000
[EOF]
");
// Color
let output = work_dir.run_jj(["log", "--color=always"]);
insta::assert_snapshot!(output, @r"
[1m[38;5;2m@[0m [1m[38;5;13mk[38;5;8mkmpptxz[39m [38;5;3mtest.user@example.com[39m [38;5;14m2001-02-03 08:05:09[39m [38;5;13mmy-bookmark[39m [38;5;12mc[38;5;8m938c088[39m[0m
│ [1m[38;5;10m(empty)[39m description 1[0m
○ [1m[38;5;5mq[0m[38;5;8mpvuntsm[39m [38;5;3mtest.user@example.com[39m [38;5;6m2001-02-03 08:05:08[39m [1m[38;5;4m007[0m[38;5;8m859d3[39m
│ add a file
[1m[38;5;14m◆[0m [1m[38;5;5mz[0m[38;5;8mzzzzzzz[39m [38;5;2mroot()[39m [1m[38;5;4m000[0m[38;5;8m00000[39m
[EOF]
");
// Color without graph
let output = work_dir.run_jj(["log", "--color=always", "--no-graph"]);
insta::assert_snapshot!(output, @r"
[1m[38;5;13mk[38;5;8mkmpptxz[39m [38;5;3mtest.user@example.com[39m [38;5;14m2001-02-03 08:05:09[39m [38;5;13mmy-bookmark[39m [38;5;12mc[38;5;8m938c088[39m[0m
[1m[38;5;10m(empty)[39m description 1[0m
[1m[38;5;5mq[0m[38;5;8mpvuntsm[39m [38;5;3mtest.user@example.com[39m [38;5;6m2001-02-03 08:05:08[39m [1m[38;5;4m007[0m[38;5;8m859d3[39m
add a file
[1m[38;5;5mz[0m[38;5;8mzzzzzzz[39m [38;5;2mroot()[39m [1m[38;5;4m000[0m[38;5;8m00000[39m
[EOF]
");
}
#[test]
fn test_log_default_without_working_copy() {
let test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
work_dir.run_jj(["workspace", "forget"]).success();
let output = work_dir.run_jj(["log"]);
insta::assert_snapshot!(output, @r"
◆ zzzzzzzz root() 00000000
[EOF]
");
}
#[test]
fn test_log_builtin_templates() {
let test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
// Render without graph to test line ending
let render = |template| work_dir.run_jj(["log", "-T", template, "--no-graph"]);
work_dir
.run_jj(["--config=user.email=''", "--config=user.name=''", "new"])
.success();
work_dir
.run_jj(["bookmark", "create", "-r@", "my-bookmark"])
.success();
insta::assert_snapshot!(render(r#"builtin_log_oneline"#), @r"
rlvkpnrz (no email set) 2001-02-03 08:05:08 my-bookmark aec3ec96 (empty) (no description set)
qpvuntsm test.user 2001-02-03 08:05:07 e8849ae1 (empty) (no description set)
zzzzzzzz root() 00000000
[EOF]
");
insta::assert_snapshot!(render(r#"builtin_log_compact"#), @r"
rlvkpnrz (no email set) 2001-02-03 08:05:08 my-bookmark aec3ec96
(empty) (no description set)
qpvuntsm test.user@example.com 2001-02-03 08:05:07 e8849ae1
(empty) (no description set)
zzzzzzzz root() 00000000
[EOF]
");
insta::assert_snapshot!(render(r#"builtin_log_comfortable"#), @r"
rlvkpnrz (no email set) 2001-02-03 08:05:08 my-bookmark aec3ec96
(empty) (no description set)
qpvuntsm test.user@example.com 2001-02-03 08:05:07 e8849ae1
(empty) (no description set)
zzzzzzzz root() 00000000
[EOF]
");
insta::assert_snapshot!(render(r#"builtin_log_detailed"#), @r"
Commit ID: aec3ec964d0771edea9da48a2a170bc6ffa1c725
Change ID: rlvkpnrzqnoowoytxnquwvuryrwnrmlp
Bookmarks: my-bookmark
Author : (no name set) <(no email set)> (2001-02-03 08:05:08)
Committer: (no name set) <(no email set)> (2001-02-03 08:05:08)
(no description set)
Commit ID: e8849ae12c709f2321908879bc724fdb2ab8a781
Change ID: qpvuntsmwlqtpsluzzsnyyzlmlwvmlnu
Author : Test User <test.user@example.com> (2001-02-03 08:05:07)
Committer: Test User <test.user@example.com> (2001-02-03 08:05:07)
(no description set)
Commit ID: 0000000000000000000000000000000000000000
Change ID: zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
Author : (no name set) <(no email set)> (1970-01-01 11:00:00)
Committer: (no name set) <(no email set)> (1970-01-01 11:00:00)
(no description set)
[EOF]
");
}
#[test]
fn test_log_builtin_templates_colored() {
let test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
let render = |template| work_dir.run_jj(["--color=always", "log", "-T", template]);
work_dir
.run_jj(["--config=user.email=''", "--config=user.name=''", "new"])
.success();
work_dir
.run_jj(["bookmark", "create", "-r@", "my-bookmark"])
.success();
insta::assert_snapshot!(render(r#"builtin_log_oneline"#), @r"
[1m[38;5;2m@[0m [1m[38;5;13mr[38;5;8mlvkpnrz[39m [38;5;9m(no email set)[39m [38;5;14m2001-02-03 08:05:08[39m [38;5;13mmy-bookmark[39m [38;5;12ma[38;5;8mec3ec96[39m [38;5;10m(empty)[39m [38;5;10m(no description set)[39m[0m
○ [1m[38;5;5mq[0m[38;5;8mpvuntsm[39m [38;5;3mtest.user[39m [38;5;6m2001-02-03 08:05:07[39m [1m[38;5;4me[0m[38;5;8m8849ae1[39m [38;5;2m(empty)[39m [38;5;2m(no description set)[39m
[1m[38;5;14m◆[0m [1m[38;5;5mz[0m[38;5;8mzzzzzzz[39m [38;5;2mroot()[39m [1m[38;5;4m0[0m[38;5;8m0000000[39m
[EOF]
");
insta::assert_snapshot!(render(r#"builtin_log_compact"#), @r"
[1m[38;5;2m@[0m [1m[38;5;13mr[38;5;8mlvkpnrz[39m [38;5;9m(no email set)[39m [38;5;14m2001-02-03 08:05:08[39m [38;5;13mmy-bookmark[39m [38;5;12ma[38;5;8mec3ec96[39m[0m
│ [1m[38;5;10m(empty)[39m [38;5;10m(no description set)[39m[0m
○ [1m[38;5;5mq[0m[38;5;8mpvuntsm[39m [38;5;3mtest.user@example.com[39m [38;5;6m2001-02-03 08:05:07[39m [1m[38;5;4me[0m[38;5;8m8849ae1[39m
│ [38;5;2m(empty)[39m [38;5;2m(no description set)[39m
[1m[38;5;14m◆[0m [1m[38;5;5mz[0m[38;5;8mzzzzzzz[39m [38;5;2mroot()[39m [1m[38;5;4m0[0m[38;5;8m0000000[39m
[EOF]
");
insta::assert_snapshot!(render(r#"builtin_log_comfortable"#), @r"
[1m[38;5;2m@[0m [1m[38;5;13mr[38;5;8mlvkpnrz[39m [38;5;9m(no email set)[39m [38;5;14m2001-02-03 08:05:08[39m [38;5;13mmy-bookmark[39m [38;5;12ma[38;5;8mec3ec96[39m[0m
│ [1m[38;5;10m(empty)[39m [38;5;10m(no description set)[39m[0m
│
○ [1m[38;5;5mq[0m[38;5;8mpvuntsm[39m [38;5;3mtest.user@example.com[39m [38;5;6m2001-02-03 08:05:07[39m [1m[38;5;4me[0m[38;5;8m8849ae1[39m
│ [38;5;2m(empty)[39m [38;5;2m(no description set)[39m
│
[1m[38;5;14m◆[0m [1m[38;5;5mz[0m[38;5;8mzzzzzzz[39m [38;5;2mroot()[39m [1m[38;5;4m0[0m[38;5;8m0000000[39m
[EOF]
");
insta::assert_snapshot!(render(r#"builtin_log_detailed"#), @r"
[1m[38;5;2m@[0m Commit ID: [38;5;4maec3ec964d0771edea9da48a2a170bc6ffa1c725[39m
│ Change ID: [38;5;5mrlvkpnrzqnoowoytxnquwvuryrwnrmlp[39m
│ Bookmarks: [38;5;5mmy-bookmark[39m
│ Author : [38;5;1m(no name set)[39m <[38;5;1m(no email set)[39m> ([38;5;6m2001-02-03 08:05:08[39m)
│ Committer: [38;5;1m(no name set)[39m <[38;5;1m(no email set)[39m> ([38;5;6m2001-02-03 08:05:08[39m)
│
│ [38;5;2m (no description set)[39m
│
○ Commit ID: [38;5;4me8849ae12c709f2321908879bc724fdb2ab8a781[39m
│ Change ID: [38;5;5mqpvuntsmwlqtpsluzzsnyyzlmlwvmlnu[39m
│ Author : [38;5;3mTest User[39m <[38;5;3mtest.user@example.com[39m> ([38;5;6m2001-02-03 08:05:07[39m)
│ Committer: [38;5;3mTest User[39m <[38;5;3mtest.user@example.com[39m> ([38;5;6m2001-02-03 08:05:07[39m)
│
│ [38;5;2m (no description set)[39m
│
[1m[38;5;14m◆[0m Commit ID: [38;5;4m0000000000000000000000000000000000000000[39m
Change ID: [38;5;5mzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz[39m
Author : [38;5;1m(no name set)[39m <[38;5;1m(no email set)[39m> ([38;5;6m1970-01-01 11:00:00[39m)
Committer: [38;5;1m(no name set)[39m <[38;5;1m(no email set)[39m> ([38;5;6m1970-01-01 11:00:00[39m)
[38;5;2m (no description set)[39m
[EOF]
");
}
#[test]
fn test_log_builtin_templates_colored_debug() {
let test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
let render = |template| work_dir.run_jj(["--color=debug", "log", "-T", template]);
work_dir
.run_jj(["--config=user.email=''", "--config=user.name=''", "new"])
.success();
work_dir
.run_jj(["bookmark", "create", "-r@", "my-bookmark"])
.success();
insta::assert_snapshot!(render(r#"builtin_log_oneline"#), @r"
[1m[38;5;2m<<log commit node working_copy::@>>[0m [1m[38;5;13m<<log commit working_copy change_id shortest prefix::r>>[38;5;8m<<log commit working_copy change_id shortest rest::lvkpnrz>>[39m<<log commit working_copy:: >>[38;5;9m<<log commit working_copy email placeholder::(no email set)>>[39m<<log commit working_copy:: >>[38;5;14m<<log commit working_copy committer timestamp local format::2001-02-03 08:05:08>>[39m<<log commit working_copy:: >>[38;5;13m<<log commit working_copy bookmarks name::my-bookmark>>[39m<<log commit working_copy:: >>[38;5;12m<<log commit working_copy commit_id shortest prefix::a>>[38;5;8m<<log commit working_copy commit_id shortest rest::ec3ec96>>[39m<<log commit working_copy:: >>[38;5;10m<<log commit working_copy empty::(empty)>>[39m<<log commit working_copy:: >>[38;5;10m<<log commit working_copy empty description placeholder::(no description set)>>[39m<<log commit working_copy::>>[0m
<<log commit node::○>> [1m[38;5;5m<<log commit change_id shortest prefix::q>>[0m[38;5;8m<<log commit change_id shortest rest::pvuntsm>>[39m<<log commit:: >>[38;5;3m<<log commit author email local::test.user>>[39m<<log commit:: >>[38;5;6m<<log commit committer timestamp local format::2001-02-03 08:05:07>>[39m<<log commit:: >>[1m[38;5;4m<<log commit commit_id shortest prefix::e>>[0m[38;5;8m<<log commit commit_id shortest rest::8849ae1>>[39m<<log commit:: >>[38;5;2m<<log commit empty::(empty)>>[39m<<log commit:: >>[38;5;2m<<log commit empty description placeholder::(no description set)>>[39m<<log commit::>>
[1m[38;5;14m<<log commit node immutable::◆>>[0m [1m[38;5;5m<<log commit change_id shortest prefix::z>>[0m[38;5;8m<<log commit change_id shortest rest::zzzzzzz>>[39m<<log commit:: >>[38;5;2m<<log commit root::root()>>[39m<<log commit:: >>[1m[38;5;4m<<log commit commit_id shortest prefix::0>>[0m[38;5;8m<<log commit commit_id shortest rest::0000000>>[39m<<log commit::>>
[EOF]
");
insta::assert_snapshot!(render(r#"builtin_log_compact"#), @r"
[1m[38;5;2m<<log commit node working_copy::@>>[0m [1m[38;5;13m<<log commit working_copy change_id shortest prefix::r>>[38;5;8m<<log commit working_copy change_id shortest rest::lvkpnrz>>[39m<<log commit working_copy:: >>[38;5;9m<<log commit working_copy email placeholder::(no email set)>>[39m<<log commit working_copy:: >>[38;5;14m<<log commit working_copy committer timestamp local format::2001-02-03 08:05:08>>[39m<<log commit working_copy:: >>[38;5;13m<<log commit working_copy bookmarks name::my-bookmark>>[39m<<log commit working_copy:: >>[38;5;12m<<log commit working_copy commit_id shortest prefix::a>>[38;5;8m<<log commit working_copy commit_id shortest rest::ec3ec96>>[39m<<log commit working_copy::>>[0m
│ [1m[38;5;10m<<log commit working_copy empty::(empty)>>[39m<<log commit working_copy:: >>[38;5;10m<<log commit working_copy empty description placeholder::(no description set)>>[39m<<log commit working_copy::>>[0m
<<log commit node::○>> [1m[38;5;5m<<log commit change_id shortest prefix::q>>[0m[38;5;8m<<log commit change_id shortest rest::pvuntsm>>[39m<<log commit:: >>[38;5;3m<<log commit author email local::test.user>><<log commit author email::@>><<log commit author email domain::example.com>>[39m<<log commit:: >>[38;5;6m<<log commit committer timestamp local format::2001-02-03 08:05:07>>[39m<<log commit:: >>[1m[38;5;4m<<log commit commit_id shortest prefix::e>>[0m[38;5;8m<<log commit commit_id shortest rest::8849ae1>>[39m<<log commit::>>
│ [38;5;2m<<log commit empty::(empty)>>[39m<<log commit:: >>[38;5;2m<<log commit empty description placeholder::(no description set)>>[39m<<log commit::>>
[1m[38;5;14m<<log commit node immutable::◆>>[0m [1m[38;5;5m<<log commit change_id shortest prefix::z>>[0m[38;5;8m<<log commit change_id shortest rest::zzzzzzz>>[39m<<log commit:: >>[38;5;2m<<log commit root::root()>>[39m<<log commit:: >>[1m[38;5;4m<<log commit commit_id shortest prefix::0>>[0m[38;5;8m<<log commit commit_id shortest rest::0000000>>[39m<<log commit::>>
[EOF]
");
insta::assert_snapshot!(render(r#"builtin_log_comfortable"#), @r"
[1m[38;5;2m<<log commit node working_copy::@>>[0m [1m[38;5;13m<<log commit working_copy change_id shortest prefix::r>>[38;5;8m<<log commit working_copy change_id shortest rest::lvkpnrz>>[39m<<log commit working_copy:: >>[38;5;9m<<log commit working_copy email placeholder::(no email set)>>[39m<<log commit working_copy:: >>[38;5;14m<<log commit working_copy committer timestamp local format::2001-02-03 08:05:08>>[39m<<log commit working_copy:: >>[38;5;13m<<log commit working_copy bookmarks name::my-bookmark>>[39m<<log commit working_copy:: >>[38;5;12m<<log commit working_copy commit_id shortest prefix::a>>[38;5;8m<<log commit working_copy commit_id shortest rest::ec3ec96>>[39m<<log commit working_copy::>>[0m
│ [1m[38;5;10m<<log commit working_copy empty::(empty)>>[39m<<log commit working_copy:: >>[38;5;10m<<log commit working_copy empty description placeholder::(no description set)>>[39m<<log commit working_copy::>>[0m
│ <<log commit::>>
<<log commit node::○>> [1m[38;5;5m<<log commit change_id shortest prefix::q>>[0m[38;5;8m<<log commit change_id shortest rest::pvuntsm>>[39m<<log commit:: >>[38;5;3m<<log commit author email local::test.user>><<log commit author email::@>><<log commit author email domain::example.com>>[39m<<log commit:: >>[38;5;6m<<log commit committer timestamp local format::2001-02-03 08:05:07>>[39m<<log commit:: >>[1m[38;5;4m<<log commit commit_id shortest prefix::e>>[0m[38;5;8m<<log commit commit_id shortest rest::8849ae1>>[39m<<log commit::>>
│ [38;5;2m<<log commit empty::(empty)>>[39m<<log commit:: >>[38;5;2m<<log commit empty description placeholder::(no description set)>>[39m<<log commit::>>
│ <<log commit::>>
[1m[38;5;14m<<log commit node immutable::◆>>[0m [1m[38;5;5m<<log commit change_id shortest prefix::z>>[0m[38;5;8m<<log commit change_id shortest rest::zzzzzzz>>[39m<<log commit:: >>[38;5;2m<<log commit root::root()>>[39m<<log commit:: >>[1m[38;5;4m<<log commit commit_id shortest prefix::0>>[0m[38;5;8m<<log commit commit_id shortest rest::0000000>>[39m<<log commit::>>
<<log commit::>>
[EOF]
");
insta::assert_snapshot!(render(r#"builtin_log_detailed"#), @r"
[1m[38;5;2m<<log commit node working_copy::@>>[0m <<log commit::Commit ID: >>[38;5;4m<<log commit commit_id::aec3ec964d0771edea9da48a2a170bc6ffa1c725>>[39m<<log commit::>>
│ <<log commit::Change ID: >>[38;5;5m<<log commit change_id::rlvkpnrzqnoowoytxnquwvuryrwnrmlp>>[39m<<log commit::>>
│ <<log commit::Bookmarks: >>[38;5;5m<<log commit local_bookmarks name::my-bookmark>>[39m<<log commit::>>
│ <<log commit::Author : >>[38;5;1m<<log commit name placeholder::(no name set)>>[39m<<log commit:: <>>[38;5;1m<<log commit email placeholder::(no email set)>>[39m<<log commit::> (>>[38;5;6m<<log commit author timestamp local format::2001-02-03 08:05:08>>[39m<<log commit::)>>
│ <<log commit::Committer: >>[38;5;1m<<log commit name placeholder::(no name set)>>[39m<<log commit:: <>>[38;5;1m<<log commit email placeholder::(no email set)>>[39m<<log commit::> (>>[38;5;6m<<log commit committer timestamp local format::2001-02-03 08:05:08>>[39m<<log commit::)>>
│ <<log commit::>>
│ [38;5;2m<<log commit empty description placeholder:: (no description set)>>[39m<<log commit::>>
│ <<log commit::>>
<<log commit node::○>> <<log commit::Commit ID: >>[38;5;4m<<log commit commit_id::e8849ae12c709f2321908879bc724fdb2ab8a781>>[39m<<log commit::>>
│ <<log commit::Change ID: >>[38;5;5m<<log commit change_id::qpvuntsmwlqtpsluzzsnyyzlmlwvmlnu>>[39m<<log commit::>>
│ <<log commit::Author : >>[38;5;3m<<log commit author name::Test User>>[39m<<log commit:: <>>[38;5;3m<<log commit author email local::test.user>><<log commit author email::@>><<log commit author email domain::example.com>>[39m<<log commit::> (>>[38;5;6m<<log commit author timestamp local format::2001-02-03 08:05:07>>[39m<<log commit::)>>
│ <<log commit::Committer: >>[38;5;3m<<log commit committer name::Test User>>[39m<<log commit:: <>>[38;5;3m<<log commit committer email local::test.user>><<log commit committer email::@>><<log commit committer email domain::example.com>>[39m<<log commit::> (>>[38;5;6m<<log commit committer timestamp local format::2001-02-03 08:05:07>>[39m<<log commit::)>>
│ <<log commit::>>
│ [38;5;2m<<log commit empty description placeholder:: (no description set)>>[39m<<log commit::>>
│ <<log commit::>>
[1m[38;5;14m<<log commit node immutable::◆>>[0m <<log commit::Commit ID: >>[38;5;4m<<log commit commit_id::0000000000000000000000000000000000000000>>[39m<<log commit::>>
<<log commit::Change ID: >>[38;5;5m<<log commit change_id::zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz>>[39m<<log commit::>>
<<log commit::Author : >>[38;5;1m<<log commit name placeholder::(no name set)>>[39m<<log commit:: <>>[38;5;1m<<log commit email placeholder::(no email set)>>[39m<<log commit::> (>>[38;5;6m<<log commit author timestamp local format::1970-01-01 11:00:00>>[39m<<log commit::)>>
<<log commit::Committer: >>[38;5;1m<<log commit name placeholder::(no name set)>>[39m<<log commit:: <>>[38;5;1m<<log commit email placeholder::(no email set)>>[39m<<log commit::> (>>[38;5;6m<<log commit committer timestamp local format::1970-01-01 11:00:00>>[39m<<log commit::)>>
<<log commit::>>
[38;5;2m<<log commit empty description placeholder:: (no description set)>>[39m<<log commit::>>
<<log commit::>>
[EOF]
");
}
#[test]
fn test_log_evolog_divergence() {
let test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
work_dir.write_file("file", "foo\n");
work_dir
.run_jj(["describe", "-m", "description 1"])
.success();
// No divergence
let output = work_dir.run_jj(["log"]);
insta::assert_snapshot!(output, @r"
@ qpvuntsm test.user@example.com 2001-02-03 08:05:08 556daeb7
│ description 1
◆ zzzzzzzz root() 00000000
[EOF]
");
// Create divergence
work_dir
.run_jj(["describe", "-m", "description 2", "--at-operation", "@-"])
.success();
let output = work_dir.run_jj(["log"]);
insta::assert_snapshot!(output, @r"
@ qpvuntsm?? test.user@example.com 2001-02-03 08:05:08 556daeb7
│ description 1
│ ○ qpvuntsm?? test.user@example.com 2001-02-03 08:05:10 5cea51a1
├─╯ description 2
◆ zzzzzzzz root() 00000000
[EOF]
------- stderr -------
Concurrent modification detected, resolving automatically.
[EOF]
");
// Color
let output = work_dir.run_jj(["log", "--color=always"]);
insta::assert_snapshot!(output, @r"
[1m[38;5;2m@[0m [1m[4m[38;5;1mq[24mpvuntsm[38;5;9m??[39m [38;5;3mtest.user@example.com[39m [38;5;14m2001-02-03 08:05:08[39m [38;5;12m55[38;5;8m6daeb7[39m[0m
│ [1mdescription 1[0m
│ ○ [1m[4m[38;5;1mq[0m[38;5;1mpvuntsm??[39m [38;5;3mtest.user@example.com[39m [38;5;6m2001-02-03 08:05:10[39m [1m[38;5;4m5c[0m[38;5;8mea51a1[39m
├─╯ description 2
[1m[38;5;14m◆[0m [1m[38;5;5mz[0m[38;5;8mzzzzzzz[39m [38;5;2mroot()[39m [1m[38;5;4m0[0m[38;5;8m0000000[39m
[EOF]
");
// Evolog and hidden divergent
let output = work_dir.run_jj(["evolog"]);
insta::assert_snapshot!(output, @r"
@ qpvuntsm?? test.user@example.com 2001-02-03 08:05:08 556daeb7
│ description 1
│ -- operation fec5a045b947 (2001-02-03 08:05:08) describe commit d0c049cd993a8d3a2e69ba6df98788e264ea9fa1
○ qpvuntsm hidden test.user@example.com 2001-02-03 08:05:08 d0c049cd
│ (no description set)
│ -- operation 911e64a1b666 (2001-02-03 08:05:08) snapshot working copy
○ qpvuntsm hidden test.user@example.com 2001-02-03 08:05:07 e8849ae1
(empty) (no description set)
-- operation 8f47435a3990 (2001-02-03 08:05:07) add workspace 'default'
[EOF]
");
// Colored evolog
let output = work_dir.run_jj(["evolog", "--color=always"]);
insta::assert_snapshot!(output, @r"
[1m[38;5;2m@[0m [1m[4m[38;5;1mq[24mpvuntsm[38;5;9m??[39m [38;5;3mtest.user@example.com[39m [38;5;14m2001-02-03 08:05:08[39m [38;5;12m55[38;5;8m6daeb7[39m[0m
│ [1mdescription 1[0m
│ [38;5;8m--[39m operation [38;5;4mfec5a045b947[39m ([38;5;6m2001-02-03 08:05:08[39m) describe commit d0c049cd993a8d3a2e69ba6df98788e264ea9fa1
○ [1m[39mq[0m[38;5;8mpvuntsm[39m hidden [38;5;3mtest.user@example.com[39m [38;5;6m2001-02-03 08:05:08[39m [1m[38;5;4md[0m[38;5;8m0c049cd[39m
│ [38;5;3m(no description set)[39m
│ [38;5;8m--[39m operation [38;5;4m911e64a1b666[39m ([38;5;6m2001-02-03 08:05:08[39m) snapshot working copy
○ [1m[39mq[0m[38;5;8mpvuntsm[39m hidden [38;5;3mtest.user@example.com[39m [38;5;6m2001-02-03 08:05:07[39m [1m[38;5;4me[0m[38;5;8m8849ae1[39m
[38;5;2m(empty)[39m [38;5;2m(no description set)[39m
[38;5;8m--[39m operation [38;5;4m8f47435a3990[39m ([38;5;6m2001-02-03 08:05:07[39m) add workspace 'default'
[EOF]
");
}
#[test]
fn test_log_bookmarks() {
let test_env = TestEnvironment::default();
test_env.add_config("git.auto-local-bookmark = true");
test_env.add_config(r#"revset-aliases."immutable_heads()" = "none()""#);
test_env.run_jj_in(".", ["git", "init", "origin"]).success();
let origin_dir = test_env.work_dir("origin");
let origin_git_repo_path = origin_dir
.root()
.join(".jj")
.join("repo")
.join("store")
.join("git");
// Created some bookmarks on the remote
origin_dir
.run_jj(["describe", "-m=description 1"])
.success();
origin_dir
.run_jj(["bookmark", "create", "-r@", "bookmark1"])
.success();
origin_dir
.run_jj(["new", "root()", "-m=description 2"])
.success();
origin_dir
.run_jj(["bookmark", "create", "-r@", "bookmark2", "unchanged"])
.success();
origin_dir
.run_jj(["new", "root()", "-m=description 3"])
.success();
origin_dir
.run_jj(["bookmark", "create", "-r@", "bookmark3"])
.success();
origin_dir.run_jj(["git", "export"]).success();
test_env
.run_jj_in(
".",
[
"git",
"clone",
origin_git_repo_path.to_str().unwrap(),
"local",
],
)
.success();
let work_dir = test_env.work_dir("local");
// Rewrite bookmark1, move bookmark2 forward, create conflict in bookmark3, add
// new-bookmark
work_dir
.run_jj(["describe", "bookmark1", "-m", "modified bookmark1 commit"])
.success();
work_dir.run_jj(["new", "bookmark2"]).success();
work_dir
.run_jj(["bookmark", "set", "bookmark2", "--to=@"])
.success();
work_dir
.run_jj(["bookmark", "create", "-r@", "new-bookmark"])
.success();
work_dir
.run_jj(["describe", "bookmark3", "-m=local"])
.success();
origin_dir
.run_jj(["describe", "bookmark3", "-m=origin"])
.success();
origin_dir.run_jj(["git", "export"]).success();
work_dir.run_jj(["git", "fetch"]).success();
let template = r#"commit_id.short() ++ " " ++ if(bookmarks, bookmarks, "(no bookmarks)")"#;
let output = work_dir.run_jj(["log", "-T", template]);
insta::assert_snapshot!(output, @r"
@ 5987a4a000d5 bookmark2* new-bookmark
○ 38a204733702 bookmark2@origin unchanged
│ ○ 999cf949d279 bookmark3?? bookmark3@origin
├─╯
│ ○ d30139075fb1 bookmark3??
├─╯
│ ○ c7f578d6e544 bookmark1*
├─╯
◆ 000000000000 (no bookmarks)
[EOF]
");
let template = r#"bookmarks.map(|b| separate("/", b.remote(), b.name())).join(", ")"#;
let output = work_dir.run_jj(["log", "-T", template]);
insta::assert_snapshot!(output, @r"
@ bookmark2, new-bookmark
○ origin/bookmark2, unchanged
│ ○ bookmark3, origin/bookmark3
├─╯
│ ○ bookmark3
├─╯
│ ○ bookmark1
├─╯
◆
[EOF]
");
let template = r#"separate(" ", "L:", local_bookmarks, "R:", remote_bookmarks)"#;
let output = work_dir.run_jj(["log", "-T", template]);
insta::assert_snapshot!(output, @r"
@ L: bookmark2* new-bookmark R:
○ L: unchanged R: bookmark2@origin unchanged@origin
│ ○ L: bookmark3?? R: bookmark3@origin
├─╯
│ ○ L: bookmark3?? R:
├─╯
│ ○ L: bookmark1* R:
├─╯
◆ L: R:
[EOF]
");
let template = r#"
remote_bookmarks.map(|ref| concat(
ref,
if(ref.tracked(),
"(+" ++ ref.tracking_ahead_count().lower()
++ "/-" ++ ref.tracking_behind_count().lower() ++ ")"),
))
"#;
let output = work_dir.run_jj(["log", "-r::remote_bookmarks()", "-T", template]);
insta::assert_snapshot!(output, @r"
○ bookmark3@origin(+0/-1)
│ ○ bookmark2@origin(+0/-1) unchanged@origin(+0/-0)
├─╯
│ ○ bookmark1@origin(+1/-1)
├─╯
◆
[EOF]
");
}
#[test]
fn test_log_git_head() {
let test_env = TestEnvironment::default();
let work_dir = test_env.work_dir("repo");
git::init(work_dir.root());
work_dir.run_jj(["git", "init", "--git-repo=."]).success();
work_dir.run_jj(["new", "-m=initial"]).success();
work_dir.write_file("file", "foo\n");
let output = work_dir.run_jj(["log", "-T", "git_head"]);
insta::assert_snapshot!(output, @r"
@ false
○ true
◆ false
[EOF]
");
let output = work_dir.run_jj(["log", "--color=always"]);
insta::assert_snapshot!(output, @r"
[1m[38;5;2m@[0m [1m[38;5;13mr[38;5;8mlvkpnrz[39m [38;5;3mtest.user@example.com[39m [38;5;14m2001-02-03 08:05:09[39m [38;5;12m6[38;5;8m87fadfd[39m[0m
│ [1minitial[0m
○ [1m[38;5;5mq[0m[38;5;8mpvuntsm[39m [38;5;3mtest.user@example.com[39m [38;5;6m2001-02-03 08:05:07[39m [38;5;2mgit_head()[39m [1m[38;5;4me[0m[38;5;8m8849ae1[39m
│ [38;5;2m(empty)[39m [38;5;2m(no description set)[39m
[1m[38;5;14m◆[0m [1m[38;5;5mz[0m[38;5;8mzzzzzzz[39m [38;5;2mroot()[39m [1m[38;5;4m0[0m[38;5;8m0000000[39m
[EOF]
");
}
#[test]
fn test_log_customize_short_id() {
let test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
work_dir.run_jj(["describe", "-m", "first"]).success();
// Customize both the commit and the change id
let decl = "template-aliases.'format_short_id(id)'";
let output = work_dir.run_jj([
"log",
"--config",
&format!(r#"{decl}='id.shortest(5).prefix().upper() ++ "_" ++ id.shortest(5).rest()'"#),
]);
insta::assert_snapshot!(output, @r"
@ Q_pvun test.user@example.com 2001-02-03 08:05:08 6_8a50
│ (empty) first
◆ Z_zzzz root() 0_0000
[EOF]
");
// Customize only the change id
let output = work_dir.run_jj([
"log",
"--config=template-aliases.'format_short_change_id(id)'='format_short_id(id).upper()'",
]);
insta::assert_snapshot!(output, @r"
@ QPVUNTSM test.user@example.com 2001-02-03 08:05:08 68a50538
│ (empty) first
◆ ZZZZZZZZ root() 00000000
[EOF]
");
}
#[test]
fn test_log_immutable() {
let test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
work_dir.run_jj(["new", "-mA", "root()"]).success();
work_dir.run_jj(["new", "-mB"]).success();
work_dir
.run_jj(["bookmark", "create", "-r@", "main"])
.success();
work_dir.run_jj(["new", "-mC"]).success();
work_dir.run_jj(["new", "-mD", "root()"]).success();
let template = r#"
separate(" ",
description.first_line(),
bookmarks,
if(immutable, "[immutable]"),
) ++ "\n"
"#;
test_env.add_config("revset-aliases.'immutable_heads()' = 'main'");
let output = work_dir.run_jj(["log", "-r::", "-T", template]);
insta::assert_snapshot!(output, @r"
@ D
│ ○ C
│ ◆ B main [immutable]
│ ◆ A [immutable]
├─╯
◆ [immutable]
[EOF]
");
// Suppress error that could be detected earlier
test_env.add_config("revsets.short-prefixes = ''");
test_env.add_config("revset-aliases.'immutable_heads()' = 'unknown_fn()'");
let output = work_dir.run_jj(["log", "-r::", "-T", template]);
insta::assert_snapshot!(output, @r"
------- stderr -------
Config error: Invalid `revset-aliases.immutable_heads()`
Caused by: --> 1:1
|
1 | unknown_fn()
| ^--------^
|
= Function `unknown_fn` doesn't exist
For help, see https://jj-vcs.github.io/jj/latest/config/ or use `jj help -k config`.
[EOF]
[exit status: 1]
");
test_env.add_config("revset-aliases.'immutable_heads()' = 'unknown_symbol'");
let output = work_dir.run_jj(["log", "-r::", "-T", template]);
insta::assert_snapshot!(output, @r#"
------- stderr -------
Error: Failed to parse template: Failed to evaluate revset
Caused by:
1: --> 5:10
|
5 | if(immutable, "[immutable]"),
| ^-------^
|
= Failed to evaluate revset
2: Revision `unknown_symbol` doesn't exist
[EOF]
[exit status: 1]
"#);
}
#[test]
fn test_log_contained_in() {
let test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
work_dir.run_jj(["new", "-mA", "root()"]).success();
work_dir.run_jj(["new", "-mB"]).success();
work_dir
.run_jj(["bookmark", "create", "-r@", "main"])
.success();
work_dir.run_jj(["new", "-mC"]).success();
work_dir.run_jj(["new", "-mD", "root()"]).success();
let template_for_revset = |revset: &str| {
format!(
r#"
separate(" ",
description.first_line(),
bookmarks,
if(self.contained_in("{revset}"), "[contained_in]"),
) ++ "\n"
"#
)
};
let output = work_dir.run_jj([
"log",
"-r::",
"-T",
&template_for_revset(r#"description(A)::"#),
]);
insta::assert_snapshot!(output, @r"
@ D
│ ○ C [contained_in]
│ ○ B main [contained_in]
│ ○ A [contained_in]
├─╯
◆
[EOF]
");
let output = work_dir.run_jj([
"log",
"-r::",
"-T",
&template_for_revset(r#"visible_heads()"#),
]);
insta::assert_snapshot!(output, @r"
@ D [contained_in]
│ ○ C [contained_in]
│ ○ B main
│ ○ A
├─╯
◆
[EOF]
");
// Suppress error that could be detected earlier
let output = work_dir.run_jj(["log", "-r::", "-T", &template_for_revset("unknown_fn()")]);
insta::assert_snapshot!(output, @r#"
------- stderr -------
Error: Failed to parse template: In revset expression
Caused by:
1: --> 5:28
|
5 | if(self.contained_in("unknown_fn()"), "[contained_in]"),
| ^------------^
|
= In revset expression
2: --> 1:1
|
1 | unknown_fn()
| ^--------^
|
= Function `unknown_fn` doesn't exist
[EOF]
[exit status: 1]
"#);
let output = work_dir.run_jj(["log", "-r::", "-T", &template_for_revset("author(x:'y')")]);
insta::assert_snapshot!(output, @r#"
------- stderr -------
Error: Failed to parse template: In revset expression
Caused by:
1: --> 5:28
|
5 | if(self.contained_in("author(x:'y')"), "[contained_in]"),
| ^-------------^
|
= In revset expression
2: --> 1:8
|
1 | author(x:'y')
| ^---^
|
= Invalid string pattern
3: Invalid string pattern kind `x:`
Hint: Try prefixing with one of `exact:`, `glob:`, `regex:`, `substring:`, or one of these with `-i` suffix added (e.g. `glob-i:`) for case-insensitive matching
[EOF]
[exit status: 1]
"#);
let output = work_dir.run_jj(["log", "-r::", "-T", &template_for_revset("maine")]);
insta::assert_snapshot!(output, @r#"
------- stderr -------
Error: Failed to parse template: Failed to evaluate revset
Caused by:
1: --> 5:28
|
5 | if(self.contained_in("maine"), "[contained_in]"),
| ^-----^
|
= Failed to evaluate revset
2: Revision `maine` doesn't exist
Hint: Did you mean `main`?
[EOF]
[exit status: 1]
"#);
}
#[test]
fn test_short_prefix_in_transaction() {
let test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
test_env.add_config(r#"
[revsets]
log = '::description(test)'
[templates]
log = 'summary ++ "\n"'
commit_summary = 'summary'
[template-aliases]
'format_id(id)' = 'id.shortest(12).prefix() ++ "[" ++ id.shortest(12).rest() ++ "]"'
'summary' = 'separate(" ", format_id(change_id), format_id(commit_id), description.first_line())'
"#);
work_dir.write_file("file", "original file\n");
work_dir.run_jj(["describe", "-m", "initial"]).success();
// Create a chain of 5 commits
for i in 0..5 {
work_dir
.run_jj(["new", "-m", &format!("commit{i}")])
.success();
work_dir.write_file("file", format!("file {i}\n"));
}
// Create 2^4 duplicates of the chain
for _ in 0..4 {
work_dir
.run_jj(["duplicate", "description(commit)"])
.success();
}
// Short prefix should be used for commit summary inside the transaction
let parent_id = "c0b41"; // Force id lookup to build index before mutation.
// If the cached index wasn't invalidated, the
// newly created commit wouldn't be found in it.
let output = work_dir.run_jj(["new", parent_id, "--no-edit", "-m", "test"]);
insta::assert_snapshot!(output, @r"
------- stderr -------
Created new commit km[kuslswpqwq] a[5d12a825adf] test
[EOF]
");
// Should match log's short prefixes
let output = work_dir.run_jj(["log", "--no-graph"]);
insta::assert_snapshot!(output, @r"
km[kuslswpqwq] a[5d12a825adf] test
y[qosqzytrlsw] c0[b41b9a1b34] commit4
r[oyxmykxtrkr] 1[2124aa50a07] commit3
m[zvwutvlkqwt] c7[673aedfb82] commit2
zs[uskulnrvyr] 4[36497fbfb9d] commit1
kk[mpptxzrspx] d[70e8b9aa12b] commit0
q[pvuntsmwlqt] 8[216f646c36d] initial
zz[zzzzzzzzzz] 0[00000000000]
[EOF]
");
test_env.add_config(r#"revsets.short-prefixes = """#);
let output = work_dir.run_jj(["log", "--no-graph"]);
insta::assert_snapshot!(output, @r"
kmk[uslswpqwq] a5[d12a825adf] test
yq[osqzytrlsw] c0b[41b9a1b34] commit4
ro[yxmykxtrkr] 121[24aa50a07] commit3
mz[vwutvlkqwt] c7[673aedfb82] commit2
zs[uskulnrvyr] 43[6497fbfb9d] commit1
kk[mpptxzrspx] d7[0e8b9aa12b] commit0
qp[vuntsmwlqt] 82[16f646c36d] initial
zz[zzzzzzzzzz] 00[0000000000]
[EOF]
");
}
#[test]
fn test_log_diff_predefined_formats() {
let test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
work_dir.write_file("file1", "a\nb\n");
work_dir.write_file("file2", "a\n");
work_dir.write_file("rename-source", "rename");
work_dir.run_jj(["new"]).success();
work_dir.write_file("file1", "a\nb\nc\n");
work_dir.write_file("file2", "b\nc\n");
std::fs::rename(
work_dir.root().join("rename-source"),
work_dir.root().join("rename-target"),
)
.unwrap();
let template = r#"
concat(
"=== color_words ===\n",
diff.color_words(),
"=== git ===\n",
diff.git(),
"=== stat ===\n",
diff.stat(80),
"=== summary ===\n",
diff.summary(),
)
"#;
// color, without paths
let output = work_dir.run_jj(["log", "--no-graph", "--color=always", "-r@", "-T", template]);
insta::assert_snapshot!(output, @r"
=== color_words ===
[38;5;3mModified regular file file1:[39m
[38;5;1m 1[39m [38;5;2m 1[39m: a
[38;5;1m 2[39m [38;5;2m 2[39m: b
[38;5;2m 3[39m: [4m[38;5;2mc[24m[39m
[38;5;3mModified regular file file2:[39m
[38;5;1m 1[39m [38;5;2m 1[39m: [4m[38;5;1ma[38;5;2mb[24m[39m
[38;5;2m 2[39m: [4m[38;5;2mc[24m[39m
[38;5;3mModified regular file rename-target (rename-source => rename-target):[39m
=== git ===
[1mdiff --git a/file1 b/file1[0m
[1mindex 422c2b7ab3..de980441c3 100644[0m
[1m--- a/file1[0m
[1m+++ b/file1[0m
[38;5;6m@@ -1,2 +1,3 @@[39m
a
b
[38;5;2m+[4mc[24m[39m
[1mdiff --git a/file2 b/file2[0m
[1mindex 7898192261..9ddeb5c484 100644[0m
[1m--- a/file2[0m
[1m+++ b/file2[0m
[38;5;6m@@ -1,1 +1,2 @@[39m
[38;5;1m-[4ma[24m[39m
[38;5;2m+[4mb[24m[39m
[38;5;2m+[4mc[24m[39m
[1mdiff --git a/rename-source b/rename-target[0m
[1mrename from rename-source[0m
[1mrename to rename-target[0m
=== stat ===
file1 | 1 [38;5;2m+[38;5;1m[39m
file2 | 3 [38;5;2m++[38;5;1m-[39m
{rename-source => rename-target} | 0[38;5;1m[39m
3 files changed, 3 insertions(+), 1 deletion(-)
=== summary ===
[38;5;6mM file1[39m
[38;5;6mM file2[39m
[38;5;6mR {rename-source => rename-target}[39m
[EOF]
");
// color labels
let output = work_dir.run_jj(["log", "--no-graph", "--color=debug", "-r@", "-T", template]);
insta::assert_snapshot!(output, @r"
<<log commit::=== color_words ===>>
[38;5;3m<<log commit diff color_words header::Modified regular file file1:>>[39m
[38;5;1m<<log commit diff color_words removed line_number:: 1>>[39m<<log commit diff color_words:: >>[38;5;2m<<log commit diff color_words added line_number:: 1>>[39m<<log commit diff color_words::: a>>
[38;5;1m<<log commit diff color_words removed line_number:: 2>>[39m<<log commit diff color_words:: >>[38;5;2m<<log commit diff color_words added line_number:: 2>>[39m<<log commit diff color_words::: b>>
<<log commit diff color_words:: >>[38;5;2m<<log commit diff color_words added line_number:: 3>>[39m<<log commit diff color_words::: >>[4m[38;5;2m<<log commit diff color_words added token::c>>[24m[39m
[38;5;3m<<log commit diff color_words header::Modified regular file file2:>>[39m
[38;5;1m<<log commit diff color_words removed line_number:: 1>>[39m<<log commit diff color_words:: >>[38;5;2m<<log commit diff color_words added line_number:: 1>>[39m<<log commit diff color_words::: >>[4m[38;5;1m<<log commit diff color_words removed token::a>>[38;5;2m<<log commit diff color_words added token::b>>[24m[39m<<log commit diff color_words::>>
<<log commit diff color_words:: >>[38;5;2m<<log commit diff color_words added line_number:: 2>>[39m<<log commit diff color_words::: >>[4m[38;5;2m<<log commit diff color_words added token::c>>[24m[39m
[38;5;3m<<log commit diff color_words header::Modified regular file rename-target (rename-source => rename-target):>>[39m
<<log commit::=== git ===>>
[1m<<log commit diff git file_header::diff --git a/file1 b/file1>>[0m
[1m<<log commit diff git file_header::index 422c2b7ab3..de980441c3 100644>>[0m
[1m<<log commit diff git file_header::--- a/file1>>[0m
[1m<<log commit diff git file_header::+++ b/file1>>[0m
[38;5;6m<<log commit diff git hunk_header::@@ -1,2 +1,3 @@>>[39m
<<log commit diff git context:: a>>
<<log commit diff git context:: b>>
[38;5;2m<<log commit diff git added::+>>[4m<<log commit diff git added token::c>>[24m[39m
[1m<<log commit diff git file_header::diff --git a/file2 b/file2>>[0m
[1m<<log commit diff git file_header::index 7898192261..9ddeb5c484 100644>>[0m
[1m<<log commit diff git file_header::--- a/file2>>[0m
[1m<<log commit diff git file_header::+++ b/file2>>[0m
[38;5;6m<<log commit diff git hunk_header::@@ -1,1 +1,2 @@>>[39m
[38;5;1m<<log commit diff git removed::->>[4m<<log commit diff git removed token::a>>[24m<<log commit diff git removed::>>[39m
[38;5;2m<<log commit diff git added::+>>[4m<<log commit diff git added token::b>>[24m<<log commit diff git added::>>[39m
[38;5;2m<<log commit diff git added::+>>[4m<<log commit diff git added token::c>>[24m[39m
[1m<<log commit diff git file_header::diff --git a/rename-source b/rename-target>>[0m
[1m<<log commit diff git file_header::rename from rename-source>>[0m
[1m<<log commit diff git file_header::rename to rename-target>>[0m
<<log commit::=== stat ===>>
<<log commit diff stat::file1 | 1 >>[38;5;2m<<log commit diff stat added::+>>[38;5;1m<<log commit diff stat removed::>>[39m
<<log commit diff stat::file2 | 3 >>[38;5;2m<<log commit diff stat added::++>>[38;5;1m<<log commit diff stat removed::->>[39m
<<log commit diff stat::{rename-source => rename-target} | 0>>[38;5;1m<<log commit diff stat removed::>>[39m
<<log commit diff stat stat-summary::3 files changed, 3 insertions(+), 1 deletion(-)>>
<<log commit::=== summary ===>>
[38;5;6m<<log commit diff summary modified::M file1>>[39m
[38;5;6m<<log commit diff summary modified::M file2>>[39m
[38;5;6m<<log commit diff summary renamed::R {rename-source => rename-target}>>[39m
[EOF]
");
// cwd != workspace root
let output = test_env.run_jj_in(".", ["log", "-Rrepo", "--no-graph", "-r@", "-T", template]);
insta::assert_snapshot!(output.normalize_backslash(), @r"
=== color_words ===
Modified regular file repo/file1:
1 1: a
2 2: b
3: c
Modified regular file repo/file2:
1 1: ab
2: c
Modified regular file repo/rename-target (repo/rename-source => repo/rename-target):
=== git ===
diff --git a/file1 b/file1
index 422c2b7ab3..de980441c3 100644
--- a/file1
+++ b/file1
@@ -1,2 +1,3 @@
a
b
+c
diff --git a/file2 b/file2
index 7898192261..9ddeb5c484 100644
--- a/file2
+++ b/file2
@@ -1,1 +1,2 @@
-a
+b
+c
diff --git a/rename-source b/rename-target
rename from rename-source
rename to rename-target
=== stat ===
repo/file1 | 1 +
repo/file2 | 3 ++-
repo/{rename-source => rename-target} | 0
3 files changed, 3 insertions(+), 1 deletion(-)
=== summary ===
M repo/file1
M repo/file2
R repo/{rename-source => rename-target}
[EOF]
");
// with non-default config
std::fs::write(
test_env.env_root().join("config-good.toml"),
indoc! {"
diff.color-words.context = 0
diff.color-words.max-inline-alternation = 0
diff.git.context = 1
"},
)
.unwrap();
let output = work_dir.run_jj([
"log",
"--config-file=../config-good.toml",
"--no-graph",
"-r@",
"-T",
template,
]);
insta::assert_snapshot!(output, @r"
=== color_words ===
Modified regular file file1:
...
3: c
Modified regular file file2:
1 : a
1: b
2: c
Modified regular file rename-target (rename-source => rename-target):
=== git ===
diff --git a/file1 b/file1
index 422c2b7ab3..de980441c3 100644
--- a/file1
+++ b/file1
@@ -2,1 +2,2 @@
b
+c
diff --git a/file2 b/file2
index 7898192261..9ddeb5c484 100644
--- a/file2
+++ b/file2
@@ -1,1 +1,2 @@
-a
+b
+c
diff --git a/rename-source b/rename-target
rename from rename-source
rename to rename-target
=== stat ===
file1 | 1 +
file2 | 3 ++-
{rename-source => rename-target} | 0
3 files changed, 3 insertions(+), 1 deletion(-)
=== summary ===
M file1
M file2
R {rename-source => rename-target}
[EOF]
");
// bad config
std::fs::write(
test_env.env_root().join("config-bad.toml"),
"diff.git.context = 'not an integer'\n",
)
.unwrap();
let output = work_dir.run_jj([
"log",
"--config-file=../config-bad.toml",
"-Tself.diff().git()",
]);
insta::assert_snapshot!(output, @r#"
------- stderr -------
Error: Failed to parse template: Failed to load diff settings
Caused by:
1: --> 1:13
|
1 | self.diff().git()
| ^-^
|
= Failed to load diff settings
2: Invalid type or value for diff.git.context
3: invalid type: string "not an integer", expected usize
Hint: Check the config file: ../config-bad.toml
[EOF]
[exit status: 1]
"#);
// color_words() with parameters
let template = "self.diff('file1').color_words(0)";
let output = work_dir.run_jj(["log", "--no-graph", "-r@", "-T", template]);
insta::assert_snapshot!(output, @r"
Modified regular file file1:
...
3: c
[EOF]
");
// git() with parameters
let template = "self.diff('file1').git(1)";
let output = work_dir.run_jj(["log", "--no-graph", "-r@", "-T", template]);
insta::assert_snapshot!(output, @r"
diff --git a/file1 b/file1
index 422c2b7ab3..de980441c3 100644
--- a/file1
+++ b/file1
@@ -2,1 +2,2 @@
b
+c
[EOF]
");
// custom template with files()
let template = indoc! {r#"
concat(
"=== " ++ commit_id.short() ++ " ===\n",
diff.files().map(|e| separate(" ",
e.path(),
"[" ++ e.status() ++ "]",
"source=" ++ e.source().path() ++ " [" ++ e.source().file_type() ++ "]",
"target=" ++ e.target().path() ++ " [" ++ e.target().file_type() ++ "]",
) ++ "\n").join(""),
"* " ++ separate(" ",
if(diff.files(), "non-empty", "empty"),
"len=" ++ diff.files().len(),
) ++ "\n",
)
"#};
let output = work_dir.run_jj(["log", "--no-graph", "-T", template]);
insta::assert_snapshot!(output, @r"
=== d9ea8f447a3b ===
file1 [modified] source=file1 [file] target=file1 [file]
file2 [modified] source=file2 [file] target=file2 [file]
rename-target [renamed] source=rename-source [file] target=rename-target [file]
* non-empty len=3
=== 20bc00d202c2 ===
file1 [added] source=file1 [] target=file1 [file]
file2 [added] source=file2 [] target=file2 [file]
rename-source [added] source=rename-source [] target=rename-source [file]
* non-empty len=3
=== 000000000000 ===
* empty len=0
[EOF]
");
// custom diff stat template
let template = indoc! {r#"
concat(
"=== " ++ commit_id.short() ++ " ===\n",
"* " ++ separate(" ",
"total_added=" ++ diff.stat().total_added(),
"total_removed=" ++ diff.stat().total_removed(),
) ++ "\n",
)
"#};
let output = work_dir.run_jj(["log", "--no-graph", "-T", template]);
insta::assert_snapshot!(output, @r"
=== d9ea8f447a3b ===
* total_added=3 total_removed=1
=== 20bc00d202c2 ===
* total_added=4 total_removed=0
=== 000000000000 ===
* total_added=0 total_removed=0
[EOF]
");
}
#[test]
fn test_file_list_entries() {
let test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
work_dir.create_dir("dir");
work_dir.write_file("dir/file", "content1");
work_dir.write_file("exec-file", "content1");
work_dir.write_file("conflict-exec-file", "content1");
work_dir.write_file("conflict-file", "content1");
work_dir
.run_jj(["file", "chmod", "x", "exec-file", "conflict-exec-file"])
.success();
work_dir.run_jj(["new", "root()"]).success();
work_dir.write_file("conflict-exec-file", "content2");
work_dir.write_file("conflict-file", "content2");
work_dir
.run_jj(["file", "chmod", "x", "conflict-exec-file"])
.success();
work_dir.run_jj(["new", "all:visible_heads()"]).success();
let template = indoc! {r#"
separate(" ",
path,
"[" ++ file_type ++ "]",
"conflict=" ++ conflict,
"executable=" ++ executable,
) ++ "\n"
"#};
let output = work_dir.run_jj(["file", "list", "-T", template]);
insta::assert_snapshot!(output, @r"
conflict-exec-file [conflict] conflict=true executable=true
conflict-file [conflict] conflict=true executable=false
dir/file [file] conflict=false executable=false
exec-file [file] conflict=false executable=true
[EOF]
");
}
#[cfg(unix)]
#[test]
fn test_file_list_symlink() {
let test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
std::os::unix::fs::symlink("symlink_target", work_dir.root().join("symlink")).unwrap();
let template = r#"separate(" ", path, "[" ++ file_type ++ "]") ++ "\n""#;
let output = work_dir.run_jj(["file", "list", "-T", template]);
insta::assert_snapshot!(output, @r"
symlink [symlink]
[EOF]
");
}
#[test]
fn test_signature_templates() {
let test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
work_dir.run_jj(["commit", "-m", "unsigned"]).success();
test_env.add_config("signing.behavior = 'own'");
test_env.add_config("signing.backend = 'test'");
work_dir.run_jj(["describe", "-m", "signed"]).success();
let template = r#"
if(signature,
signature.status() ++ " " ++ signature.display(),
"no",
) ++ " signature""#;
// show that signatures can render
let output = work_dir.run_jj(["log", "-T", template]);
insta::assert_snapshot!(output, @r"
@ good test-display signature
○ no signature
◆ no signature
[EOF]
");
let output = work_dir.run_jj(["show", "-T", template]);
insta::assert_snapshot!(output, @"good test-display signature[EOF]");
// builtin templates
test_env.add_config("ui.show-cryptographic-signatures = true");
let args = ["log", "-r", "..", "-T"];
let output = work_dir.run_jj_with(|cmd| cmd.args(args).arg("builtin_log_oneline"));
insta::assert_snapshot!(output, @r"
@ rlvkpnrz test.user 2001-02-03 08:05:09 eb0e9b58 [✓︎] (empty) signed
○ qpvuntsm test.user 2001-02-03 08:05:08 0604e056 (empty) unsigned
│
~
[EOF]
");
let output = work_dir.run_jj_with(|cmd| cmd.args(args).arg("builtin_log_compact"));
insta::assert_snapshot!(output, @r"
@ rlvkpnrz test.user@example.com 2001-02-03 08:05:09 eb0e9b58 [✓︎]
│ (empty) signed
○ qpvuntsm test.user@example.com 2001-02-03 08:05:08 0604e056
│ (empty) unsigned
~
[EOF]
");
let output = work_dir.run_jj_with(|cmd| cmd.args(args).arg("builtin_log_detailed"));
insta::assert_snapshot!(output, @r"
@ Commit ID: eb0e9b58b724003df03b4277d3066c1c20187ce5
│ Change ID: rlvkpnrzqnoowoytxnquwvuryrwnrmlp
│ Author : Test User <test.user@example.com> (2001-02-03 08:05:09)
│ Committer: Test User <test.user@example.com> (2001-02-03 08:05:09)
│ Signature: good signature by test-display
│
│ signed
│
○ Commit ID: 0604e056feaf8ee553fae4e06d4bfc57cdd319d6
│ Change ID: qpvuntsmwlqtpsluzzsnyyzlmlwvmlnu
~ Author : Test User <test.user@example.com> (2001-02-03 08:05:08)
Committer: Test User <test.user@example.com> (2001-02-03 08:05:08)
Signature: (no signature)
unsigned
[EOF]
");
// customization point
let config_val = r#"template-aliases."format_short_cryptographic_signature(signature)"="'status: ' ++ signature.status()""#;
let output = work_dir.run_jj_with(|cmd| {
cmd.args(args)
.arg("builtin_log_oneline")
.args(["--config", config_val])
});
insta::assert_snapshot!(output, @r"
@ rlvkpnrz test.user 2001-02-03 08:05:09 eb0e9b58 status: good (empty) signed
○ qpvuntsm test.user 2001-02-03 08:05:08 0604e056 status: <Error: No CryptographicSignature available> (empty) unsigned
│
~
[EOF]
");
}
#[test]
fn test_log_git_format_patch_template() {
let test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
work_dir.write_file("file1", "foo\n");
work_dir.write_file("file2", "bar\n");
work_dir
.run_jj([
"new",
"-m",
"some change\n\nmultiline desc\nsecond line\n\nwith blanks\n",
])
.success();
work_dir.remove_file("file1");
work_dir.write_file("file2", "modified\n");
work_dir.write_file("file3", "new\n");
let output = work_dir.run_jj([
"log",
"--no-graph",
"-T",
"git_format_patch_email_headers",
"-r@",
]);
insta::assert_snapshot!(output, @r"
From fee27496968a4347a49d69c0a634fc0d5cf7fbc0 Mon Sep 17 00:00:00 2001
From: Test User <test.user@example.com>
Date: Sat, 3 Feb 2001 04:05:08 +0700
Subject: [PATCH] some change
multiline desc
second line
with blanks
---
file1 | 1 -
file2 | 2 +-
file3 | 1 +
3 files changed, 2 insertions(+), 2 deletions(-)
[EOF]
");
}
#[test]
fn test_log_format_trailers() {
let test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
let output = work_dir.run_jj([
"log",
"--no-graph",
"-T",
"format_gerrit_change_id_trailer(self) ++ format_signed_off_by_trailer(self)",
"-r@",
]);
insta::assert_snapshot!(output, @r"
Change-Id: I6a6a69649a45c67d3e96a7e5007c110ede34dec5
Signed-off-by: Test User <test.user@example.com>
[EOF]
");
work_dir
.run_jj([
"describe",
"-r@",
"-m",
"a change with trailers",
r#"--config=templates.commit_trailers="format_signed_off_by_trailer(self) ++ format_gerrit_change_id_trailer(self)""#,
])
.success();
let output = work_dir.run_jj(["log", "--no-graph", "-T", r#"trailers ++ "\n""#, "-r@"]);
insta::assert_snapshot!(output, @r"
Signed-off-by: Test User <test.user@example.com>
Change-Id: I6a6a69649a45c67d3e96a7e5007c110ede34dec5
[EOF]
");
let output = work_dir.run_jj([
"log",
"--no-graph",
"-T",
"trailers.map(|t| t.key())",
"-r@",
]);
insta::assert_snapshot!(output, @"Signed-off-by Change-Id[EOF]");
let output = work_dir.run_jj([
"log",
"--no-graph",
"-T",
"trailers.map(|t| t.value())",
"-r@",
]);
insta::assert_snapshot!(output, @"Test User <test.user@example.com> I6a6a69649a45c67d3e96a7e5007c110ede34dec5[EOF]");
let output = work_dir.run_jj([
"log",
"--no-graph",
"-T",
r#"self.trailers().contains_key("Signed-off-by")"#,
"-r@",
]);
insta::assert_snapshot!(output, @"true[EOF]");
let output = work_dir.run_jj([
"log",
"--no-graph",
"-T",
r#"self.trailers().contains_key("foo")"#,
"-r@",
]);
insta::assert_snapshot!(output, @"false[EOF]");
}
|