pub fn move_worktree(
repo: &Repository,
from: &str,
to: &str,
options: &MoveOptions,
) -> Result<WorktreeDescriptor>Expand description
Move (rename) a worktree and its branch atomically.
This performs the following operations:
- Renames the branch
- Moves the worktree directory
- Updates worktree metadata
The operation includes rollback if the directory move fails after branch rename.
§Arguments
repo- The repository containing the worktreefrom- Current worktree/branch nameto- New worktree/branch nameoptions- Move options (force flag, etc.)
§Errors
Returns an error if:
- Source worktree doesn’t exist
- Target already exists (worktree or branch)
- Source is detached HEAD
- Source is protected (unless force)
- Source is dirty (unless force)
- Source has unpushed commits (unless force)
- Directory move fails