module documentation
Git merge implementation.
| Class | |
Handles git merge operations. |
| Exception | |
Raised when a merge conflict occurs. |
| Function | make |
Return a Merge3 object, or raise ImportError if merge3 is not installed. |
| Function | merge |
Perform three-way merge on blob contents. |
| Function | octopus |
Perform an octopus merge of multiple commits. |
| Function | recursive |
Perform a recursive merge with multiple merge bases. |
| Function | three |
Perform a three-way merge between commits. |
| Function | _can |
Check if lines can be merged without conflict. |
| Function | _create |
Create a virtual commit object for recursive merging. |
| Function | _merge3 |
Convert merge3 result to bytes with conflict markers. |
| Function | _merge |
Merge lines when possible. |
def make_merge3(base:
Sequence[ bytes], a: Sequence[ bytes], b: Sequence[ bytes], is_cherrypick: bool = False, sequence_matcher: type[ SequenceMatcherProtocol[ bytes]] | None = None) -> merge3.Merge3[ bytes]:
¶
Return a Merge3 object, or raise ImportError if merge3 is not installed.
def merge_blobs(base_blob:
Blob | None, ours_blob: Blob | None, theirs_blob: Blob | None, path: bytes | None = None, gitattributes: GitAttributes | None = None, config: Config | None = None) -> tuple[ bytes, bool]:
¶
Perform three-way merge on blob contents.
| Parameters | |
baseBlob | None | Common ancestor blob (can be None) |
oursBlob | None | Our version of the blob (can be None) |
theirsBlob | None | Their version of the blob (can be None) |
path:bytes | None | Optional path of the file being merged |
gitattributes:GitAttributes | None | Optional GitAttributes object for checking merge drivers |
config:Config | None | Optional Config object for loading merge driver configuration |
| Returns | |
tuple[ | Tuple of (merged_content, had_conflicts) |
def octopus_merge(object_store:
BaseObjectStore, merge_bases: list[ ObjectID], head_commit: Commit, other_commits: list[ Commit], gitattributes: GitAttributes | None = None, config: Config | None = None) -> tuple[ Tree, list[ bytes]]:
¶
Perform an octopus merge of multiple commits.
The octopus merge strategy merges multiple branches sequentially into a single commit with multiple parents. It refuses to proceed if any merge would result in conflicts that require manual resolution.
| Parameters | |
objectBaseObjectStore | Object store to read/write objects |
mergelist[ | List of common ancestor commit IDs for all commits |
headCommit | Current HEAD commit (ours) |
otherlist[ | List of commits to merge (theirs) |
gitattributes:GitAttributes | None | Optional GitAttributes object for checking merge drivers |
config:Config | None | Optional Config object for loading merge driver configuration |
| Returns | |
tuple[ | tuple of (merged_tree, list_of_conflicted_paths) If any conflicts occur during the sequential merges, the function returns early with the conflicts list populated. |
| Raises | |
TypeError | If any object is not of the expected type |
def recursive_merge(object_store:
BaseObjectStore, merge_bases: list[ ObjectID], ours_commit: Commit, theirs_commit: Commit, gitattributes: GitAttributes | None = None, config: Config | None = None) -> tuple[ Tree, list[ bytes]]:
¶
Perform a recursive merge with multiple merge bases.
This implements Git's recursive merge strategy, which handles cases where there are multiple common ancestors (criss-cross merges). The algorithm:
- If there's 0 or 1 merge base, perform a simple three-way merge
- If there are multiple merge bases, merge them recursively to create a virtual merge base, then use that for the final three-way merge
| Parameters | |
objectBaseObjectStore | Object store to read/write objects |
mergelist[ | List of merge base commit IDs |
oursCommit | Our commit |
theirsCommit | Their commit |
gitattributes:GitAttributes | None | Optional GitAttributes object for checking merge drivers |
config:Config | None | Optional Config object for loading merge driver configuration |
| Returns | |
tuple[ | tuple of (merged_tree, list_of_conflicted_paths) |
def three_way_merge(object_store:
BaseObjectStore, base_commit: Commit | None, ours_commit: Commit, theirs_commit: Commit, gitattributes: GitAttributes | None = None, config: Config | None = None) -> tuple[ Tree, list[ bytes]]:
¶
Perform a three-way merge between commits.
| Parameters | |
objectBaseObjectStore | Object store to read/write objects |
baseCommit | None | Common ancestor commit (None if no common ancestor) |
oursCommit | Our commit |
theirsCommit | Their commit |
gitattributes:GitAttributes | None | Optional GitAttributes object for checking merge drivers |
config:Config | None | Optional Config object for loading merge driver configuration |
| Returns | |
tuple[ | tuple of (merged_tree, list_of_conflicted_paths) |
def _can_merge_lines(base_lines:
Sequence[ bytes], a_lines: Sequence[ bytes], b_lines: Sequence[ bytes]) -> bool:
¶
Check if lines can be merged without conflict.