2

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

LoranceChen
  • 2,453
  • 2
  • 22
  • 48
  • Have you gotten any methods? – Suge Nov 23 '20 at 01:44
  • @Suge, maybe use `git_patch_to_buf` method. Long time ago, sorry forgetten the problem context. could be some help in the repo: https://github.com/LoranceChen/libgit2-travel – LoranceChen Nov 24 '20 at 01:07

0 Answers0