Merges the given Reference or Commit into HEAD. Merges the given commit into HEAD, writing the results into the working directory. Any changes are staged for commit and any conflicts are written to the index. Callers should inspect the repository's index after this
(
self,
source: Reference | Commit | Oid | str,
favor: MergeFavor = MergeFavor.NORMAL,
flags: MergeFlag = MergeFlag.FIND_RENAMES,
file_flags: MergeFileFlag = MergeFileFlag.DEFAULT,
)
| 982 | return Index.from_c(self, cindex) |
| 983 | |
| 984 | def merge( |
| 985 | self, |
| 986 | source: Reference | Commit | Oid | str, |
| 987 | favor: MergeFavor = MergeFavor.NORMAL, |
| 988 | flags: MergeFlag = MergeFlag.FIND_RENAMES, |
| 989 | file_flags: MergeFileFlag = MergeFileFlag.DEFAULT, |
| 990 | ) -> None: |
| 991 | """ |
| 992 | Merges the given Reference or Commit into HEAD. |
| 993 | |
| 994 | Merges the given commit into HEAD, writing the results into the working directory. |
| 995 | Any changes are staged for commit and any conflicts are written to the index. |
| 996 | Callers should inspect the repository's index after this completes, |
| 997 | resolve any conflicts and prepare a commit. |
| 998 | |
| 999 | Parameters: |
| 1000 | |
| 1001 | source |
| 1002 | The Reference, Commit, or commit Oid to merge into HEAD. |
| 1003 | It is preferable to pass in a Reference, because this enriches the |
| 1004 | merge with additional information (for example, Repository.message will |
| 1005 | specify the name of the branch being merged). |
| 1006 | Previous versions of pygit2 allowed passing in a partial commit |
| 1007 | hash as a string; this is deprecated. |
| 1008 | |
| 1009 | favor |
| 1010 | An enums.MergeFavor constant specifying how to deal with file-level conflicts. |
| 1011 | For all but NORMAL, the index will not record a conflict. |
| 1012 | |
| 1013 | flags |
| 1014 | A combination of enums.MergeFlag constants. |
| 1015 | |
| 1016 | file_flags |
| 1017 | A combination of enums.MergeFileFlag constants. |
| 1018 | """ |
| 1019 | |
| 1020 | if isinstance(source, Reference): |
| 1021 | # Annotated commit from ref |
| 1022 | cptr = ffi.new('struct git_reference **') |
| 1023 | ffi.buffer(cptr)[:] = source._pointer[:] # type: ignore[attr-defined] |
| 1024 | commit_ptr = ffi.new('git_annotated_commit **') |
| 1025 | err = C.git_annotated_commit_from_ref(commit_ptr, self._repo, cptr[0]) |
| 1026 | check_error(err) |
| 1027 | else: |
| 1028 | # Annotated commit from commit id |
| 1029 | if isinstance(source, str): |
| 1030 | # For backwards compatibility, parse a string as a partial commit hash |
| 1031 | warnings.warn( |
| 1032 | 'Passing str to Repository.merge is deprecated. ' |
| 1033 | 'Pass Commit, Oid, or a Reference (such as a Branch) instead.', |
| 1034 | DeprecationWarning, |
| 1035 | ) |
| 1036 | oid = self[source].peel(Commit).id |
| 1037 | elif isinstance(source, Commit): |
| 1038 | oid = source.id |
| 1039 | elif isinstance(source, Oid): |
| 1040 | oid = source |
| 1041 | else: |