#!/bin/sh -e
if [ $# -ne 1 ] || [ ! -f CVS/Repository ]; then
    echo "Usage: $0 branchname"
    echo ""
    echo "Creates a new branch from the current working directory"
    echo ""
    exit 1
fi
if [ -f CVS/Tag ]; then
    basetag=`cat CVS/Tag|cut -c2-`
else
    basetag=HEAD
fi
rootdir=`cat CVS/Root|sed -e 's/.*://'`
module=`cat CVS/Repository|sed -e "s!^$rootdir!!"`
branch=`echo $1|sed -e 's/\./_/g'`
workdir=../`echo $branch|sed -e's/_/./g'`
if [ -d ../$workdir ]; then
   echo "Error! ../$workdir already exists"
   exit 1
fi
cp -rp . $workdir &
mergetag="Z-${branch}_merge_${basetag}"
cvs -z9 -q rtag -r $basetag -b $branch $module
cvs -z9 -q rtag -r $branch $mergetag $module
wait
cd $workdir
cvs -z9 update -P -d -r $branch


