Last active
October 2, 2015 07:58
-
-
Save vishvananda/2206428 to your computer and use it in GitHub Desktop.
Script for backporting OpenStack branches
This file contains hidden or 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
#!/usr/bin/env bash | |
# This is a little script to make backporting patches. | |
# Instructions | |
# ------------ | |
# Make sure that milestone-proposed exists and is up to date: | |
# git branch -D milestone-proposed | |
# git checkout -b milestone-proposed origin/<branch> | |
# git pull | |
# Grab the file and stick it in your <project> directory: | |
# curl -OL https://raw.github.com/gist/2206428/bp.sh | |
# Make sure the script is runnable: | |
# chmod 755 bp.sh | |
# Start backporting reviews: | |
# ./bp.sh <review_number> | |
# Recovering from errors | |
# ---------------------- | |
# If you have previously downloaded a branch you will see a failure | |
# from git-review -d that branch xxxx/xxxx/xxxx already exists | |
# to recover you will need to delete two branches: | |
# git branch -D xxxx/xxxx/xxxx | |
# git branch -D bp-<review_number> | |
# If your branch fails to merge cleanly it is usually due to | |
# a dependent branch not being in yet. In that case your best bet | |
# is to wait for the dependent branch to merge, then: | |
# git checkout <branch> | |
# git pull | |
# git branch -D xxxx/xxxx/xxxx | |
# git branch -D bp-<review_number> | |
# and rerun the script | |
if [ -z "$1" ]; then | |
echo "Usage: $0 <review_number> [<branch=milestone-proposed>]" | |
exit 1 | |
fi | |
$BRANCH=${1-milestone-proposed} | |
git review -d $1 | |
git checkout $BRANCH | |
git checkout -b bp-$1 | |
git cherry-pick -x HEAD@{2} | |
git review $BRANCH | |
REMOTE=`git remote show gerrit -n | grep Fetch | cut -d'/' -f3` | |
PORT=`echo $REMOTE | cut -d':' -f2` | |
HOST=`echo $REMOTE | cut -d':' -f1` | |
SHA=`git rev-parse HEAD` | |
echo "Use the following line to approve the review" | |
echo "ssh -p $PORT $HOST gerrit review --code-review +2 --approved +1 $SHA" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment