#!/usr/bin/env bash set -euo pipefail usage() { cat <<'EOF' usage: scripts/worktree-review [--dry-run] [start-ref] Create an isolated, DETACHED review worktree under branches/review-. Reviews an existing branch in its own folder without creating a local branch, so review work never blocks or contaminates the author's implementation folder and a reviewer cannot accidentally commit. Default start-ref is prgs/. Examples: scripts/worktree-review fix/issue-123-example scripts/worktree-review --dry-run fix/issue-123-example prgs/fix/issue-123-example EOF } dry_run=0 if [[ "${1:-}" == "--dry-run" ]]; then dry_run=1 shift fi if [[ $# -lt 1 || $# -gt 2 ]]; then usage >&2 exit 2 fi branch="$1" start_ref="${2:-prgs/$branch}" script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" repo_root="$(cd "$script_dir/.." && pwd)" worktree_name="review-${branch//\//-}" worktree_path="$repo_root/branches/$worktree_name" if [[ -e "$worktree_path" ]]; then cat >&2 <