Created
September 9, 2011 15:19
-
-
Save ceronman/1206493 to your computer and use it in GitHub Desktop.
Git review
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
| #!/bin/bash | |
| set -x | |
| set -e | |
| # update master first | |
| git checkout master | |
| git pull upstream master | |
| git push origin master | |
| BRANCH=$1 | |
| PREREQUISITE=$2 | |
| REVIEW_BRANCH_NAME=_reviewbranch | |
| PREREQUISITE_BRANCH_NAME=_prerequisite | |
| if [ $BRANCH ] | |
| then | |
| parts=($(echo "$BRANCH"|tr ':' '\n')) | |
| BRANCH_REMOTE=${parts[0]} | |
| BRANCH_NAME=${parts[1]} | |
| else | |
| echo "Error: branch is not specified" | |
| exit 1 | |
| fi | |
| # delete previous review branches | |
| git branch -D $REVIEW_BRANCH_NAME | true | |
| git branch -D $PREREQUISITE_BRANCH_NAME | true | |
| git fetch $BRANCH_REMOTE $BRANCH_NAME:$REVIEW_BRANCH_NAME | |
| if [ $PREREQUISITE ] | |
| then | |
| parts=($(echo "$PREREQUISITE"|tr ':' '\n')) | |
| PREREQUISITE_REMOTE=${parts[0]} | |
| PREREQUISITE_NAME=${parts[1]} | |
| git fetch $PREREQUISITE_REMOTE $PREREQUISITE_NAME:$PREREQUISITE_BRANCH_NAME | |
| REBASE_BRANCH=$PREREQUISITE_BRANCH_NAME | |
| else | |
| REBASE_BRANCH=master | |
| fi | |
| # checkout to the new branch and rebase | |
| git checkout $REVIEW_BRANCH_NAME | |
| git rebase $REBASE_BRANCH |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
!/bin/bash
set -x -e
update master first
git checkout master
git pull upstream master
git push origin master
REVIEW_BRANCH_NAME=_reviewbranch
PREREQUISITE_BRANCH_NAME=_prerequisite
case $# in
1) BRANCH="$1";;
2) BRANCH="$1"; PREREQUISITE="$2";;
*) echo "Usage:
basename $0branch [prerequisite]" >&2; exit 1;;esac
parts=($(echo "$BRANCH"|tr : '\n'))
BRANCH_REMOTE=${parts[0]}
BRANCH_NAME=${parts[1]}
delete previous review branches
git branch -D $REVIEW_BRANCH_NAME | true
git branch -D $PREREQUISITE_BRANCH_NAME | true
git fetch $BRANCH_REMOTE $BRANCH_NAME:$REVIEW_BRANCH_NAME
if [ $PREREQUISITE ]
then
parts=($(echo "$PREREQUISITE"|tr : '\n'))
PREREQUISITE_REMOTE=${parts[0]}
PREREQUISITE_NAME=${parts[1]}
git fetch $PREREQUISITE_REMOTE $PREREQUISITE_NAME:$PREREQUISITE_BRANCH_NAME
REBASE_BRANCH=$PREREQUISITE_BRANCH_NAME
else
REBASE_BRANCH=master
fi
checkout to the new branch and rebase
git checkout $REVIEW_BRANCH_NAME
git rebase $REBASE_BRANCH