checkout-pr-branch.sh 704 B

123456789101112131415161718192021222324
  1. #!/bin/bash
  2. # This script is used to checkout a Parser PR branch in a forked repo.
  3. if test -z $1; then
  4. echo -e "Usage:\n"
  5. echo -e "\tcheckout-pr-branch.sh [github-username]:[pr-branch]\n"
  6. echo -e "The argument can be copied directly from github PR page."
  7. echo -e "The local branch name would be [github-username]/[pr-branch]."
  8. exit 0;
  9. fi
  10. username=$(echo $1 | cut -d':' -f1)
  11. branch=$(echo $1 | cut -d':' -f2)
  12. local_branch=$username/$branch
  13. fork="https://github.com/$username/parser"
  14. exists=`git show-ref refs/heads/$local_branch`
  15. if [ -n "$exists" ]; then
  16. git checkout $local_branch
  17. git pull $fork $branch:$local_branch
  18. else
  19. git fetch $fork $branch:$local_branch
  20. git checkout $local_branch
  21. fi