pub fn create_worktree(
repo_root: &Path,
branch: &str,
rebase_onto_main: bool,
placement: WorktreePlacement,
) -> Result<WorktreeCreation, PawError>Expand description
Creates a git worktree for branch.
If the branch already exists, checks it out in a new worktree. If the
branch does not exist, creates it from HEAD with git worktree add -b.
Returns both the worktree path and whether the branch was newly created,
so the session can track which branches to delete on purge.
When rebase_onto_main is true and the target branch already exists in
the local repository, the branch is rebased onto default_branch() BEFORE
the existence check. The rebase resolves drift between supervisor work on
main and live agent branches (MILESTONE.md drift item 48: agents otherwise
commit on a stale baseline). On rebase conflict the function runs
git rebase --abort and returns PawError::WorktreeError; the branch is
left at its pre-rebase HEAD. When rebase_onto_main is false or the
branch does not yet exist locally, the rebase step is skipped.
placement selects where the worktree directory is created (see
WorktreePlacement). WorktreePlacement::Child resolves to
<repo_root>/.git-paw/worktrees/<branch-slug> (creating
.git-paw/worktrees/ if absent); WorktreePlacement::Sibling resolves
to <repo_parent>/<project>-<branch-slug>, matching the v0.7.0 layout.
Only the resolved target path varies with placement; all other behaviour
is identical.