Pull by phatblat · Pull Request #464 · libgit2/objective-git (original) (raw)

My insights are for raw libgit2 but I will outline how I merge and perhaps this can be applied in objective-git.

For me git_merge_analysis is key to getting good merges in the second step of a push.

I start out getting merge heads for HEAD and corresponding head on remote tracking branch. These merge heads are git_annotated_commit in libgit2. Then I use git_merge_analysis to determine if fast-forward is possible, if HEAD is unborn (without any previous commits) or if we need to perform a regular merge.

fast-forward and unborn HEAD is fixed by pointing to the head commit of the remote tracking branch with git_reference_set_target but the real work lies in regular merge of course.

The regular merge changes the tree and I use git_index_has_conflicts to check for conflicts. When there are none I can simply make the merge commit having the old HEAD and remote tracking head commits as parents.

If there are conflicts these need to be resolved by the user somehow and git_index_remove_bypath followed by git_index_add_bypath is used to mark a file as resolved and when everything is resolved a commit can proceed.

Hope this helps in some small way.

Working Copy does not currently do rebase but it should be a matter of applying git_cherrypick on the commits that the remote tracking branch is ahead.