Merge pull request #4298 from tiennou/gather-reflog-messages-tests Gather the reflog entry content tests
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
diff --git a/tests/refs/branches/create.c b/tests/refs/branches/create.c
index 69488e6..a4db574 100644
--- a/tests/refs/branches/create.c
+++ b/tests/refs/branches/create.c
@@ -116,51 +116,6 @@ void test_refs_branches_create__creating_a_branch_with_an_invalid_name_returns_E
git_branch_create(&branch, repo, "inv@{id", target, 0));
}
-void test_refs_branches_create__default_reflog_message(void)
-{
- git_reflog *log;
- git_buf buf = GIT_BUF_INIT;
- const git_reflog_entry *entry;
- git_annotated_commit *annotated;
- git_signature *sig;
- git_config *cfg;
-
- cl_git_pass(git_repository_config(&cfg, repo));
- cl_git_pass(git_config_set_string(cfg, "user.name", "Foo Bar"));
- cl_git_pass(git_config_set_string(cfg, "user.email", "foo@example.com"));
- git_config_free(cfg);
-
- cl_git_pass(git_signature_default(&sig, repo));
-
- retrieve_known_commit(&target, repo);
- cl_git_pass(git_branch_create(&branch, repo, NEW_BRANCH_NAME, target, false));
- cl_git_pass(git_reflog_read(&log, repo, "refs/heads/" NEW_BRANCH_NAME));
-
- entry = git_reflog_entry_byindex(log, 0);
- cl_git_pass(git_buf_printf(&buf, "branch: Created from %s", git_oid_tostr_s(git_commit_id(target))));
- cl_assert_equal_s(git_buf_cstr(&buf), git_reflog_entry_message(entry));
- cl_assert_equal_s(sig->email, git_reflog_entry_committer(entry)->email);
-
- cl_git_pass(git_reference_remove(repo, "refs/heads/" NEW_BRANCH_NAME));
- git_reference_free(branch);
- git_reflog_free(log);
- git_buf_clear(&buf);
-
- cl_git_pass(git_annotated_commit_from_revspec(&annotated, repo, "e90810b8df3"));
- cl_git_pass(git_branch_create_from_annotated(&branch, repo, NEW_BRANCH_NAME, annotated, true));
- cl_git_pass(git_reflog_read(&log, repo, "refs/heads/" NEW_BRANCH_NAME));
-
- entry = git_reflog_entry_byindex(log, 0);
- cl_git_pass(git_buf_printf(&buf, "branch: Created from e90810b8df3"));
- cl_assert_equal_s(git_buf_cstr(&buf), git_reflog_entry_message(entry));
- cl_assert_equal_s(sig->email, git_reflog_entry_committer(entry)->email);
-
- git_annotated_commit_free(annotated);
- git_buf_free(&buf);
- git_reflog_free(log);
- git_signature_free(sig);
-}
-
static void assert_branch_matches_name(
const char *expected, const char *lookup_as)
{
diff --git a/tests/refs/branches/move.c b/tests/refs/branches/move.c
index bec39e1..acd8661 100644
--- a/tests/refs/branches/move.c
+++ b/tests/refs/branches/move.c
@@ -195,41 +195,6 @@ void test_refs_branches_move__moving_the_branch_pointed_at_by_HEAD_updates_HEAD(
git_reference_free(branch);
}
-void test_refs_branches_move__default_reflog_message(void)
-{
- git_reference *branch;
- git_reference *new_branch;
- git_reflog *log;
- const git_reflog_entry *entry;
- git_signature *sig;
- git_config *cfg;
- git_oid id;
-
- cl_git_pass(git_repository_config(&cfg, repo));
- cl_git_pass(git_config_set_string(cfg, "user.name", "Foo Bar"));
- cl_git_pass(git_config_set_string(cfg, "user.email", "foo@example.com"));
- git_config_free(cfg);
-
- cl_git_pass(git_signature_default(&sig, repo));
-
- cl_git_pass(git_reference_lookup(&branch, repo, "refs/heads/master"));
- git_oid_cpy(&id, git_reference_target(branch));
- cl_git_pass(git_branch_move(&new_branch, branch, "master2", 0));
-
- cl_git_pass(git_reflog_read(&log, repo, git_reference_name(new_branch)));
- entry = git_reflog_entry_byindex(log, 0);
- cl_assert_equal_s("branch: renamed refs/heads/master to refs/heads/master2",
- git_reflog_entry_message(entry));
- cl_assert_equal_s(sig->email, git_reflog_entry_committer(entry)->email);
- cl_assert_equal_oid(&id, git_reflog_entry_id_old(entry));
- cl_assert_equal_oid(&id, git_reflog_entry_id_new(entry));
-
- git_reference_free(branch);
- git_reference_free(new_branch);
- git_reflog_free(log);
- git_signature_free(sig);
-}
-
void test_refs_branches_move__can_move_with_unicode(void)
{
git_reference *original_ref, *new_ref;
diff --git a/tests/refs/createwithlog.c b/tests/refs/createwithlog.c
deleted file mode 100644
index 4f64363..0000000
--- a/tests/refs/createwithlog.c
+++ /dev/null
@@ -1,47 +0,0 @@
-#include "clar_libgit2.h"
-
-#include "repository.h"
-#include "git2/reflog.h"
-#include "reflog.h"
-#include "ref_helpers.h"
-
-static const char *current_master_tip = "a65fedf39aefe402d3bb6e24df4d4f5fe4547750";
-
-static git_repository *g_repo;
-
-void test_refs_createwithlog__initialize(void)
-{
- g_repo = cl_git_sandbox_init("testrepo.git");
-}
-
-void test_refs_createwithlog__cleanup(void)
-{
- cl_git_sandbox_cleanup();
-}
-
-void test_refs_createwithlog__creating_a_direct_reference_adds_a_reflog_entry(void)
-{
- git_reference *reference;
- git_oid id;
- git_reflog *reflog;
- const git_reflog_entry *entry;
-
- const char *name = "refs/heads/new-head";
- const char *message = "You've been logged, mate!";
-
- git_oid_fromstr(&id, current_master_tip);
-
- cl_git_pass(
- git_reference_create(&reference, g_repo, name, &id, 0, message));
-
- cl_git_pass(git_reflog_read(&reflog, g_repo, name));
- cl_assert_equal_sz(1, git_reflog_entrycount(reflog));
-
- entry = git_reflog_entry_byindex(reflog, 0);
- cl_assert(git_oid_streq(&entry->oid_old, GIT_OID_HEX_ZERO) == 0);
- cl_assert_equal_oid(&id, &entry->oid_cur);
- cl_assert_equal_s(message, entry->msg);
-
- git_reflog_free(reflog);
- git_reference_free(reference);
-}
diff --git a/tests/refs/reflog/messages.c b/tests/refs/reflog/messages.c
new file mode 100644
index 0000000..a7a7766
--- /dev/null
+++ b/tests/refs/reflog/messages.c
@@ -0,0 +1,409 @@
+#include "clar_libgit2.h"
+
+#include "fileops.h"
+#include "git2/reflog.h"
+#include "reflog.h"
+#include "refs.h"
+#include "reflog_helpers.h"
+
+static const char *g_email = "foo@example.com";
+static git_repository *g_repo;
+
+/* Fixture setup and teardown */
+void test_refs_reflog_messages__initialize(void)
+{
+ g_repo = cl_git_sandbox_init("testrepo.git");
+ cl_git_pass(git_repository_set_ident(g_repo, "Foo Bar", g_email));
+}
+
+void test_refs_reflog_messages__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+}
+
+void test_refs_reflog_messages__setting_head_updates_reflog(void)
+{
+ git_object *tag;
+ git_signature *sig;
+ git_annotated_commit *annotated;
+
+ cl_git_pass(git_signature_now(&sig, "me", "foo@example.com"));
+
+ cl_git_pass(git_repository_set_head(g_repo, "refs/heads/haacked")); /* 4 */
+ cl_git_pass(git_repository_set_head(g_repo, "refs/heads/unborn"));
+ cl_git_pass(git_revparse_single(&tag, g_repo, "tags/test"));
+ cl_git_pass(git_repository_set_head_detached(g_repo, git_object_id(tag))); /* 3 */
+ cl_git_pass(git_repository_set_head(g_repo, "refs/heads/haacked")); /* 2 */
+ cl_git_pass(git_repository_set_head(g_repo, "refs/tags/test")); /* 1 */
+ cl_git_pass(git_repository_set_head(g_repo, "refs/remotes/test/master")); /* 0 */
+
+ cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 4,
+ NULL, "refs/heads/haacked",
+ "foo@example.com",
+ "checkout: moving from master to haacked");
+ cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 3,
+ NULL, "tags/test^{commit}",
+ "foo@example.com",
+ "checkout: moving from unborn to e90810b8df3e80c413d903f631643c716887138d");
+ cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 2,
+ "tags/test^{commit}", "refs/heads/haacked",
+ "foo@example.com",
+ "checkout: moving from e90810b8df3e80c413d903f631643c716887138d to haacked");
+ cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 1,
+ "refs/heads/haacked", "tags/test^{commit}",
+ "foo@example.com",
+ "checkout: moving from haacked to test");
+ cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0,
+ "tags/test^{commit}", "refs/remotes/test/master",
+ "foo@example.com",
+ "checkout: moving from e90810b8df3e80c413d903f631643c716887138d to test/master");
+
+ cl_git_pass(git_annotated_commit_from_revspec(&annotated, g_repo, "haacked~0"));
+ cl_git_pass(git_repository_set_head_detached_from_annotated(g_repo, annotated));
+
+ cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0,
+ NULL, "refs/heads/haacked",
+ "foo@example.com",
+ "checkout: moving from be3563ae3f795b2b4353bcce3a527ad0a4f7f644 to haacked~0");
+
+ git_annotated_commit_free(annotated);
+ git_object_free(tag);
+ git_signature_free(sig);
+}
+
+void test_refs_reflog_messages__setting_head_to_same_target_ignores_reflog(void)
+{
+ size_t nentries, nentries_after;
+
+ nentries = reflog_entrycount(g_repo, GIT_HEAD_FILE);
+
+ cl_git_pass(git_repository_set_head(g_repo, "refs/heads/haacked"));
+ cl_git_pass(git_repository_set_head(g_repo, "refs/heads/haacked"));
+
+ nentries_after = reflog_entrycount(g_repo, GIT_HEAD_FILE);
+
+ cl_assert_equal_i(nentries + 1, nentries_after);
+}
+
+void test_refs_reflog_messages__detaching_writes_reflog(void)
+{
+ git_signature *sig;
+ git_oid id;
+ const char *msg;
+
+ cl_git_pass(git_signature_now(&sig, "me", "foo@example.com"));
+
+ msg = "checkout: moving from master to e90810b8df3e80c413d903f631643c716887138d";
+ git_oid_fromstr(&id, "e90810b8df3e80c413d903f631643c716887138d");
+ cl_git_pass(git_repository_set_head_detached(g_repo, &id));
+ cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0,
+ "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
+ "e90810b8df3e80c413d903f631643c716887138d",
+ NULL, msg);
+
+ msg = "checkout: moving from e90810b8df3e80c413d903f631643c716887138d to haacked";
+ cl_git_pass(git_repository_set_head(g_repo, "refs/heads/haacked"));
+ cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0,
+ "e90810b8df3e80c413d903f631643c716887138d",
+ "258f0e2a959a364e40ed6603d5d44fbb24765b10",
+ NULL, msg);
+
+ git_signature_free(sig);
+}
+
+void test_refs_reflog_messages__orphan_branch_does_not_count(void)
+{
+ git_oid id;
+ const char *msg;
+
+ /* Have something known */
+ msg = "checkout: moving from master to e90810b8df3e80c413d903f631643c716887138d";
+ git_oid_fromstr(&id, "e90810b8df3e80c413d903f631643c716887138d");
+ cl_git_pass(git_repository_set_head_detached(g_repo, &id));
+ cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0,
+ "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
+ "e90810b8df3e80c413d903f631643c716887138d",
+ NULL, msg);
+
+ /* Switching to an orphan branch does not write to the reflog */
+ cl_git_pass(git_repository_set_head(g_repo, "refs/heads/orphan"));
+ cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0,
+ "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
+ "e90810b8df3e80c413d903f631643c716887138d",
+ NULL, msg);
+
+ /* And coming back, we set the source to zero */
+ msg = "checkout: moving from orphan to haacked";
+ cl_git_pass(git_repository_set_head(g_repo, "refs/heads/haacked"));
+ cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0,
+ "0000000000000000000000000000000000000000",
+ "258f0e2a959a364e40ed6603d5d44fbb24765b10",
+ NULL, msg);
+}
+
+void test_refs_reflog_messages__branch_birth(void)
+{
+ git_signature *sig;
+ git_oid id;
+ git_tree *tree;
+ git_reference *ref;
+ const char *msg;
+ size_t nentries, nentries_after;
+
+ nentries = reflog_entrycount(g_repo, GIT_HEAD_FILE);
+
+ cl_git_pass(git_signature_now(&sig, "me", "foo@example.com"));
+
+ cl_git_pass(git_repository_head(&ref, g_repo));
+ cl_git_pass(git_reference_peel((git_object **) &tree, ref, GIT_OBJ_TREE));
+
+ cl_git_pass(git_repository_set_head(g_repo, "refs/heads/orphan"));
+
+ nentries_after = reflog_entrycount(g_repo, GIT_HEAD_FILE);
+
+ cl_assert_equal_i(nentries, nentries_after);
+
+ msg = "message 2";
+ cl_git_pass(git_commit_create(&id, g_repo, "HEAD", sig, sig, NULL, msg, tree, 0, NULL));
+
+ cl_assert_equal_i(1, reflog_entrycount(g_repo, "refs/heads/orphan"));
+
+ nentries_after = reflog_entrycount(g_repo, GIT_HEAD_FILE);
+
+ cl_assert_equal_i(nentries + 1, nentries_after);
+
+ git_signature_free(sig);
+ git_tree_free(tree);
+ git_reference_free(ref);
+}
+
+void test_refs_reflog_messages__commit_on_symbolic_ref_updates_head_reflog(void)
+{
+ git_signature *sig;
+ git_oid id;
+ git_tree *tree;
+ git_reference *ref1, *ref2;
+ const char *msg;
+ size_t nentries_head, nentries_master;
+
+ nentries_head = reflog_entrycount(g_repo, GIT_HEAD_FILE);
+
+ cl_git_pass(git_signature_now(&sig, "me", "foo@example.com"));
+
+ cl_git_pass(git_repository_head(&ref1, g_repo));
+ cl_git_pass(git_reference_peel((git_object **) &tree, ref1, GIT_OBJ_TREE));
+
+ nentries_master = reflog_entrycount(g_repo, "refs/heads/master");
+
+ msg = "message 1";
+ cl_git_pass(git_reference_symbolic_create(&ref2, g_repo, "refs/heads/master", "refs/heads/foo", 1, msg));
+
+ cl_assert_equal_i(0, reflog_entrycount(g_repo, "refs/heads/foo"));
+ cl_assert_equal_i(nentries_head, reflog_entrycount(g_repo, GIT_HEAD_FILE));
+ cl_assert_equal_i(nentries_master, reflog_entrycount(g_repo, "refs/heads/master"));
+
+ msg = "message 2";
+ cl_git_pass(git_commit_create(&id, g_repo, "HEAD", sig, sig, NULL, msg, tree, 0, NULL));
+
+ cl_assert_equal_i(1, reflog_entrycount(g_repo, "refs/heads/foo"));
+ cl_assert_equal_i(nentries_head + 1, reflog_entrycount(g_repo, GIT_HEAD_FILE));
+ cl_assert_equal_i(nentries_master, reflog_entrycount(g_repo, "refs/heads/master"));
+
+ git_signature_free(sig);
+ git_reference_free(ref1);
+ git_reference_free(ref2);
+ git_tree_free(tree);
+}
+
+void test_refs_reflog_messages__show_merge_for_merge_commits(void)
+{
+ git_oid b1_oid;
+ git_oid b2_oid;
+ git_oid merge_commit_oid;
+ git_commit *b1_commit;
+ git_commit *b2_commit;
+ git_signature *s;
+ git_commit *parent_commits[2];
+ git_tree *tree;
+
+ cl_git_pass(git_signature_now(&s, "alice", "alice@example.com"));
+
+ cl_git_pass(git_reference_name_to_id(&b1_oid, g_repo, "HEAD"));
+ cl_git_pass(git_reference_name_to_id(&b2_oid, g_repo, "refs/heads/test"));
+
+ cl_git_pass(git_commit_lookup(&b1_commit, g_repo, &b1_oid));
+ cl_git_pass(git_commit_lookup(&b2_commit, g_repo, &b2_oid));
+
+ parent_commits[0] = b1_commit;
+ parent_commits[1] = b2_commit;
+
+ cl_git_pass(git_commit_tree(&tree, b1_commit));
+
+ cl_git_pass(git_commit_create(&merge_commit_oid,
+ g_repo, "HEAD", s, s, NULL,
+ "Merge commit", tree,
+ 2, (const struct git_commit **) parent_commits));
+
+ cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0,
+ NULL,
+ git_oid_tostr_s(&merge_commit_oid),
+ NULL, "commit (merge): Merge commit");
+
+ git_tree_free(tree);
+ git_commit_free(b1_commit);
+ git_commit_free(b2_commit);
+ git_signature_free(s);
+}
+
+void test_refs_reflog_messages__creating_a_direct_reference(void)
+{
+ git_reference *reference;
+ git_oid id;
+ git_reflog *reflog;
+ const git_reflog_entry *entry;
+
+ const char *name = "refs/heads/new-head";
+ const char *message = "You've been logged, mate!";
+
+ cl_git_pass(git_reference_name_to_id(&id, g_repo, "HEAD"));
+
+ cl_git_pass(git_reference_create(&reference, g_repo, name, &id, 0, message));
+
+ cl_git_pass(git_reflog_read(&reflog, g_repo, name));
+ cl_assert_equal_sz(1, git_reflog_entrycount(reflog));
+
+ entry = git_reflog_entry_byindex(reflog, 0);
+ cl_assert(git_oid_streq(&entry->oid_old, GIT_OID_HEX_ZERO) == 0);
+ cl_assert_equal_oid(&id, &entry->oid_cur);
+ cl_assert_equal_s(message, entry->msg);
+
+ git_reflog_free(reflog);
+ git_reference_free(reference);
+}
+
+
+void test_refs_reflog_messages__renaming_ref(void)
+{
+ git_reference *ref, *new_ref;
+
+ cl_git_pass(git_reference_lookup(&ref, g_repo, "refs/heads/master"));
+ cl_git_pass(git_reference_rename(&new_ref, ref, "refs/heads/renamed", false,
+ "message"));
+
+ cl_reflog_check_entry(g_repo, git_reference_name(new_ref), 0,
+ "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
+ "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
+ "foo@example.com", "message");
+
+ git_reference_free(ref);
+ git_reference_free(new_ref);
+}
+
+void test_refs_reflog_messages__updating_a_direct_reference(void)
+{
+ git_reference *ref, *ref_out, *target_ref;
+ git_oid target_id;
+ const char *message = "You've been logged, mate!";
+
+ git_reference_name_to_id(&target_id, g_repo, "refs/heads/haacked");
+ cl_git_pass(git_reference_lookup(&target_ref, g_repo, "refs/heads/haacked"));
+
+ cl_git_pass(git_reference_lookup(&ref, g_repo, "refs/heads/master"));
+
+ cl_git_pass(git_reference_set_target(&ref_out, ref, &target_id, message));
+
+ cl_reflog_check_entry(g_repo, "refs/heads/master", 0,
+ "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
+ "258f0e2a959a364e40ed6603d5d44fbb24765b10",
+ NULL, message);
+
+ git_reference_free(target_ref);
+ git_reference_free(ref);
+ git_reference_free(ref_out);
+}
+
+#define NEW_BRANCH_NAME "new-branch-on-the-block"
+
+void test_refs_reflog_messages__creating_branches_default_messages(void)
+{
+ git_buf buf = GIT_BUF_INIT;
+ git_annotated_commit *annotated;
+ git_object *obj;
+ git_commit *target;
+ git_reference *branch1, *branch2;
+
+ cl_git_pass(git_revparse_single(&obj, g_repo, "e90810b8df3"));
+ cl_git_pass(git_commit_lookup(&target, g_repo, git_object_id(obj)));
+ git_object_free(obj);
+
+ cl_git_pass(git_branch_create(&branch1, g_repo, NEW_BRANCH_NAME, target, false));
+
+ cl_git_pass(git_buf_printf(&buf, "branch: Created from %s", git_oid_tostr_s(git_commit_id(target))));
+ cl_reflog_check_entry(g_repo, "refs/heads/" NEW_BRANCH_NAME, 0,
+ GIT_OID_HEX_ZERO,
+ git_oid_tostr_s(git_commit_id(target)),
+ g_email, git_buf_cstr(&buf));
+
+ cl_git_pass(git_reference_remove(g_repo, "refs/heads/" NEW_BRANCH_NAME));
+
+ cl_git_pass(git_annotated_commit_from_revspec(&annotated, g_repo, "e90810b8df3"));
+ cl_git_pass(git_branch_create_from_annotated(&branch2, g_repo, NEW_BRANCH_NAME, annotated, true));
+
+ cl_reflog_check_entry(g_repo, "refs/heads/" NEW_BRANCH_NAME, 0,
+ GIT_OID_HEX_ZERO,
+ git_oid_tostr_s(git_commit_id(target)),
+ g_email, "branch: Created from e90810b8df3");
+
+ git_annotated_commit_free(annotated);
+ git_buf_free(&buf);
+ git_commit_free(target);
+ git_reference_free(branch1);
+ git_reference_free(branch2);
+}
+
+void test_refs_reflog_messages__moving_branch_default_message(void)
+{
+ git_reference *branch;
+ git_reference *new_branch;
+ git_oid id;
+
+ cl_git_pass(git_reference_lookup(&branch, g_repo, "refs/heads/master"));
+ git_oid_cpy(&id, git_reference_target(branch));
+ cl_git_pass(git_branch_move(&new_branch, branch, "master2", 0));
+
+ cl_reflog_check_entry(g_repo, git_reference_name(new_branch), 0,
+ "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
+ "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
+ g_email,
+ "branch: renamed refs/heads/master to refs/heads/master2");
+
+ git_reference_free(branch);
+ git_reference_free(new_branch);
+}
+
+void test_refs_reflog_messages__detaching_head_default_message(void)
+{
+ git_reference *ref;
+
+ cl_assert_equal_i(false, git_repository_head_detached(g_repo));
+
+ cl_git_pass(git_repository_detach_head(g_repo));
+ cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0,
+ "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
+ "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
+ NULL, "checkout: moving from master to a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
+ cl_assert_equal_i(true, git_repository_head_detached(g_repo));
+
+ /* take the repo back to its original state */
+ cl_git_pass(git_reference_symbolic_create(&ref, g_repo, "HEAD", "refs/heads/master",
+ true, "REATTACH"));
+
+ cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0,
+ "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
+ "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
+ NULL, "REATTACH");
+
+ cl_assert_equal_i(false, git_repository_head_detached(g_repo));
+
+ git_reference_free(ref);
+}
diff --git a/tests/refs/reflog/reflog.c b/tests/refs/reflog/reflog.c
index 2522421..bbcdbf9 100644
--- a/tests/refs/reflog/reflog.c
+++ b/tests/refs/reflog/reflog.c
@@ -4,7 +4,6 @@
#include "git2/reflog.h"
#include "reflog.h"
-static const char *merge_reflog_message = "commit (merge): Merge commit";
static const char *new_ref = "refs/heads/test-reflog";
static const char *current_master_tip = "a65fedf39aefe402d3bb6e24df4d4f5fe4547750";
#define commit_msg "commit: bla bla"
@@ -448,45 +447,3 @@ void test_refs_reflog_reflog__logallrefupdates_nonbare_set_false(void)
assert_no_reflog_update();
}
-
-void test_refs_reflog_reflog__show_merge_for_merge_commits(void)
-{
- git_oid b1_oid;
- git_oid b2_oid;
- git_oid merge_commit_oid;
- git_commit *b1_commit;
- git_commit *b2_commit;
- git_signature *s;
- git_commit *parent_commits[2];
- git_tree *tree;
- git_reflog *log;
- const git_reflog_entry *entry;
-
- cl_git_pass(git_signature_now(&s, "alice", "alice@example.com"));
-
- cl_git_pass(git_reference_name_to_id(&b1_oid, g_repo, "HEAD"));
- cl_git_pass(git_reference_name_to_id(&b2_oid, g_repo, "refs/heads/test"));
-
- cl_git_pass(git_commit_lookup(&b1_commit, g_repo, &b1_oid));
- cl_git_pass(git_commit_lookup(&b2_commit, g_repo, &b2_oid));
-
- parent_commits[0] = b1_commit;
- parent_commits[1] = b2_commit;
-
- cl_git_pass(git_commit_tree(&tree, b1_commit));
-
- cl_git_pass(git_commit_create(&merge_commit_oid,
- g_repo, "HEAD", s, s, NULL,
- "Merge commit", tree,
- 2, (const struct git_commit **) parent_commits));
-
- cl_git_pass(git_reflog_read(&log, g_repo, "HEAD"));
- entry = git_reflog_entry_byindex(log, 0);
- cl_assert_equal_s(merge_reflog_message, git_reflog_entry_message(entry));
-
- git_reflog_free(log);
- git_tree_free(tree);
- git_commit_free(b1_commit);
- git_commit_free(b2_commit);
- git_signature_free(s);
-}
diff --git a/tests/refs/reflog/reflog_helpers.c b/tests/refs/reflog/reflog_helpers.c
new file mode 100644
index 0000000..5e36736
--- /dev/null
+++ b/tests/refs/reflog/reflog_helpers.c
@@ -0,0 +1,118 @@
+#include "clar_libgit2.h"
+
+#include "repository.h"
+#include "reflog.h"
+
+static int reflog_entry_tostr(git_buf *out, const git_reflog_entry *entry)
+{
+ char old_oid[GIT_OID_HEXSZ], new_oid[GIT_OID_HEXSZ];
+
+ assert(out && entry);
+
+ git_oid_tostr((char *)&old_oid, GIT_OID_HEXSZ, git_reflog_entry_id_old(entry));
+ git_oid_tostr((char *)&new_oid, GIT_OID_HEXSZ, git_reflog_entry_id_new(entry));
+
+ return git_buf_printf(out, "%s %s %s %s", old_oid, new_oid, "somesig", git_reflog_entry_message(entry));
+}
+
+size_t reflog_entrycount(git_repository *repo, const char *name)
+{
+ git_reflog *log;
+ size_t ret;
+
+ cl_git_pass(git_reflog_read(&log, repo, name));
+ ret = git_reflog_entrycount(log);
+ git_reflog_free(log);
+
+ return ret;
+}
+
+void cl_reflog_check_entry_(git_repository *repo, const char *reflog, size_t idx,
+ const char *old_spec, const char *new_spec,
+ const char *email, const char *message, const char *file, int line)
+{
+ git_reflog *log;
+ const git_reflog_entry *entry;
+ git_buf result = GIT_BUF_INIT;
+
+ cl_git_pass(git_reflog_read(&log, repo, reflog));
+ entry = git_reflog_entry_byindex(log, idx);
+ if (entry == NULL)
+ clar__fail(file, line, "Reflog has no such entry", NULL, 1);
+
+ if (old_spec) {
+ git_object *obj = NULL;
+ if (git_revparse_single(&obj, repo, old_spec) == GIT_OK) {
+ if (git_oid_cmp(git_object_id(obj), git_reflog_entry_id_old(entry)) != 0) {
+ git_oid__writebuf(&result, "\tOld OID: \"", git_object_id(obj));
+ git_oid__writebuf(&result, "\" != \"", git_reflog_entry_id_old(entry));
+ git_buf_puts(&result, "\"\n");
+ }
+ git_object_free(obj);
+ } else {
+ git_oid *oid = git__calloc(1, sizeof(*oid));
+ git_oid_fromstr(oid, old_spec);
+ if (git_oid_cmp(oid, git_reflog_entry_id_old(entry)) != 0) {
+ git_oid__writebuf(&result, "\tOld OID: \"", oid);
+ git_oid__writebuf(&result, "\" != \"", git_reflog_entry_id_old(entry));
+ git_buf_puts(&result, "\"\n");
+ }
+ git__free(oid);
+ }
+ }
+ if (new_spec) {
+ git_object *obj = NULL;
+ if (git_revparse_single(&obj, repo, new_spec) == GIT_OK) {
+ if (git_oid_cmp(git_object_id(obj), git_reflog_entry_id_new(entry)) != 0) {
+ git_oid__writebuf(&result, "\tNew OID: \"", git_object_id(obj));
+ git_oid__writebuf(&result, "\" != \"", git_reflog_entry_id_new(entry));
+ git_buf_puts(&result, "\"\n");
+ }
+ git_object_free(obj);
+ } else {
+ git_oid *oid = git__calloc(1, sizeof(*oid));
+ git_oid_fromstr(oid, new_spec);
+ if (git_oid_cmp(oid, git_reflog_entry_id_new(entry)) != 0) {
+ git_oid__writebuf(&result, "\tNew OID: \"", oid);
+ git_oid__writebuf(&result, "\" != \"", git_reflog_entry_id_new(entry));
+ git_buf_puts(&result, "\"\n");
+ }
+ git__free(oid);
+ }
+ }
+
+ if (email && strcmp(email, git_reflog_entry_committer(entry)->email) != 0)
+ git_buf_printf(&result, "\tEmail: \"%s\" != \"%s\"\n", email, git_reflog_entry_committer(entry)->email);
+
+ if (message) {
+ const char *entry_msg = git_reflog_entry_message(entry);
+ if (entry_msg == NULL) entry_msg = "";
+
+ if (entry_msg && strcmp(message, entry_msg) != 0)
+ git_buf_printf(&result, "\tMessage: \"%s\" != \"%s\"\n", message, entry_msg);
+ }
+ if (git_buf_len(&result) != 0)
+ clar__fail(file, line, "Reflog entry mismatch", git_buf_cstr(&result), 1);
+
+ git_buf_free(&result);
+ git_reflog_free(log);
+}
+
+void reflog_print(git_repository *repo, const char *reflog_name)
+{
+ git_reflog *reflog;
+ size_t idx;
+ git_buf out = GIT_BUF_INIT;
+
+ git_reflog_read(&reflog, repo, reflog_name);
+
+ for (idx = 0; idx < git_reflog_entrycount(reflog); idx++) {
+ const git_reflog_entry *entry = git_reflog_entry_byindex(reflog, idx);
+ reflog_entry_tostr(&out, entry);
+ git_buf_putc(&out, '\n');
+ }
+
+ fprintf(stderr, "%s", git_buf_cstr(&out));
+ git_buf_free(&out);
+ git_reflog_free(reflog);
+}
diff --git a/tests/refs/reflog/reflog_helpers.h b/tests/refs/reflog/reflog_helpers.h
new file mode 100644
index 0000000..80814ea
--- /dev/null
+++ b/tests/refs/reflog/reflog_helpers.h
@@ -0,0 +1,10 @@
+size_t reflog_entrycount(git_repository *repo, const char *name);
+
+#define cl_reflog_check_entry(repo, reflog, idx, old_spec, new_spec, email, message) \
+ cl_reflog_check_entry_(repo, reflog, idx, old_spec, new_spec, email, message, __FILE__, __LINE__)
+
+void cl_reflog_check_entry_(git_repository *repo, const char *reflog, size_t idx,
+ const char *old_spec, const char *new_spec,
+ const char *email, const char *message, const char *file, int line);
+
+void reflog_print(git_repository *repo, const char *reflog_name);
diff --git a/tests/refs/rename.c b/tests/refs/rename.c
index 6106e6c..3e0be31 100644
--- a/tests/refs/rename.c
+++ b/tests/refs/rename.c
@@ -366,22 +366,3 @@ void test_refs_rename__propagate_eexists(void)
git_reference_free(ref);
}
-
-void test_refs_rename__writes_to_reflog(void)
-{
- git_reference *ref, *new_ref;
- git_reflog *log;
- const git_reflog_entry *entry;
-
- cl_git_pass(git_reference_lookup(&ref, g_repo, ref_master_name));
- cl_git_pass(git_reference_rename(&new_ref, ref, ref_one_name_new, false,
- "message"));
- cl_git_pass(git_reflog_read(&log, g_repo, git_reference_name(new_ref)));
- entry = git_reflog_entry_byindex(log, 0);
- cl_assert_equal_s("message", git_reflog_entry_message(entry));
- cl_assert_equal_s("foo@example.com", git_reflog_entry_committer(entry)->email);
-
- git_reflog_free(log);
- git_reference_free(ref);
- git_reference_free(new_ref);
-}
diff --git a/tests/refs/settargetwithlog.c b/tests/refs/settargetwithlog.c
deleted file mode 100644
index 58fbb5f..0000000
--- a/tests/refs/settargetwithlog.c
+++ /dev/null
@@ -1,51 +0,0 @@
-#include "clar_libgit2.h"
-
-#include "repository.h"
-#include "git2/reflog.h"
-#include "reflog.h"
-#include "ref_helpers.h"
-
-static const char *br2_tip = "a4a7dce85cf63874e984719f4fdd239f5145052f";
-static const char *master_tip = "a65fedf39aefe402d3bb6e24df4d4f5fe4547750";
-static const char *br2_name = "refs/heads/br2";
-
-static git_repository *g_repo;
-
-void test_refs_settargetwithlog__initialize(void)
-{
- g_repo = cl_git_sandbox_init("testrepo.git");
-}
-
-void test_refs_settargetwithlog__cleanup(void)
-{
- cl_git_sandbox_cleanup();
-}
-
-void test_refs_settargetwithlog__updating_a_direct_reference_adds_a_reflog_entry(void)
-{
- git_reference *reference, *reference_out;
- git_oid current_id, target_id;
- git_reflog *reflog;
- const git_reflog_entry *entry;
-
- const char *message = "You've been logged, mate!";
-
- git_oid_fromstr(¤t_id, br2_tip);
- git_oid_fromstr(&target_id, master_tip);
-
- cl_git_pass(git_reference_lookup(&reference, g_repo, br2_name));
-
- cl_git_pass(git_reference_set_target(
- &reference_out, reference, &target_id, message));
-
- cl_git_pass(git_reflog_read(&reflog, g_repo, br2_name));
-
- entry = git_reflog_entry_byindex(reflog, 0);
- cl_assert_equal_oid(¤t_id, &entry->oid_old);
- cl_assert_equal_oid(&target_id, &entry->oid_cur);
- cl_assert_equal_s(message, entry->msg);
-
- git_reflog_free(reflog);
- git_reference_free(reference_out);
- git_reference_free(reference);
-}
diff --git a/tests/repo/head.c b/tests/repo/head.c
index d021160..ed3b3dc 100644
--- a/tests/repo/head.c
+++ b/tests/repo/head.c
@@ -18,40 +18,6 @@ void test_repo_head__cleanup(void)
cl_git_sandbox_cleanup();
}
-static void check_last_reflog_entry(const char *email, const char *message)
-{
- git_reflog *log;
- const git_reflog_entry *entry;
-
- cl_git_pass(git_reflog_read(&log, repo, GIT_HEAD_FILE));
- cl_assert(git_reflog_entrycount(log) > 0);
- entry = git_reflog_entry_byindex(log, 0);
- if (email)
- cl_assert_equal_s(email, git_reflog_entry_committer(entry)->email);
- if (message)
- cl_assert_equal_s(message, git_reflog_entry_message(entry));
- git_reflog_free(log);
-}
-
-void test_repo_head__head_detached(void)
-{
- git_reference *ref;
-
- cl_assert_equal_i(false, git_repository_head_detached(repo));
-
- cl_git_pass(git_repository_detach_head(repo));
- check_last_reflog_entry(g_email, "checkout: moving from master to a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
- cl_assert_equal_i(true, git_repository_head_detached(repo));
-
- /* take the repo back to it's original state */
- cl_git_pass(git_reference_symbolic_create(&ref, repo, "HEAD", "refs/heads/master",
- true, "REATTACH"));
- git_reference_free(ref);
-
- check_last_reflog_entry(g_email, "REATTACH");
- cl_assert_equal_i(false, git_repository_head_detached(repo));
-}
-
void test_repo_head__unborn_head(void)
{
git_reference *ref;
@@ -214,252 +180,3 @@ void test_repo_head__can_tell_if_an_unborn_head_is_detached(void)
cl_assert_equal_i(false, git_repository_head_detached(repo));
}
-
-static void test_reflog(git_repository *repo, size_t idx,
- const char *old_spec, const char *new_spec,
- const char *email, const char *message)
-{
- git_reflog *log;
- const git_reflog_entry *entry;
-
- cl_git_pass(git_reflog_read(&log, repo, "HEAD"));
- entry = git_reflog_entry_byindex(log, idx);
-
- if (old_spec) {
- git_object *obj;
- cl_git_pass(git_revparse_single(&obj, repo, old_spec));
- cl_assert_equal_oid(git_object_id(obj), git_reflog_entry_id_old(entry));
- git_object_free(obj);
- }
- if (new_spec) {
- git_object *obj;
- cl_git_pass(git_revparse_single(&obj, repo, new_spec));
- cl_assert_equal_oid(git_object_id(obj), git_reflog_entry_id_new(entry));
- git_object_free(obj);
- }
-
- if (email) {
- cl_assert_equal_s(email, git_reflog_entry_committer(entry)->email);
- }
- if (message) {
- cl_assert_equal_s(message, git_reflog_entry_message(entry));
- }
-
- git_reflog_free(log);
-}
-
-void test_repo_head__setting_head_updates_reflog(void)
-{
- git_object *tag;
- git_signature *sig;
- git_annotated_commit *annotated;
-
- cl_git_pass(git_signature_now(&sig, "me", "foo@example.com"));
-
- cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked"));
- cl_git_pass(git_repository_set_head(repo, "refs/heads/unborn"));
- cl_git_pass(git_revparse_single(&tag, repo, "tags/test"));
- cl_git_pass(git_repository_set_head_detached(repo, git_object_id(tag)));
- cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked"));
- cl_git_pass(git_repository_set_head(repo, "refs/tags/test"));
- cl_git_pass(git_repository_set_head(repo, "refs/remotes/test/master"));
-
- test_reflog(repo, 4, NULL, "refs/heads/haacked", "foo@example.com", "checkout: moving from master to haacked");
- test_reflog(repo, 3, NULL, "tags/test^{commit}", "foo@example.com", "checkout: moving from unborn to e90810b8df3e80c413d903f631643c716887138d");
- test_reflog(repo, 2, "tags/test^{commit}", "refs/heads/haacked", "foo@example.com", "checkout: moving from e90810b8df3e80c413d903f631643c716887138d to haacked");
- test_reflog(repo, 1, "refs/heads/haacked", "tags/test^{commit}", "foo@example.com", "checkout: moving from haacked to test");
- test_reflog(repo, 0, "tags/test^{commit}", "refs/remotes/test/master", "foo@example.com", "checkout: moving from e90810b8df3e80c413d903f631643c716887138d to test/master");
-
- cl_git_pass(git_annotated_commit_from_revspec(&annotated, repo, "haacked~0"));
- cl_git_pass(git_repository_set_head_detached_from_annotated(repo, annotated));
-
- test_reflog(repo, 0, NULL, "refs/heads/haacked", "foo@example.com", "checkout: moving from be3563ae3f795b2b4353bcce3a527ad0a4f7f644 to haacked~0");
-
- git_annotated_commit_free(annotated);
- git_object_free(tag);
- git_signature_free(sig);
-}
-
-static void assert_head_reflog(git_repository *repo, size_t idx,
- const char *old_id, const char *new_id, const char *message)
-{
- git_reflog *log;
- const git_reflog_entry *entry;
- char id_str[GIT_OID_HEXSZ + 1] = {0};
-
- cl_git_pass(git_reflog_read(&log, repo, GIT_HEAD_FILE));
- entry = git_reflog_entry_byindex(log, idx);
-
- git_oid_fmt(id_str, git_reflog_entry_id_old(entry));
- cl_assert_equal_s(old_id, id_str);
-
- git_oid_fmt(id_str, git_reflog_entry_id_new(entry));
- cl_assert_equal_s(new_id, id_str);
-
- cl_assert_equal_s(message, git_reflog_entry_message(entry));
-
- git_reflog_free(log);
-}
-
-void test_repo_head__detaching_writes_reflog(void)
-{
- git_signature *sig;
- git_oid id;
- const char *msg;
-
- cl_git_pass(git_signature_now(&sig, "me", "foo@example.com"));
-
- msg = "checkout: moving from master to e90810b8df3e80c413d903f631643c716887138d";
- git_oid_fromstr(&id, "e90810b8df3e80c413d903f631643c716887138d");
- cl_git_pass(git_repository_set_head_detached(repo, &id));
- assert_head_reflog(repo, 0, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
- "e90810b8df3e80c413d903f631643c716887138d", msg);
-
- msg = "checkout: moving from e90810b8df3e80c413d903f631643c716887138d to haacked";
- cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked"));
- assert_head_reflog(repo, 0, "e90810b8df3e80c413d903f631643c716887138d",
- "258f0e2a959a364e40ed6603d5d44fbb24765b10", msg);
-
- git_signature_free(sig);
-}
-
-void test_repo_head__orphan_branch_does_not_count(void)
-{
- git_oid id;
- const char *msg;
-
- /* Have something known */
- msg = "checkout: moving from master to e90810b8df3e80c413d903f631643c716887138d";
- git_oid_fromstr(&id, "e90810b8df3e80c413d903f631643c716887138d");
- cl_git_pass(git_repository_set_head_detached(repo, &id));
- assert_head_reflog(repo, 0, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
- "e90810b8df3e80c413d903f631643c716887138d", msg);
-
- /* Switching to an orphan branch does not write tot he reflog */
- cl_git_pass(git_repository_set_head(repo, "refs/heads/orphan"));
- assert_head_reflog(repo, 0, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
- "e90810b8df3e80c413d903f631643c716887138d", msg);
-
- /* And coming back, we set the source to zero */
- msg = "checkout: moving from orphan to haacked";
- cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked"));
- assert_head_reflog(repo, 0, "0000000000000000000000000000000000000000",
- "258f0e2a959a364e40ed6603d5d44fbb24765b10", msg);
-}
-
-void test_repo_head__set_to_current_target(void)
-{
- git_reflog *log;
- size_t nentries, nentries_after;
-
- cl_git_pass(git_reflog_read(&log, repo, GIT_HEAD_FILE));
- nentries = git_reflog_entrycount(log);
- git_reflog_free(log);
-
- cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked"));
- cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked"));
-
- cl_git_pass(git_reflog_read(&log, repo, GIT_HEAD_FILE));
- nentries_after = git_reflog_entrycount(log);
- git_reflog_free(log);
-
- cl_assert_equal_i(nentries + 1, nentries_after);
-}
-
-void test_repo_head__branch_birth(void)
-{
- git_signature *sig;
- git_oid id;
- git_tree *tree;
- git_reference *ref;
- const char *msg;
- git_reflog *log;
- size_t nentries, nentries_after;
-
- cl_git_pass(git_reflog_read(&log, repo, GIT_HEAD_FILE));
- nentries = git_reflog_entrycount(log);
- git_reflog_free(log);
-
- cl_git_pass(git_signature_now(&sig, "me", "foo@example.com"));
-
- cl_git_pass(git_repository_head(&ref, repo));
- cl_git_pass(git_reference_peel((git_object **) &tree, ref, GIT_OBJ_TREE));
- git_reference_free(ref);
-
- cl_git_pass(git_repository_set_head(repo, "refs/heads/orphan"));
-
- cl_git_pass(git_reflog_read(&log, repo, GIT_HEAD_FILE));
- nentries_after = git_reflog_entrycount(log);
- git_reflog_free(log);
-
- cl_assert_equal_i(nentries, nentries_after);
-
- msg = "message 2";
- cl_git_pass(git_commit_create(&id, repo, "HEAD", sig, sig, NULL, msg, tree, 0, NULL));
-
- git_tree_free(tree);
-
- cl_git_pass(git_reflog_read(&log, repo, "refs/heads/orphan"));
- cl_assert_equal_i(1, git_reflog_entrycount(log));
- git_reflog_free(log);
-
- cl_git_pass(git_reflog_read(&log, repo, GIT_HEAD_FILE));
- nentries_after = git_reflog_entrycount(log);
- git_reflog_free(log);
-
- cl_assert_equal_i(nentries + 1, nentries_after);
-
- git_signature_free(sig);
-
-}
-
-static size_t entrycount(git_repository *repo, const char *name)
-{
- git_reflog *log;
- size_t ret;
-
- cl_git_pass(git_reflog_read(&log, repo, name));
- ret = git_reflog_entrycount(log);
- git_reflog_free(log);
-
- return ret;
-}
-
-void test_repo_head__symref_chain(void)
-{
- git_signature *sig;
- git_oid id;
- git_tree *tree;
- git_reference *ref;
- const char *msg;
- size_t nentries, nentries_master;
-
- nentries = entrycount(repo, GIT_HEAD_FILE);
-
- cl_git_pass(git_signature_now(&sig, "me", "foo@example.com"));
-
- cl_git_pass(git_repository_head(&ref, repo));
- cl_git_pass(git_reference_peel((git_object **) &tree, ref, GIT_OBJ_TREE));
- git_reference_free(ref);
-
- nentries_master = entrycount(repo, "refs/heads/master");
-
- msg = "message 1";
- cl_git_pass(git_reference_symbolic_create(&ref, repo, "refs/heads/master", "refs/heads/foo", 1, msg));
- git_reference_free(ref);
-
- cl_assert_equal_i(0, entrycount(repo, "refs/heads/foo"));
- cl_assert_equal_i(nentries, entrycount(repo, GIT_HEAD_FILE));
- cl_assert_equal_i(nentries_master, entrycount(repo, "refs/heads/master"));
-
- msg = "message 2";
- cl_git_pass(git_commit_create(&id, repo, "HEAD", sig, sig, NULL, msg, tree, 0, NULL));
- git_tree_free(tree);
-
- cl_assert_equal_i(1, entrycount(repo, "refs/heads/foo"));
- cl_assert_equal_i(nentries +1, entrycount(repo, GIT_HEAD_FILE));
- cl_assert_equal_i(nentries_master, entrycount(repo, "refs/heads/master"));
-
- git_signature_free(sig);
-
-}