1

I try to merge branch into master:

repo = pygit2.Repository("/path/to/repo/")
branch = repo.lookup_branch("upstream/branch", pygit2.GIT_BRANCH_REMOTE)
oid = branch.target
merge_result = repo.merge(oid)

And merge_result contains ff oid (as in documentaion) and repo hasn't changed.

What should I do next to change the repository?

1 Answers1

4

The merge function does the merge (or in this case tells you you could skip it), but it's up to you (or the user of the tool) whether you want to move the current branch to the new position.

Doing that is the same as any other time you want to change a reference. In this case you want to get to the current branch, which you do via resolving HEAD to a non-symbolic reference and setting its target.

repo.lookup_reference('HEAD').resolve().target = merge_result.fastforward_oid
Carlos Martín Nieto
  • 5,207
  • 1
  • 15
  • 16
  • `merge_result` aka `repo.merge(oid)` returns for me a NoneType, and it means I can't pull `result.fastforward_oid`. How come the merge returns something for you? [I can't see it in the docs](http://www.pygit2.org/merge.html#pygit2.Repository.merge) – GuySoft Sep 02 '14 at 13:06
  • It seems this answer is out of date, according to [this commit in the docs](https://github.com/libgit2/pygit2/commit/9a7348a9d0af13e2d4bcf2ab19e167e64f173cd7) – GuySoft Sep 02 '14 at 13:19
  • 1
    This answer covers v0.20 which is what was released at the time. v0.21 fixed some silliness by making the merge method always perform a merge and introducing `merge_analysis` to let you see what the relationship between the commits is. – Carlos Martín Nieto Sep 02 '14 at 14:43