更新が多くなった+新しいコマンドを追加したので別記事にまとめ直しました。
http://qiita.com/KeitaMoromizato/items/23474a40d1a19994dc81
最近WIP PR(Work In Progress Pull Request)による開発を始めたけどプルリクエストを作るまでが面倒なので自動化してみた。
まずはaliasを作るためにconfigに追加
.git/config
[alias "create"]
pr = "!f(){ .git/Github/create_pullrequest $1;};f"
上記aliasを叩いた時に実行されるコマンドを定義
.git/Github/create_pullrequest
git checkout -b $1
git commit --allow-empty -m "create PullRequest"
git push origin $1
git branch -u origin/$1 $1
コマンドに実行権限を付与
$ chmod a+x .git/Github/create_pullrequest
これで以下のコマンドを叩けば、カレントブランチから新しいブランチを作ってpushまでは自動でできる。
$ git create.pr feature/test
create.prとか言いつつPullRequestを作成するところまでは自動化していないのでそれはまた次の機会に。
===
追記
hubコマンドを使ってPullRequestまで自動化できます。
hubコマンドを使えない方はhomebrewでインストール(Windowsの方ごめんなさい)
$ brew install hub
上で作ったファイルに1行目、6行目を追記。
.git/Github/create_pullrequest
current=`git rev-parse --abbrev-ref HEAD`
git checkout -b $1
git commit --allow-empty -m "create PullRequest"
git push origin $1
git branch -u origin/$1 $1
hub pull-request -m "$1" -b $current
これでPullRequestの作成まで自動化出来ます。
===
追記2
チーム開発をするときは上記スクリプトを生成するスクリプトを書きましょう。以下のスクリプトをレポジトリのどこかに置いて、cloneしたときにgitのルートディレクトリ(.gitがある場所)でスクリプトを実行します。
setup.sh
#!/bin/sh
echo "setup PullRequest..."
mkdir .git/Github
#create PullRequest script
cat << "EOF" > .git/Github/create_pullrequest
#!/bin/sh
current=`git rev-parse --abbrev-ref HEAD`
git checkout -b $1
git commit --allow-empty -m "create PullRequest"
git push origin $1
git branch -u origin/$1 $1
hub pull-request -m "$1" -b $current
EOF
chmod +x .git/Github/create_pullrequest
#setup gitconfig
cat << "EOF" >> .git/config
[alias "create"]
pr = "!f(){ .git/Github/create_pullrequest $1;};f"
EOF