Skip to content

Commit 320f53c

Browse files
author
Edward Thomson
committed
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`.
1 parent 1dc4491 commit 320f53c

File tree

1 file changed

+65
-5
lines changed

1 file changed

+65
-5
lines changed

tests/rebase/abort.c

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,15 @@ void test_rebase_abort__cleanup(void)
1919
cl_git_sandbox_cleanup();
2020
}
2121

22-
static void test_abort(git_annotated_commit *branch, git_annotated_commit *onto)
22+
static void ensure_aborted(
23+
git_annotated_commit *branch,
24+
git_annotated_commit *onto)
2325
{
24-
git_rebase *rebase;
2526
git_reference *head_ref, *branch_ref = NULL;
2627
git_status_list *statuslist;
2728
git_reflog *reflog;
2829
const git_reflog_entry *reflog_entry;
2930

30-
cl_git_pass(git_rebase_open(&rebase, repo, NULL));
31-
cl_git_pass(git_rebase_abort(rebase));
32-
3331
cl_assert_equal_i(GIT_REPOSITORY_STATE_NONE, git_repository_state(repo));
3432

3533
/* Make sure the refs are updated appropriately */
@@ -58,6 +56,18 @@ static void test_abort(git_annotated_commit *branch, git_annotated_commit *onto)
5856
git_reflog_free(reflog);
5957
git_reference_free(head_ref);
6058
git_reference_free(branch_ref);
59+
}
60+
61+
static void test_abort(
62+
git_annotated_commit *branch, git_annotated_commit *onto)
63+
{
64+
git_rebase *rebase;
65+
66+
cl_git_pass(git_rebase_open(&rebase, repo, NULL));
67+
cl_git_pass(git_rebase_abort(rebase));
68+
69+
ensure_aborted(branch, onto);
70+
6171
git_rebase_free(rebase);
6272
}
6373

@@ -86,6 +96,32 @@ void test_rebase_abort__merge(void)
8696
git_rebase_free(rebase);
8797
}
8898

99+
void test_rebase_abort__merge_immediately_after_init(void)
100+
{
101+
git_rebase *rebase;
102+
git_reference *branch_ref, *onto_ref;
103+
git_annotated_commit *branch_head, *onto_head;
104+
105+
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/beef"));
106+
cl_git_pass(git_reference_lookup(&onto_ref, repo, "refs/heads/master"));
107+
108+
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
109+
cl_git_pass(git_annotated_commit_from_ref(&onto_head, repo, onto_ref));
110+
111+
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, NULL, onto_head, NULL));
112+
cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
113+
114+
cl_git_pass(git_rebase_abort(rebase));
115+
ensure_aborted(branch_head, onto_head);
116+
117+
git_annotated_commit_free(branch_head);
118+
git_annotated_commit_free(onto_head);
119+
120+
git_reference_free(branch_ref);
121+
git_reference_free(onto_ref);
122+
git_rebase_free(rebase);
123+
}
124+
89125
void test_rebase_abort__merge_by_id(void)
90126
{
91127
git_rebase *rebase;
@@ -109,6 +145,30 @@ void test_rebase_abort__merge_by_id(void)
109145
git_rebase_free(rebase);
110146
}
111147

148+
void test_rebase_abort__merge_by_id_immediately_after_init(void)
149+
{
150+
git_rebase *rebase;
151+
git_oid branch_id, onto_id;
152+
git_annotated_commit *branch_head, *onto_head;
153+
154+
cl_git_pass(git_oid_fromstr(&branch_id, "b146bd7608eac53d9bf9e1a6963543588b555c64"));
155+
cl_git_pass(git_oid_fromstr(&onto_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00"));
156+
157+
cl_git_pass(git_annotated_commit_lookup(&branch_head, repo, &branch_id));
158+
cl_git_pass(git_annotated_commit_lookup(&onto_head, repo, &onto_id));
159+
160+
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, NULL, onto_head, NULL));
161+
cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
162+
163+
cl_git_pass(git_rebase_abort(rebase));
164+
ensure_aborted(branch_head, onto_head);
165+
166+
git_annotated_commit_free(branch_head);
167+
git_annotated_commit_free(onto_head);
168+
169+
git_rebase_free(rebase);
170+
}
171+
112172
void test_rebase_abort__detached_head(void)
113173
{
114174
git_rebase *rebase;

0 commit comments

Comments
 (0)