Created
July 29, 2015 23:53
-
-
Save mpontillo/cd0546f1b069d08246c3 to your computer and use it in GitHub Desktop.
bzr branch review script
This file contains 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 | |
function get_branch { | |
echo $1 | cut -f 3 -d '/' | |
} | |
function die { | |
echo "$@" | |
exit 1 | |
} | |
if [ "$MAAS_HOME" == "" ]; then | |
MAAS_HOME=/opt/src/maas | |
fi | |
test -d $MAAS_HOME || die "Could not find MAAS_HOME (tried: $MAAS_HOME)" | |
if [ "$1" == "" ]; then | |
echo "Usage: $0 <branch-to-review> [branch-to-merge-into]" | |
echo "" | |
echo " branch-to-review: a string in the format: p:~user/project/branch" | |
echo " branch-to-merge-into: a branch sandbox in $MAAS_HOME (\$MAAS_HOME)" | |
die | |
fi | |
cd "$MAAS_HOME" || die "Failed to change directory to $MAAS_HOME" | |
target_branch=trunk | |
if [ "$2" != "" ]; then | |
target_branch="$2" | |
fi | |
source_branch=$(get_branch $1) | |
review_branch=$target_branch-$source_branch | |
if [ -x "$source_branch" ]; then | |
echo "$source_branch: already exists: press <enter> to confirm (and delete); ^C to cancel" | |
read | |
fi | |
rm -rf $source_branch | |
if [ -x "$review_branch" ]; then | |
echo "$review_branch: already exists: press <enter> to confirm (and delete); ^C to cancel" | |
read | |
fi | |
rm -rf $review_branch | |
bzr branch "$1" || die "Failed to find review branch" | |
bzr branch "$target_branch" "$review_branch" || die "Failed to branch merge target: $target_branch" | |
cd $review_branch || die "$review_branch: directory not found" | |
bzr merge ../$source_branch && merged=1 || merged=0 | |
if [ $merged -eq 1 ]; then | |
echo "Merged into: $review_branch" | |
bzr qdiff > /dev/null 2>&1 & | |
else | |
die "Merge failed: $review_branch" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment