#!/bin/bash

# shellcheck shell=bash

# Switch to worktree
bridge_switch_worktree() {
  if [[ -z "${1:-}" ]]; then
    json_error "Branch name required"
    return 1
  fi
  branch_name="$1"
  
  if git_require_repo_root >/dev/null 2>&1; then
    if git_worktree_exists_for_branch "$branch_name"; then
      worktree_path="$(git_branch_to_worktree_path "$branch_name")"
      echo "\"$worktree_path\""
    else
      json_error "No worktree found for branch: $branch_name"
    fi
  else
    json_error "Not a git repository"
  fi
}