libgit2 / libgit2sharp

Git + .NET = ❤
http://libgit2.github.com
MIT License
3.15k stars 887 forks source link

Added ObjectDatabase.MergeTrees() #1941

Closed frindler closed 3 months ago

frindler commented 2 years ago

This wraps the libgit2 function git_merge_trees() and so allows one to merge trees directly (specifying the ancestor tree to use in the 3-way merge). This functionality currently does not seem to be possible in libgit2sharp since the merge methods always take commits and do not allow to specify the ancestor. So, for instance, if I want to compute an octopus-merge ancestor and then iteratively merge N commits relative to this ancestor, then I cannot currently do this. With MergeTrees() one can. Later, one may write the resulting index to a tree via Index.WriteToTree() and create a commit with ObjectDatabase.CreateCommit(). Notes: 1) I added MergeTrees() to ObjectDatabase, not directly on Repository, because it seemed more low-level. 2) Internally I use ObjectHandle for trees (not a new "TreeHandle" via git_tree_lookup) - this seems to be how it's done everywhere else that uses Tree and it doesn't seem to matter in any case since libgit2 treats trees as objects. 3) I added 5 unit tests, which are basically the same unit tests as the existing merge ones for commits (I copied & adapted them), but with merging on the level of commits replaced with merging on the level of the corresponding trees.