module documentation

Porcelain for git subtree operations.

Function subtree_add Add a subtree to the repository.
Function subtree_merge Merge changes into an existing subtree.
Function subtree_pull Pull changes from a remote repository into a subtree.
Function subtree_push Push a subtree to a remote repository.
Function subtree_split Split a subtree into a separate branch.
Function _create_subtree_commit Create a subtree commit with standard metadata.
def subtree_add(repo: RepoPath, prefix: bytes | str, repository: str | None = None, ref: bytes | str | None = None, commit: bytes | str | Commit | Tag | None = None, squash: bool = False, message: bytes | None = None) -> ObjectID:

Add a subtree to the repository.

Parameters
repo:RepoPathRepository to add subtree to
prefix:bytes | strDirectory path where subtree will be added
repository:str | NoneURL of repository to add (for remote subtrees)
ref:bytes | str | NoneRef to fetch from repository
commit:bytes | str | Commit | Tag | NoneCommit object to add (for local subtrees)
squash:boolIf True, squash history into a single commit
message:bytes | NoneCustom commit message
Returns
ObjectIDObject ID of the new commit
Raises
ErrorIf prefix already exists or commit cannot be found
ValueErrorIf neither (repository, ref) nor commit is provided
def subtree_merge(repo: RepoPath, prefix: bytes | str, commit: bytes | str | Commit | Tag, squash: bool = False, message: bytes | None = None) -> ObjectID:

Merge changes into an existing subtree.

Parameters
repo:RepoPathRepository to merge into
prefix:bytes | strDirectory path of the subtree
commit:bytes | str | Commit | TagCommit to merge
squash:boolIf True, squash history into a single commit
message:bytes | NoneCustom commit message
Returns
ObjectIDObject ID of the merge commit
Raises
ErrorIf prefix doesn't exist or merge fails
def subtree_pull(repo: RepoPath, prefix: bytes | str, repository: str, ref: bytes | str, squash: bool = False, message: bytes | None = None) -> ObjectID:

Pull changes from a remote repository into a subtree.

Parameters
repo:RepoPathRepository to pull into
prefix:bytes | strDirectory path of the subtree
repository:strURL of repository to pull from
ref:bytes | strRef to fetch
squash:boolIf True, squash history into a single commit
message:bytes | NoneCustom commit message
Returns
ObjectIDObject ID of the merge commit
Raises
ErrorIf fetch or merge fails
def subtree_push(repo: RepoPath, prefix: bytes | str, repository: str, ref: bytes | str):

Push a subtree to a remote repository.

Parameters
repo:RepoPathRepository to push from
prefix:bytes | strDirectory path of the subtree
repository:strURL of repository to push to
ref:bytes | strRef to push to
Raises
ErrorIf split or push fails
def subtree_split(repo: RepoPath, prefix: bytes | str, branch: bytes | str | None = None, rejoin: bool = False, onto: bytes | str | None = None) -> ObjectID:

Split a subtree into a separate branch.

Parameters
repo:RepoPathRepository to split from
prefix:bytes | strDirectory path of the subtree to split
branch:bytes | str | NoneBranch name to create (optional)
rejoin:boolIf True, merge the split branch back with metadata
onto:bytes | str | NoneCommit to use as the initial parent (optional)
Returns
ObjectIDObject ID of the split commit
Raises
ErrorIf prefix doesn't exist
def _create_subtree_commit(repo: Repo, tree_id: ObjectID, parents: list[ObjectID], message: bytes, base_commit: Commit) -> ObjectID:

Create a subtree commit with standard metadata.

Parameters
repo:RepoRepository to create commit in
tree_id:ObjectIDTree ID for the commit
parents:list[ObjectID]Parent commit IDs
message:bytesCommit message (with trailers already added)
base_commit:CommitBase commit to copy author/committer info from
Returns
ObjectIDObject ID of the new commit