Skip to content

Instantly share code, notes, and snippets.

@luiscoms
Created May 28, 2014 20:14
Show Gist options
  • Save luiscoms/43e5c39f365db77407f3 to your computer and use it in GitHub Desktop.
Save luiscoms/43e5c39f365db77407f3 to your computer and use it in GitHub Desktop.
Script to merge an CVS project
#!/bin/sh
usage() {
mesy "Usage: "`basename $0`" -p <project> -b <branch> -t <tag>
"
}
# green
mesg() {
[ -t 1 ] && echo "\033[1;32m#####" $* "#####\033[0m" || echo -n "#####" $* "#####"
}
# red
mesr() {
[ -t 1 ] && echo '\033[0;31m#####' $* '#####\033[0m' || echo -n '#####' $* '#####'
}
# yellow
mesy() {
[ -t 1 ] && echo '\033[0;33m#####' $* '#####\033[0m' || echo -n '#####' $* '#####'
}
# blue
mesb() {
[ -t 1 ] && echo '\033[1;34m#####' $* '#####\033[0m' || echo -n '#####' $* '#####'
}
if [ -z ${CVSROOT} ]; then
mesr "Missing CVSROOT";
exit
fi
# initialize vars
PROJECT=""
BRANCH=""
TAG=""
options=':p:b:t:h'
while getopts $options option
do
case $option in
p ) PROJECT=$OPTARG;;
b ) BRANCH=$OPTARG;;
t ) TAG=$OPTARG;;
h ) usage; exit;;
\? ) mesr "Unknown option: -$OPTARG" >&2; exit 1;;
: ) mesr "Missing option argument for -$OPTARG" >&2; usage; exit 1;;
* ) mesr "Unimplemented option: -$OPTARG" >&2; usage; exit 1;;
esac
done
if [ -z ${PROJECT} ] || [ -z ${BRANCH} ] || [ -z ${TAG} ];then
if [ -z ${PROJECT} ]; then
mesr "Missing mandatory option -p <project>";
fi
if [ -z ${BRANCH} ]; then
mesr "Missing mandatory option -b <branch>";
fi
if [ -z ${TAG} ]; then
mesr "Missing mandatory option -t <tag>";
fi
usage; exit 1;
fi
mesg "=========== Merge " ${PROJECT} ${BRANCH} ${TAG}" ==========="
mesb "Checking branch and tag"
branch_and_tag=`cvs rlog ${PROJECT} 2>/dev/null | egrep "(${BRANCH}|${TAG})" | sed 's!.*\b\('${BRANCH}'\|'${TAG}'\)\b.*!\1!' | sort -u`
if test "`echo $branch_and_tag | wc -2`" -ne "2"
then
if test "`echo $branch_and_tag | grep ${BRANCH} | wc -w`" -ne "1"
then
mesr "Invalid branch"
fi
if test "`echo $branch_and_tag | grep ${TAG} | wc -w`" -ne "1"
then
mesr "Invalid tag"
fi
exit
fi
mesb "Creating paths"
mkdir -p branch-merge merge
mesb "Cleaning paths"
rm -rf branch-merge/* merge/* merge-status diff-merge diff-brach missing-files-head missing-files-branch
mesb "Entering in the directory"
cd branch-merge
mesb "Cloning branch ${BRANCH} from project ${PROJECT}"
cvs co -r ${BRANCH} ${PROJECT} 2>/dev/null
if ! [ -d ${PROJECT} ];then
mesr "Clone failed from project ${PROJECT}"
exit
fi
cd ${PROJECT}
mesb "Checking branch"
#cvs status Makefile
mesb "Verifying differences beteween branch and tag"
> ../../diff-branch
> ../../missing-files-branch
cvs diff -r ${TAG} 1>> ../../diff-branch 2>> ../../missing-files-branch
cd ../../merge
mesb "Merging the branch into head"
> ../merge-status
cvs co -j ${BRANCH} ${PROJECT} 1>> ../merge-status 2>>../merge-status
echo "Verifying all conflicts, if exists resolve manualy"
if test '`egrep -rin "(^[^U])|(conflicts)" ../merge-status | wc -l`' -ne "0"
then
mesr "Conflicts found"
egrep -rin "(^[^U])|(conflicts)" ../merge-status
exit
fi
egrep -rin "(^[^U])|(conflicts)" ../merge-status
cd ${PROJECT}
echo "Making diff again from local directory to head"
cvs diff 1> ../../diff-head 2> ../../missing-files-head
echo "Validate that everything that appears in the differences and what has changed and only what we wanted to have changed"
vimdiff ../../diff-branch ../../diff-head
vimdiff ../../missing-files-branch ../../missing-files-head
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment