From 1da19cd5abafecef343e6f46f61156270e56eab4 Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Wed, 25 Mar 2015 16:13:37 -0700 Subject: [PATCH] add backporting git alias --- git/gitconfig | 2 ++ git/githelpers | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/git/gitconfig b/git/gitconfig index 699d56c..b28102d 100644 --- a/git/gitconfig +++ b/git/gitconfig @@ -31,6 +31,8 @@ la = !git l --all sync = "!source ~/.githelpers && sync_to_remote" bsync = "!source ~/.githelpers && update_branch" + bp = !git backport + backport = "!source ~/.githelpers && backport_pr" todo = grep --heading --break --ignore-case -e ' FIX: *' -e ' TODO: *' pr = "!source ~/.githelpers && get_pr" diff --git a/git/githelpers b/git/githelpers index dc1a78e..c71376c 100644 --- a/git/githelpers +++ b/git/githelpers @@ -87,4 +87,23 @@ clean_branches() { for i in ${BRANCHES}; do git branch -d $i done -} \ No newline at end of file +} + +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 - +}