我正在尝试使用Libgit2将另一个分支合并到我自己的分支中。它运行时没有错误代码,但是当我实际查看文件时,合并似乎没有发生。这是我的代码:
git_commit * commit = NULL; /* the result */
git_oid oid_parent_commit; /* the SHA1 for last commit */
int error = git_reference_name_to_id(&oid_parent_commit, repo, branchToReferenceMap.value("master"));
if (error < 0)
errorMessage(error);
git_commit *lastCommit;
if (error == 0)
{
/* get the actual commit structure */
error = git_commit_lookup(&commit, repo, &oid_parent_commit);
if (error == 0)
{
lastCommit = getLastCommit(repo, "master");
}
}
else
return;
git_annotated_commit *heads;
git_commit *lastCommit = getLastCommit(repo, "master");
const git_oid *id = git_commit_id(lastCommit);
int error = git_annotated_commit_lookup(&heads, repo, id);
if (error < 0)
errorMessage(error);
git_merge_options opts;
git_checkout_options checkOpts;
error = git_merge_init_options(&opts, GIT_MERGE_FILE_OPTIONS_VERSION);
if (error < 0)
errorMessage(error);
error = git_checkout_init_options(&checkOpts, GIT_CHECKOUT_OPTIONS_VERSION);
if (error < 0)
errorMessage(error);
error = git_merge(repo, const_cast<const git_annotated_commit**>(&heads), 1, &opts, &checkOpts);
if (error < 0)
errorMessage(error);
error = git_repository_state_cleanup(repo);
if (error < 0)
errorMessage(error);