diff --git a/git/githelpers b/git/githelpers index 01d55fb..ca3894d 100644 --- a/git/githelpers +++ b/git/githelpers @@ -111,7 +111,15 @@ backport_pr() { 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 + git checkout ${BRANCH} && git pull ${REMOTE} ${BRANCH} && curl -s "https://github.com/elastic/kibana/pull/${PR}.patch" | git am + + # if the backport couldn't be cleanly applied, tell the user and exit + if [ $? -ne 0 ]; then + echo "FAILED - Backport could not be cleanly applied!" + echo "FAILED - Fix by hand or run 'git am --abort'" + exit 2 + fi + + # switch back if we didn't start in the target branch [ "$THISBRANCH" != "$BRANCH" ] && git checkout - }