libgit2 / pygit2

Python bindings for libgit2
https://www.pygit2.org/
Other
1.59k stars 383 forks source link

Repository.create_commit() after Repository.merge() doesn't clear merge artifacts #1081

Closed imbuedhope closed 2 years ago

imbuedhope commented 3 years ago

Is there a different call that is supposed to do this? The docs didn't mention anything.

When I run the following the merge happens successfully and there is a new commit added to HEAD

>>> import os, pygit2
>>> r = pygit2.Repository(os.getcwd())
>>> target_br = 'foo'
>>> r.merge(r.references[target_br].resolve().target)
>>> tree = r.index.write_tree()
>>> r.create_commit('HEAD', r.default_signature, r.default_signature, 'test merge commit', tree, [r.head.peel().oid, r.references[target_br].resolve().target])
8d8c429c7ec9177349091130e7d952d602907c37
>>> exit()

but git status claims that the merge is still in progress and there are merge artifacts in the .git folder

$ git status
On branch testy
All conflicts fixed but you are still merging.
  (use "git commit" to conclude merge)
$ cat .git/MERGE_HEAD 
c9700fe76b89132e33ed118f69845fff42eb51f9
yoichi commented 2 years ago

I think it is the expected behavior. You should call r.state_cleanup() at the end.

libgit2's example does similarly: https://github.com/libgit2/libgit2/blob/9b04a3076d419279ac43f165be89a9893f9f0670/examples/merge.c#L270