Last active
November 14, 2016 12:33
-
-
Save mapyo/b08ed9f726878289887c to your computer and use it in GitHub Desktop.
現在の開いているプルリクのブランチに切り替えて変更分をとってくるやつ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
使い方的なもの
zshrcとかbashrcとかその辺に以下を追加
git-checkout-this-pr
を実行http://motemen.hatenablog.com/entry/2014/07/04/git-checkout-this-pr
こちらのスクリプトが動かなくなっていたので修正した。
chrome使ってる人のみ。