Monday, 21 October 2013

Merging the trunk to branch, the lazy way

#!/bin/sh                                                                                                                                 
${SVN_INSTALLATION?"Please set the environment variable SVN_INSTALLATION."}
SVN=$SVN_INSTALLATION
BRANCH_DIR=`pwd`
tmp=`$SVN info 2>&1 | grep SVN_ERR_WC_NOT_WORKING_COPY`
if [ -n "$tmp" ]; then
    echo "Error: The branch directory does not contain a SVN repository." >&2;
    exit;
fi
TRUNK_DIR=$1
REL_DIR=$2
if [ -z "$TRUNK_DIR" ]; then
    echo "Usage: mergeBranch <trunk directory>" >&2;
    exit;
fi
if [ ! -d "$TRUNK_DIR" ]; then
    echo "Error: Trunk directory not found." >&2;
    exit;
fi
cd $TRUNK_DIR
tmp='$SVN info 2>&1 | grep SVN_ERR_WC_NOT_WORKING_COPY'
if [ -z "$tmp" ]; then
    echo "Error: The trunk directory does not contain a SVN repository." 1>&2;
    cd $BRANCH_DIR
    exit;
fi
cd $TRUNK_DIR;
$SVN up
tmp=`$SVN info | grep "Last Changed Rev:"`
TRUNK=${tmp##*: }
cd $BRANCH_DIR
tmp=`$SVN info | grep "Last Changed Rev:"`
BRANCH=${tmp##*: }
$SVN up
WHAT=${BRANCH_DIR##*/}
echo "On the $WHAT branch: trunk revision $TRUNK merged into branch revision $BRANCH." > log.mesg
$SVN merge $REL_DIR