class documentation
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 |
Initialize a WorkTreeContainer for the given repository.
| Parameters | |
repo:Repo | The repository this container belongs to |
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[ | Path where the new worktree should be created |
branch:str | bytes | None | Branch to checkout in the new worktree |
commit:ObjectID | None | Specific commit to checkout (results in detached HEAD) |
force:bool | Force creation even if branch is already checked out elsewhere |
detach:bool | Detach HEAD in the new worktree |
existbool | If True, do not raise an error if the directory already exists |
relativebool | None | If True, use relative paths for gitdir references. If None, check worktree.useRelativePaths config (defaults to False) |
| Returns | |
Repo | The newly created worktree repository |
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 | |
oldstr | bytes | os.PathLike[ | Current path of the worktree |
newstr | bytes | os.PathLike[ | New path for the worktree |
relativebool | None | If True, use relative paths for gitdir references. If None, check worktree.useRelativePaths config or preserve existing format |
Remove a worktree.
| Parameters | |
path:str | bytes | os.PathLike[ | Path to the worktree to remove |
force:bool | Force 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[ | Optional list of worktree paths to repair. If None, repairs connections from the main repository to all linked worktrees. |
relativebool | None | If True, use relative paths for gitdir references. If None, check worktree.useRelativePaths config or preserve existing format |
| Returns | |
builtins.list[ | List of repaired worktree paths |