Open josecv opened 6 years ago
I admit that I don't know enough about it is really supposed to work, but may add here that GitPython
has a few merge-related functions in the IndexFile
and Tree
types, which could be useful here.
I did try faking this functionality with IndexFile
-- by essentially faking the merge and seeing what conflicts came out. It's capable of determining that there were merge conflicts, and where they were. But it unfortunately can't tell me what the precise fixes for the merge conflicts were. Also, unlike diffing, IndexFile
requires locking the index, so it doesn't work with parallel applications.
Indeed, it will only merge on tree/blob level, never on the individual hunks. That is the part you would have to implement on your end.
The default index file onrepo.index
will create locks, indeed, but I vaguely remember that this happens only on the default index, and not for non-default index files. The idea is to work with temporary index files, as needed.
Imagine I want to merge a feature branch into master, when that feature branch contains changes that conflict with master, e.g.:
In this case, in order to merge
feature2
intomaster
I had to resolve a conflict; so the merge commit has some content that is not in either of its parents:In git, I can use a three way diff as
git diff 87ef22e9631701222b8a461080484c1ee880c23c 87ef22e9631701222b8a461080484c1ee880c23c^1 87ef22e9631701222b8a461080484c1ee880c23c^2
to see only the changes that were made to resolve the merge conflict. (Incidentally this is equivalent togit diff-tree --cc 87ef22e9631701222b8a461080484c1ee880c23c
, and it's whatgit show
uses internally)Note that this differs from doing two separate
git diff
s against the individual parents of the commit. If Igit diff 87ef22e9631701222b8a461080484c1ee880c23c 87ef22e9631701222b8a461080484c1ee880c23c^1
, it will show not only the content brought in by resolving the merge commit, but also the content that was introduced by87ef22e9631701222b8a461080484c1ee880c23c^2
that did not conflict with the first parent.Currently GitPython does not support this sort of three-way (or n-way) diffing, so it is actually impossible to cleanly examine changes introduced by resolving merge conflicts.