class documentation

class WorkTreeContainer:

Constructor: WorkTreeContainer(repo)

View In Hierarchy

Container for managing multiple working trees.

This class manages worktrees for a repository, similar to how RefsContainer manages references.

Method __init__ Initialize a WorkTreeContainer for the given repository.
Method __iter__ Iterate over all worktrees.
Method add Add a new worktree.
Method list List all worktrees for this repository.
Method lock Lock a worktree to prevent it from being pruned.
Method move Move a worktree to a new location.
Method prune Prune worktree administrative files for missing worktrees.
Method remove Remove a worktree.
Method repair Repair worktree administrative files.
Method unlock Unlock a worktree.
Instance Variable _repo Undocumented
def __init__(self, repo: Repo):

Initialize a WorkTreeContainer for the given repository.

Parameters
repo:RepoThe repository this container belongs to
def __iter__(self) -> Iterator[WorkTreeInfo]:

Iterate over all worktrees.

def add(self, path: str | bytes | os.PathLike[str], branch: str | bytes | None = None, commit: ObjectID | None = None, force: bool = False, detach: bool = False, exist_ok: bool = False, relative_paths: bool | None = None) -> Repo:

Add a new worktree.

Parameters
path:str | bytes | os.PathLike[str]Path where the new worktree should be created
branch:str | bytes | NoneBranch to checkout in the new worktree
commit:ObjectID | NoneSpecific commit to checkout (results in detached HEAD)
force:boolForce creation even if branch is already checked out elsewhere
detach:boolDetach HEAD in the new worktree
exist_ok:boolIf True, do not raise an error if the directory already exists
relative_paths:bool | NoneIf True, use relative paths for gitdir references. If None, check worktree.useRelativePaths config (defaults to False)
Returns
RepoThe newly created worktree repository
def list(self) -> list[WorkTreeInfo]:

List all worktrees for this repository.

Returns
list[WorkTreeInfo]A list of WorkTreeInfo objects
def lock(self, path: str | bytes | os.PathLike[str], reason: str | None = None):

Lock a worktree to prevent it from being pruned.

Parameters
path:str | bytes | os.PathLike[str]Path to the worktree to lock
reason:str | NoneOptional reason for locking
def move(self, old_path: str | bytes | os.PathLike[str], new_path: str | bytes | os.PathLike[str], relative_paths: bool | None = None):

Move a worktree to a new location.

Parameters
old_path:str | bytes | os.PathLike[str]Current path of the worktree
new_path:str | bytes | os.PathLike[str]New path for the worktree
relative_paths:bool | NoneIf True, use relative paths for gitdir references. If None, check worktree.useRelativePaths config or preserve existing format
def prune(self, expire: int | None = None, dry_run: bool = False) -> builtins.list[str]:

Prune worktree administrative files for missing worktrees.

Parameters
expire:int | NoneOnly prune worktrees older than this many seconds
dry_run:boolDon't actually remove anything, just report what would be removed
Returns
builtins.list[str]List of pruned worktree identifiers
def remove(self, path: str | bytes | os.PathLike[str], force: bool = False):

Remove a worktree.

Parameters
path:str | bytes | os.PathLike[str]Path to the worktree to remove
force:boolForce removal even if there are local changes
def repair(self, paths: Sequence[str | bytes | os.PathLike[str]] | None = None, relative_paths: bool | None = None) -> builtins.list[str]:

Repair worktree administrative files.

Parameters
paths:Sequence[str | bytes | os.PathLike[str]] | NoneOptional list of worktree paths to repair. If None, repairs connections from the main repository to all linked worktrees.
relative_paths:bool | NoneIf True, use relative paths for gitdir references. If None, check worktree.useRelativePaths config or preserve existing format
Returns
builtins.list[str]List of repaired worktree paths
def unlock(self, path: str | bytes | os.PathLike[str]):

Unlock a worktree.

Parameters
path:str | bytes | os.PathLike[str]Path to the worktree to unlock
_repo =

Undocumented