1

I am essentially trying to do a "git merge --no-ff branch" to merge my branch back in. Looking at the Pygit2 documentation, I am not entierly sure what the correct way to do this is. The direct thought would be to do something like this:

repo.merge(branch.target)

However, I do not see any options for merging with no-fastforward. Has anyone extensively used pygit2 that can give me any insight? All the help is greatly appreciated.

Stephen Lu
  • 314
  • 1
  • 9

1 Answers1

3

However, I do not see any options for merging with no-fastforward.

That is because, from the pygit2 merge documentation:

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

That means you can then decide to create a new commit once the merge itself is done.

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.

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

user = repo.default_signature()
tree = repo.index.write_tree()
new_commit = repo.create_commit('HEAD', user, user, tree,
                                [repo.head.target, other_branch_tip])
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250