Skip to main content

checkout_branch_in_worktree

Function checkout_branch_in_worktree 

Source
pub fn checkout_branch_in_worktree(
    wt_repo: &Repository,
    branch: &str,
) -> Result<CheckoutOutcome>
Expand description

Move HEAD in the worktree opened as wt_repo to branch.

wt_repo must be a Repository opened on the worktree’s path (not the bare root) so HEAD/index target that worktree’s working directory — the same handle the stash operations take, so one open serves the whole checkout flow. Resolves refs/heads/<branch>, performs a safe checkout (CheckoutBuilder::safe()), then updates HEAD with set_head. On conflict HEAD is left unmoved and CheckoutOutcome::Conflict is returned rather than Err, so the caller can prompt before deciding to stash-and-retry (PR-3) or abort.

Returns Err only for genuine git errors (branch not found, I/O, etc.).