Reputation: 5683
I've managed to fetch from the remote, and I'm running the code below to get the changes staged in the local master branch.
git_annotated_commit * fetchhead_commit;
git_annotated_commit_lookup(&fetchhead_commit,
repo,
oid
);
git_merge(repo,&fetchhead_commit,1,NULL,NULL);
So now if I use the git command line tool to commit I get an automatic merge commit comment and after I can see that the log is the same as from the remote. I'm trying to obtain the same with libgit but my efforts so far in trying to create a commit of the merge results in the remote history to be lost.
How should I do a "proper" commit of the merged changes in order to preserve the history from the remote?
EDIT: Got a little further by doing a fast forward, but still if there are local commits these are lost after the incoming merge. Local changes are not lost, but staged after the merge and have to be committed again.
You can see my code here: https://github.com/fintechneo/libgit2/blob/master/jsbuild/jslib.c
The merge is happening in the fetchead_foreach_cb
function which again is called from jsgitpull
And for the record this hack does work in the web-browser if anyone wonders what the emscripten stuff is about.
Upvotes: 0
Views: 1500
Reputation: 2897
Create the merge commit with git_commit_create
. The merge commit should have two parents. One is the current HEAD commit. The second is the same annotated commit you merged in git_merge
(e.g. the fetch head).
Upvotes: 1