Commit 320f53cd6c95cdf19f2c157b50561fdd48193fe7

Edward Thomson 2016-04-21T17:03:21

rebase: test abort immediately after init Instead of `open`ing a rebase and `abort`ing that, test that we can `abort` a rebase that has just begun with `init`.

diff --git a/tests/rebase/abort.c b/tests/rebase/abort.c
index 4cf14dd..7052952 100644
--- a/tests/rebase/abort.c
+++ b/tests/rebase/abort.c
@@ -19,17 +19,15 @@ void test_rebase_abort__cleanup(void)
 	cl_git_sandbox_cleanup();
 }
 
-static void test_abort(git_annotated_commit *branch, git_annotated_commit *onto)
+static void ensure_aborted(
+	git_annotated_commit *branch,
+	git_annotated_commit *onto)
 {
-	git_rebase *rebase;
 	git_reference *head_ref, *branch_ref = NULL;
 	git_status_list *statuslist;
 	git_reflog *reflog;
 	const git_reflog_entry *reflog_entry;
 
-	cl_git_pass(git_rebase_open(&rebase, repo, NULL));
-	cl_git_pass(git_rebase_abort(rebase));
-
 	cl_assert_equal_i(GIT_REPOSITORY_STATE_NONE, git_repository_state(repo));
 
 	/* Make sure the refs are updated appropriately */
@@ -58,6 +56,18 @@ static void test_abort(git_annotated_commit *branch, git_annotated_commit *onto)
 	git_reflog_free(reflog);
 	git_reference_free(head_ref);
 	git_reference_free(branch_ref);
+}
+
+static void test_abort(
+	git_annotated_commit *branch, git_annotated_commit *onto)
+{
+	git_rebase *rebase;
+
+	cl_git_pass(git_rebase_open(&rebase, repo, NULL));
+	cl_git_pass(git_rebase_abort(rebase));
+
+	ensure_aborted(branch, onto);
+
 	git_rebase_free(rebase);
 }
 
@@ -86,6 +96,32 @@ void test_rebase_abort__merge(void)
 	git_rebase_free(rebase);
 }
 
+void test_rebase_abort__merge_immediately_after_init(void)
+{
+	git_rebase *rebase;
+	git_reference *branch_ref, *onto_ref;
+	git_annotated_commit *branch_head, *onto_head;
+
+	cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/beef"));
+	cl_git_pass(git_reference_lookup(&onto_ref, repo, "refs/heads/master"));
+
+	cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
+	cl_git_pass(git_annotated_commit_from_ref(&onto_head, repo, onto_ref));
+
+	cl_git_pass(git_rebase_init(&rebase, repo, branch_head, NULL, onto_head, NULL));
+	cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
+
+	cl_git_pass(git_rebase_abort(rebase));
+	ensure_aborted(branch_head, onto_head);
+
+	git_annotated_commit_free(branch_head);
+	git_annotated_commit_free(onto_head);
+
+	git_reference_free(branch_ref);
+	git_reference_free(onto_ref);
+	git_rebase_free(rebase);
+}
+
 void test_rebase_abort__merge_by_id(void)
 {
 	git_rebase *rebase;
@@ -109,6 +145,30 @@ void test_rebase_abort__merge_by_id(void)
 	git_rebase_free(rebase);
 }
 
+void test_rebase_abort__merge_by_id_immediately_after_init(void)
+{
+	git_rebase *rebase;
+	git_oid branch_id, onto_id;
+	git_annotated_commit *branch_head, *onto_head;
+
+	cl_git_pass(git_oid_fromstr(&branch_id, "b146bd7608eac53d9bf9e1a6963543588b555c64"));
+	cl_git_pass(git_oid_fromstr(&onto_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00"));
+
+	cl_git_pass(git_annotated_commit_lookup(&branch_head, repo, &branch_id));
+	cl_git_pass(git_annotated_commit_lookup(&onto_head, repo, &onto_id));
+
+	cl_git_pass(git_rebase_init(&rebase, repo, branch_head, NULL, onto_head, NULL));
+	cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
+
+	cl_git_pass(git_rebase_abort(rebase));
+	ensure_aborted(branch_head, onto_head);
+
+	git_annotated_commit_free(branch_head);
+	git_annotated_commit_free(onto_head);
+
+	git_rebase_free(rebase);
+}
+
 void test_rebase_abort__detached_head(void)
 {
 	git_rebase *rebase;