|
1 | 1 | #include "clar_libgit2.h" |
| 2 | +#include "git2/checkout.h" |
2 | 3 | #include "git2/rebase.h" |
3 | 4 | #include "posix.h" |
4 | 5 | #include "signature.h" |
@@ -475,6 +476,58 @@ void test_rebase_merge__finish(void) |
475 | 476 | git_rebase_free(rebase); |
476 | 477 | } |
477 | 478 |
|
| 479 | +void test_rebase_merge__detached_finish(void) |
| 480 | +{ |
| 481 | + git_rebase *rebase; |
| 482 | + git_reference *branch_ref, *upstream_ref, *head_ref; |
| 483 | + git_annotated_commit *branch_head, *upstream_head; |
| 484 | + git_rebase_operation *rebase_operation; |
| 485 | + git_oid commit_id; |
| 486 | + git_reflog *reflog; |
| 487 | + const git_reflog_entry *reflog_entry; |
| 488 | + git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; |
| 489 | + int error; |
| 490 | + |
| 491 | + cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/gravy")); |
| 492 | + cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/veal")); |
| 493 | + |
| 494 | + cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref)); |
| 495 | + cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref)); |
| 496 | + |
| 497 | + cl_git_pass(git_repository_set_head_detached_from_annotated(repo, branch_head)); |
| 498 | + opts.checkout_strategy = GIT_CHECKOUT_FORCE; |
| 499 | + git_checkout_head(repo, &opts); |
| 500 | + |
| 501 | + cl_git_pass(git_rebase_init(&rebase, repo, NULL, upstream_head, NULL, NULL)); |
| 502 | + |
| 503 | + cl_git_pass(git_rebase_next(&rebase_operation, rebase)); |
| 504 | + cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature, |
| 505 | + NULL, NULL)); |
| 506 | + |
| 507 | + cl_git_fail(error = git_rebase_next(&rebase_operation, rebase)); |
| 508 | + cl_assert_equal_i(GIT_ITEROVER, error); |
| 509 | + |
| 510 | + cl_git_pass(git_rebase_finish(rebase, signature)); |
| 511 | + |
| 512 | + cl_assert_equal_i(GIT_REPOSITORY_STATE_NONE, git_repository_state(repo)); |
| 513 | + |
| 514 | + cl_git_pass(git_reference_lookup(&head_ref, repo, "HEAD")); |
| 515 | + cl_assert_equal_i(GIT_REF_OID, git_reference_type(head_ref)); |
| 516 | + |
| 517 | + /* Make sure the reflogs are updated appropriately */ |
| 518 | + cl_git_pass(git_reflog_read(&reflog, repo, "HEAD")); |
| 519 | + cl_assert(reflog_entry = git_reflog_entry_byindex(reflog, 0)); |
| 520 | + cl_assert_equal_oid(git_annotated_commit_id(upstream_head), git_reflog_entry_id_old(reflog_entry)); |
| 521 | + cl_assert_equal_oid(&commit_id, git_reflog_entry_id_new(reflog_entry)); |
| 522 | + |
| 523 | + git_reflog_free(reflog); |
| 524 | + git_annotated_commit_free(branch_head); |
| 525 | + git_annotated_commit_free(upstream_head); |
| 526 | + git_reference_free(branch_ref); |
| 527 | + git_reference_free(upstream_ref); |
| 528 | + git_rebase_free(rebase); |
| 529 | +} |
| 530 | + |
478 | 531 | void test_rebase_merge__finish_with_ids(void) |
479 | 532 | { |
480 | 533 | git_rebase *rebase; |
|
0 commit comments