summaryrefslogtreecommitdiff
path: root/tests/merge/merge_helpers.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/merge/merge_helpers.c')
-rw-r--r--tests/merge/merge_helpers.c43
1 files changed, 36 insertions, 7 deletions
diff --git a/tests/merge/merge_helpers.c b/tests/merge/merge_helpers.c
index 43619be0d..154985f11 100644
--- a/tests/merge/merge_helpers.c
+++ b/tests/merge/merge_helpers.c
@@ -10,7 +10,7 @@
int merge_trees_from_branches(
git_index **index, git_repository *repo,
const char *ours_name, const char *theirs_name,
- git_merge_tree_opts *opts)
+ git_merge_options *opts)
{
git_commit *our_commit, *their_commit, *ancestor_commit = NULL;
git_tree *our_tree, *their_tree, *ancestor_tree = NULL;
@@ -52,21 +52,50 @@ int merge_trees_from_branches(
return 0;
}
-int merge_branches(git_merge_result **result, git_repository *repo, const char *ours_branch, const char *theirs_branch, git_merge_opts *opts)
+int merge_commits_from_branches(
+ git_index **index, git_repository *repo,
+ const char *ours_name, const char *theirs_name,
+ git_merge_options *opts)
+{
+ git_commit *our_commit, *their_commit;
+ git_oid our_oid, their_oid;
+ git_buf branch_buf = GIT_BUF_INIT;
+
+ git_buf_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, ours_name);
+ cl_git_pass(git_reference_name_to_id(&our_oid, repo, branch_buf.ptr));
+ cl_git_pass(git_commit_lookup(&our_commit, repo, &our_oid));
+
+ git_buf_clear(&branch_buf);
+ git_buf_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, theirs_name);
+ cl_git_pass(git_reference_name_to_id(&their_oid, repo, branch_buf.ptr));
+ cl_git_pass(git_commit_lookup(&their_commit, repo, &their_oid));
+
+ cl_git_pass(git_merge_commits(index, repo, our_commit, their_commit, opts));
+
+ git_buf_free(&branch_buf);
+ git_commit_free(our_commit);
+ git_commit_free(their_commit);
+
+ return 0;
+}
+
+int merge_branches(git_repository *repo,
+ const char *ours_branch, const char *theirs_branch,
+ git_merge_options *merge_opts, git_checkout_options *checkout_opts)
{
git_reference *head_ref, *theirs_ref;
git_merge_head *theirs_head;
- git_checkout_opts head_checkout_opts = GIT_CHECKOUT_OPTS_INIT;
+ git_checkout_options head_checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
head_checkout_opts.checkout_strategy = GIT_CHECKOUT_FORCE;
- cl_git_pass(git_reference_symbolic_create(&head_ref, repo, "HEAD", ours_branch, 1));
+ cl_git_pass(git_reference_symbolic_create(&head_ref, repo, "HEAD", ours_branch, 1, NULL, NULL));
cl_git_pass(git_checkout_head(repo, &head_checkout_opts));
cl_git_pass(git_reference_lookup(&theirs_ref, repo, theirs_branch));
cl_git_pass(git_merge_head_from_ref(&theirs_head, repo, theirs_ref));
- cl_git_pass(git_merge(result, repo, (const git_merge_head **)&theirs_head, 1, opts));
+ cl_git_pass(git_merge(repo, (const git_merge_head **)&theirs_head, 1, merge_opts, checkout_opts));
git_reference_free(head_ref);
git_reference_free(theirs_ref);
@@ -85,7 +114,7 @@ void merge__dump_index_entries(git_vector *index_entries)
index_entry = index_entries->contents[i];
printf("%o ", index_entry->mode);
- printf("%s ", git_oid_allocfmt(&index_entry->oid));
+ printf("%s ", git_oid_allocfmt(&index_entry->id));
printf("%d ", git_index_entry_stage(index_entry));
printf("%s ", index_entry->path);
printf("\n");
@@ -139,7 +168,7 @@ static int index_entry_eq_merge_index_entry(const struct merge_index_entry *expe
test_oid = 0;
if (actual->mode != expected->mode ||
- (test_oid && git_oid_cmp(&actual->oid, &expected_oid) != 0) ||
+ (test_oid && git_oid_cmp(&actual->id, &expected_oid) != 0) ||
git_index_entry_stage(actual) != expected->stage)
return 0;