MCPcopy Create free account
hub / github.com/libgit2/pygit2 / merge_commits

Method merge_commits

pygit2/repository.py:865–925  ·  view source on GitHub ↗

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,
    )

Source from the content-addressed store, hash-verified

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)

Callers 3

test_merge_commitsFunction · 0.80
test_merge_commits_favorFunction · 0.80

Calls 3

_merge_optionsMethod · 0.95
check_errorFunction · 0.85
from_cMethod · 0.45

Tested by 3

test_merge_commitsFunction · 0.64
test_merge_commits_favorFunction · 0.64