Last active
December 25, 2015 16:39
-
-
Save kamranzafar/7007731 to your computer and use it in GitHub Desktop.
SVN branch merge helper script
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 | |
# | |
# Branch Merge script | |
# | |
function usage(){ | |
if [ "$#" -lt 2 ]; then | |
echo "Usage: $0 <Repository Url> <Branch Name>" | |
exit 1 | |
fi | |
} | |
function checko(){ | |
if [ "$#" -eq 0 ]; then | |
echo "Could not perform merge." | |
exit 1 | |
fi | |
} | |
function cleanup(){ | |
echo "Cleaning up..." | |
cd $1 | |
rm -rf $1/trunk | |
rm -rf $1/$2 | |
} | |
usage $@ | |
C_DIR=$(pwd) | |
TRUNK=$1/trunk | |
BRANCH=$1/branches/$2 | |
DEL_BRANCH=true | |
while getopts ":d" opt; do | |
case $opt in | |
d) | |
DEL_BRANCH=true | |
;; | |
\?) | |
echo "Invalid option: -$OPTARG" >&2 | |
exit 1 | |
esac | |
done | |
echo "Checking out $TRUNK..." | |
checko $(svn co $TRUNK) | |
echo "Checking out $BRANCH..." | |
checko $(svn co $BRANCH) | |
cd trunk | |
to=$(svn up | grep "revision" | awk '{print $3}' | cut -d '.' -f 1) | |
cd ../$2 | |
from=$(svn log --stop-on-copy | tail -5 | egrep 'r[0-9]{1,}' | awk '{print $1;}' | cut -d 'r' -f 2) | |
if [ "$from" == "$to" ]; then | |
echo "No changes found." | |
cleanup $C_DIR $2 | |
exit 1 | |
fi | |
if echo $from$to | egrep -q '[^0-9]+'; then | |
echo "Could not perform merge." | |
exit 1 | |
fi | |
cd ../trunk | |
echo "Merging branch $2 r$from:$to to trunk..." | |
checko $(svn merge -r$from:$to $BRANCH) | |
echo "Tagging current trunk revision..." | |
checko $(svn copy $TRUNK $1/tags/revision_$from -m "Tagging current trunk revision") | |
echo "Checking in trunk after merge..." | |
checko $(svn ci -m "Merged branch $2 r$from:$to to trunk") | |
echo "Merge complete" | |
if $DEL_BRANCH; then | |
echo "Deleting branch $2 after merge" | |
svn rm $BRANCH -m "Deleting branch after merge to trunk" | |
fi | |
cleanup $C_DIR $2 | |
echo "Done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment