Merge two arbitrary commits. Returns: an index with the result of the merge. Parameters: ours The commit to take as "ours" or base. theirs The commit which will be merged into "ours" favor An enums.MergeFavor c
(
self,
ours: str | Oid | Commit,
theirs: str | Oid | Commit,
favor: MergeFavor = MergeFavor.NORMAL,
flags: MergeFlag = MergeFlag.FIND_RENAMES,
file_flags: MergeFileFlag = MergeFileFlag.DEFAULT,
)
| 863 | return mergeFileResult |
| 864 | |
| 865 | def merge_commits( |
| 866 | self, |
| 867 | ours: str | Oid | Commit, |
| 868 | theirs: str | Oid | Commit, |
| 869 | favor: MergeFavor = MergeFavor.NORMAL, |
| 870 | flags: MergeFlag = MergeFlag.FIND_RENAMES, |
| 871 | file_flags: MergeFileFlag = MergeFileFlag.DEFAULT, |
| 872 | ) -> 'Index': |
| 873 | """ |
| 874 | Merge two arbitrary commits. |
| 875 | |
| 876 | Returns: an index with the result of the merge. |
| 877 | |
| 878 | Parameters: |
| 879 | |
| 880 | ours |
| 881 | The commit to take as "ours" or base. |
| 882 | |
| 883 | theirs |
| 884 | The commit which will be merged into "ours" |
| 885 | |
| 886 | favor |
| 887 | An enums.MergeFavor constant specifying how to deal with file-level conflicts. |
| 888 | For all but NORMAL, the index will not record a conflict. |
| 889 | |
| 890 | flags |
| 891 | A combination of enums.MergeFlag constants. |
| 892 | |
| 893 | file_flags |
| 894 | A combination of enums.MergeFileFlag constants. |
| 895 | |
| 896 | Both "ours" and "theirs" can be any object which peels to a commit or |
| 897 | the id (string or Oid) of an object which peels to a commit. |
| 898 | """ |
| 899 | ours_ptr = ffi.new('git_commit **') |
| 900 | theirs_ptr = ffi.new('git_commit **') |
| 901 | cindex = ffi.new('git_index **') |
| 902 | |
| 903 | if isinstance(ours, (str, Oid)): |
| 904 | ours_object = self[ours] |
| 905 | if not isinstance(ours_object, Commit): |
| 906 | raise TypeError(f'expected Commit, got {type(ours_object)}') |
| 907 | ours = ours_object |
| 908 | if isinstance(theirs, (str, Oid)): |
| 909 | theirs_object = self[theirs] |
| 910 | if not isinstance(theirs_object, Commit): |
| 911 | raise TypeError(f'expected Commit, got {type(theirs_object)}') |
| 912 | theirs = theirs_object |
| 913 | |
| 914 | ours = ours.peel(Commit) |
| 915 | theirs = theirs.peel(Commit) |
| 916 | |
| 917 | opts = self._merge_options(favor, flags, file_flags) |
| 918 | |
| 919 | ffi.buffer(ours_ptr)[:] = ours._pointer[:] |
| 920 | ffi.buffer(theirs_ptr)[:] = theirs._pointer[:] |
| 921 | |
| 922 | err = C.git_merge_commits(cindex, self._repo, ours_ptr[0], theirs_ptr[0], opts) |