Skip to content

Commit

Permalink
misc: Add checkout-pr.sh script for easier checkout
Browse files Browse the repository at this point in the history
It usually takes some time to get patches for review but it'd be useful
to have a script for that.

The 'checkout-pr.sh' script accepts a single parameter to get the pull
request ID.
It fetches from the source repo and checkouts to the fetched head.

The example usage is as follows.

  $ ./misc/checkout-pr.sh 1974
    % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                   Dload  Upload   Total   Spent    Left  Speed
  100 18502  100 18502    0     0  39899      0 --:--:-- --:--:-- --:--:-- 39875
  remote: Enumerating objects: 1, done.
  remote: Counting objects: 100% (1/1), done.
  remote: Total 1 (delta 0), reused 1 (delta 0), pack-reused 0 (from 0)
  Unpacking objects: 100% (1/1), 354 bytes | 354.00 KiB/s, done.
  From https://github.com/GabrielKimm/uftrace
   * branch              fix-tui-non-utf8-locale -> FETCH_HEAD
  Switched to and reset branch 'pull/1974'

Now you're ready to review the pull request 1974 where can be found at
namhyung#1974.

Signed-off-by: Honggyu Kim <[email protected]>
  • Loading branch information
honggyukim committed Oct 1, 2024
1 parent 4afc58f commit 6fbb3cd
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions misc/checkout-pr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh

if [ $# -ne "1" ]; then
echo "usage: $0 <PR number>"
exit 1
fi

if [ ! -x "$(command -v curl)" ]; then
echo "You need curl to run this script."
exit 1
fi

pr=$1
pr_json="pr.json"

curl -o $pr_json https://api.github.com/repos/namhyung/uftrace/pulls/$pr
repo=$(jq -r '.head.repo.html_url' $pr_json)
refspec=$(jq -r '.head.ref' $pr_json)
git fetch $repo $refspec && git checkout -B pull/$pr FETCH_HEAD
exit 0

0 comments on commit 6fbb3cd

Please sign in to comment.