Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 09d9968

Browse files
author
Edward Thomson
committed
rebase: additional tests for completing a rebase
1 parent 2a39818 commit 09d9968

File tree

2 files changed

+83
-5
lines changed

2 files changed

+83
-5
lines changed

tests/rebase/abort.c

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,41 @@ void test_rebase_abort__merge(void)
8686
git_rebase_free(rebase);
8787
}
8888

89+
void test_rebase_abort__merge_by_id(void)
90+
{
91+
git_rebase *rebase;
92+
git_oid branch_id, onto_id;
93+
git_annotated_commit *branch_head, *onto_head;
94+
95+
cl_git_pass(git_oid_fromstr(&branch_id, "b146bd7608eac53d9bf9e1a6963543588b555c64"));
96+
cl_git_pass(git_oid_fromstr(&onto_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00"));
97+
98+
cl_git_pass(git_annotated_commit_lookup(&branch_head, repo, &branch_id));
99+
cl_git_pass(git_annotated_commit_lookup(&onto_head, repo, &onto_id));
100+
101+
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, NULL, onto_head, NULL));
102+
cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
103+
104+
test_abort(branch_head, onto_head);
105+
106+
git_annotated_commit_free(branch_head);
107+
git_annotated_commit_free(onto_head);
108+
109+
git_rebase_free(rebase);
110+
}
111+
89112
void test_rebase_abort__detached_head(void)
90113
{
91114
git_rebase *rebase;
92-
git_oid branch_id;
93-
git_reference *onto_ref;
115+
git_oid branch_id, onto_id;
94116
git_signature *signature;
95117
git_annotated_commit *branch_head, *onto_head;
96118

97119
git_oid_fromstr(&branch_id, "b146bd7608eac53d9bf9e1a6963543588b555c64");
98-
cl_git_pass(git_reference_lookup(&onto_ref, repo, "refs/heads/master"));
120+
git_oid_fromstr(&onto_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00");
99121

100122
cl_git_pass(git_annotated_commit_lookup(&branch_head, repo, &branch_id));
101-
cl_git_pass(git_annotated_commit_from_ref(&onto_head, repo, onto_ref));
123+
cl_git_pass(git_annotated_commit_lookup(&onto_head, repo, &onto_id));
102124

103125
cl_git_pass(git_signature_new(&signature, "Rebaser", "[email protected]", 1404157834, -400));
104126

@@ -112,7 +134,6 @@ void test_rebase_abort__detached_head(void)
112134
git_annotated_commit_free(branch_head);
113135
git_annotated_commit_free(onto_head);
114136

115-
git_reference_free(onto_ref);
116137
git_rebase_free(rebase);
117138
}
118139

tests/rebase/merge.c

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,63 @@ void test_rebase_merge__commit(void)
252252
git_rebase_free(rebase);
253253
}
254254

255+
void test_rebase_merge__commit_with_id(void)
256+
{
257+
git_rebase *rebase;
258+
git_oid branch_id, upstream_id;
259+
git_annotated_commit *branch_head, *upstream_head;
260+
git_rebase_operation *rebase_operation;
261+
git_oid commit_id, tree_id, parent_id;
262+
git_signature *author;
263+
git_commit *commit;
264+
git_reflog *reflog;
265+
const git_reflog_entry *reflog_entry;
266+
267+
cl_git_pass(git_oid_fromstr(&branch_id, "b146bd7608eac53d9bf9e1a6963543588b555c64"));
268+
cl_git_pass(git_oid_fromstr(&upstream_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00"));
269+
270+
cl_git_pass(git_annotated_commit_lookup(&branch_head, repo, &branch_id));
271+
cl_git_pass(git_annotated_commit_lookup(&upstream_head, repo, &upstream_id));
272+
273+
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
274+
275+
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
276+
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
277+
NULL, NULL));
278+
279+
cl_git_pass(git_commit_lookup(&commit, repo, &commit_id));
280+
281+
git_oid_fromstr(&parent_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00");
282+
cl_assert_equal_i(1, git_commit_parentcount(commit));
283+
cl_assert_equal_oid(&parent_id, git_commit_parent_id(commit, 0));
284+
285+
git_oid_fromstr(&tree_id, "4461379789c777d2a6c1f2ee0e9d6c86731b9992");
286+
cl_assert_equal_oid(&tree_id, git_commit_tree_id(commit));
287+
288+
cl_assert_equal_s(NULL, git_commit_message_encoding(commit));
289+
cl_assert_equal_s("Modification 1 to beef\n", git_commit_message(commit));
290+
291+
cl_git_pass(git_signature_new(&author,
292+
"Edward Thomson", "[email protected]", 1405621769, 0-(4*60)));
293+
cl_assert(git_signature__equal(author, git_commit_author(commit)));
294+
295+
cl_assert(git_signature__equal(signature, git_commit_committer(commit)));
296+
297+
/* Make sure the reflogs are updated appropriately */
298+
cl_git_pass(git_reflog_read(&reflog, repo, "HEAD"));
299+
cl_assert(reflog_entry = git_reflog_entry_byindex(reflog, 0));
300+
cl_assert_equal_oid(&parent_id, git_reflog_entry_id_old(reflog_entry));
301+
cl_assert_equal_oid(&commit_id, git_reflog_entry_id_new(reflog_entry));
302+
cl_assert_equal_s("rebase: Modification 1 to beef", git_reflog_entry_message(reflog_entry));
303+
304+
git_reflog_free(reflog);
305+
git_signature_free(author);
306+
git_commit_free(commit);
307+
git_annotated_commit_free(branch_head);
308+
git_annotated_commit_free(upstream_head);
309+
git_rebase_free(rebase);
310+
}
311+
255312
void test_rebase_merge__blocked_when_dirty(void)
256313
{
257314
git_rebase *rebase;

0 commit comments

Comments
 (0)