Merge

Repository.merge_base(oid, oid) → Oid

Find as good common ancestors as possible for a merge.

Repository.merge(id)

Merges the given id into HEAD.

Merges the given commit(s) into HEAD, writing the results into the working directory. Any changes are staged for commit and any conflicts are written to the index. Callers should inspect the repository’s index after this completes, resolve any conflicts and prepare a commit.

Repository.merge_analysis(id) -> (Integer, Integer)

Analyzes the given branch and determines the opportunities for merging them into the HEAD of the repository

The first returned value is a mixture of the GIT_MERGE_ANALYSIS_NONE, _NORMAL, _UP_TO_DATE, _FASTFORWARD and _UNBORN flags. The second value is the user’s preference from ‘merge.ff’

The merge method

The method does a merge over the current working copy. It gets an Oid object as a parameter.

As its name says, it only does the merge, does not commit nor update the branch reference in the case of a fastforward.

For the moment, the merge does not support options, it will perform the merge with the default ones defined in GIT_MERGE_OPTS_INIT libgit2 constant.

Example:

>>> other_branch_tip = '5ebeeebb320790caf276b9fc8b24546d63316533'
>>> repo.merge(other_branch_tip)

You can now inspect the index file for conflicts and get back to the user to resolve if there are. Once there are no conflicts left, you can create a commit with these two parents.

>>> user = repo.default_signature
>>> tree = repo.index.write_tree()
>>> new_commit = repo.create_commit('HEAD', user, user, tree,
                                    [repo.head.target, other_branch_tip])