Skip to main content

move_worktree

Function move_worktree 

Source
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:

  1. Renames the branch
  2. Moves the worktree directory
  3. Updates worktree metadata

The operation includes rollback if the directory move fails after branch rename.

§Arguments

  • repo - The repository containing the worktree
  • from - Current worktree/branch name
  • to - New worktree/branch name
  • options - 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