I'm want use libgit2 get a preview of a conflict commit in a bare repo, which means there is no workdir.
have using those functions, git_merge_commits
git_index_has_conflicts
and git_index_conflict_get
, to get relative infomation.
Main code like this:
git_index *index;
int error = git_merge_commits(&index, repo, git_commit1, git_commit2, NULL);
int conflict_count = git_index_has_conflicts(index);
git_oid index_tree_oid, index_commit_oid;
git_tree *index_tree;
if(conflict_count == 0) {
// do commit the index
} else {
// solve conflict
const git_index_entry *ancestor = NULL,
*ours = NULL,
*theirs = NULL;
error = git_index_conflict_get(
&ancestor,
&ours,
&theirs,
index,
"file2");
error_check(error);
...
How to get preview of the merge in buffer
contains <<<< HEAD
like this?
aaaaaaaa
bbbbbbbb22222222
<<<<<<< HEAD
bbbbbbbb11111111
bbbbbbbb11111111
=======
bbbbbbbb22222222
>>>>>>> b3
aaaaaaaa
aaaaaaaa
aaaaaaaa
Currently, a merge only has one file can conflict.
Thanks