Skip to content

Instantly share code, notes, and snippets.

@mapyo mapyo/git-checkout-this-pr
Last active Nov 14, 2016

Embed
What would you like to do?
現在の開いているプルリクのブランチに切り替えて変更分をとってくるやつ
#!/bin/sh
set -e
chrome-cli execute '(function () {
return [
location.hostname,
location.pathname.split("/")[1],
location.pathname.split("/")[2],
document.title,
document.getElementsByClassName("css-truncate-target")[4].innerHTML
].join("\n");
})()' | {
read host
read user
read repo
read title
read pr_ref
remote_url=$(git config remote.origin.url)
remote_url=${remote_url%.git}
if [ "$remote_url" != "git@$host:$user/$repo" \
-a "$remote_url" != "https://$host/$user/$repo" \
-a "$remote_url" != "git://$host/$user/$repo" \
-a "$remote_url" != "ssh://git@$host/$user/$repo" ]; then
echo "Remote differs: $remote_url VS $host,$user,$repo" >&2
exit 1
fi
pr_branch=${pr_ref#*:}
pr_user=${pr_ref%:*}
if [ "$pr_user" = "$pr_ref" ]; then
pr_user=
fi
echo "$title ($pr_ref)"
if [ -n "$pr_user" ]; then
git remote add -f "$pr_user" "https://$host/$pr_user/$repo" || git remote update "$pr_user"
git checkout -b $pr_branch --track $pr_user/$pr_branch
else
git remote update origin
git checkout $pr_branch
git pull origin $pr_branch
fi
}
@mapyo

This comment has been minimized.

Copy link
Owner Author

commented Oct 23, 2015

使い方的なもの

brew install chrome-cli
cd ~
mkdir bin
cd bin
curl https://gist.githubusercontent.com/mapyo/b08ed9f726878289887c/raw/24df1eb6a1687d6d4d2e9916a43992396007e0a4/git-checkout-this-pr > git-checkout-this-pr
chmod +x git-checkout-this-pr

zshrcとかbashrcとかその辺に以下を追加

export PATH=$PATH:$HOME/bin
  1. 一度ターミナルを閉じて開く
  2. 普段使っているリポジトリに移動
  3. レビューしたり、手元に持ってきたいプルリクを開く
  4. git-checkout-this-prを実行

http://motemen.hatenablog.com/entry/2014/07/04/git-checkout-this-pr

こちらのスクリプトが動かなくなっていたので修正した。

chrome使ってる人のみ。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.