Materializes ref into a detached worktree under parentDir, runs block with its directory, and removes the worktree afterward (even on failure).