add backporting git alias

This commit is contained in:
2015-03-25 16:13:37 -07:00
parent 556aa15bfa
commit 1da19cd5ab
2 changed files with 22 additions and 1 deletions

View File

@@ -31,6 +31,8 @@
la = !git l --all la = !git l --all
sync = "!source ~/.githelpers && sync_to_remote" sync = "!source ~/.githelpers && sync_to_remote"
bsync = "!source ~/.githelpers && update_branch" bsync = "!source ~/.githelpers && update_branch"
bp = !git backport
backport = "!source ~/.githelpers && backport_pr"
todo = grep --heading --break --ignore-case -e ' FIX: *' -e ' TODO: *' todo = grep --heading --break --ignore-case -e ' FIX: *' -e ' TODO: *'
pr = "!source ~/.githelpers && get_pr" pr = "!source ~/.githelpers && get_pr"

View File

@@ -87,4 +87,23 @@ clean_branches() {
for i in ${BRANCHES}; do for i in ${BRANCHES}; do
git branch -d $i git branch -d $i
done done
} }
backport_pr() {
PR=$1
BRANCH=$2
[ -z "$BRANCH" ] && BRANCH=`git rev-parse --abbrev-ref HEAD`
REMOTE=$3
: ${REMOTE:=$DEFAULT_REMOTE}
THISBRANCH=`git rev-parse --abbrev-ref HEAD`
if [ -z "$PR" ]; then
echo "Please specify a PR to backport"
exit 1
fi
echo Backporting ${PR} to ${BRANCH} from ${REMOTE}
git fetch ${REMOTE} pull/${1}/head:pr/${1}
git checkout ${BRANCH} && curl -s "https://github.com/elastic/kibana/pull/${PR}.patch" | git am
[ "$THISBRANCH" != "$BRANCH" ] && git checkout -
}