Use when given a GitHub pull request link and needing to create an isolated worktree, check out PR code, export the PR diff to <pr-number>.diff, and return JSON metadata (`code_path`, `diff_filename`, `work_tree`) even when gh authentication is unavailable or the current directory is outside the target repo.
Create a new git worktree from a target project, check out the target PR in that worktree, save the PR diff as <pr-number>.diff, and emit one JSON object for later steps.
Use the bundled script for deterministic execution.
pr_link
https://github.com/pingcap/tidb/pull/1234512345project_path
Print exactly one JSON object with these fields:
code_path: absolute path to the newly created worktreediff_filename: generated diff filename, always <pr-number>.diffwork_treeworktrees/Example:
{"code_path":"/abs/repo/worktrees/pr-12345","diff_filename":"12345.diff","work_tree":"pr-12345"}
If currently inside the target project:
./prepare-pr-diff-worktree/scripts/create_pr_worktree_and_diff.sh <pr_link>
If currently outside the target project:
./prepare-pr-diff-worktree/scripts/create_pr_worktree_and_diff.sh --project-path <project_path> <pr_link>
gh (gh auth login)
gh pr checkoutgh pr diffgh auth):
git fetch https://github.com/<owner>/<repo>.git pull/<pr-number>/headFETCH_HEADhttps://github.com/<owner>/<repo>/pull/<pr-number>.diff--project-path.origin remote.<repo-root>/worktrees/.gh, fallback git fetch for public GitHub PRs).<pr-number>.diff at the worktree root (preferred gh, fallback curl from .diff URL).origin should point to the target GitHub repo.worktrees/pr-<number> already exists, the script appends a numeric suffix to create a unique work_tree.