#!/bin/sh # ctg_commit # # David Adams # April 11, 2003 # Updated for ctest_gnu 20jan05 # # Commits the code in the current directory and then tags using # the content of VERSION. No action is taken if VERSION is not # present. # # Argument is the message to log with the commit. # # Extract command line options. HELP= FORCE= BRANCH= COMMIT=true TAG=true while getopts hfb: OPT; do case $OPT in h) HELP=true;; f) FORCE=true;; b) BRANCH=$OPTARG;; *) exit 1;; esac done shift $(( OPTIND - 1 )) # Display help if requested if [ -n "$HELP" ]; then echo Usage: $0 [ -f ] '"log message"' echo " -f forces commit even if version is not changed" echo " -b brname tags changes on branch brname" echo " (First create branch with \"cvs rtag -b brname my_module\")" exit 0 fi # Fetch the log message. if [ "$#" -eq 0 ]; then echo Log message must be provided exit 1 fi MSG=$* # Fetch the package name REP=CVS/Repository if [ ! -r $REP ]; then echo Unable to find $REP exit 2 fi PKG=`cat $REP` if [ $? != 0 -o -z "$PKG" ]; then echo Unable to parse $REP exit 3 fi # Check if there are any changes in the package. if [ `cvs diff > /dev/null 2>&1; echo $?` = 0 ]; then echo "Package $PKG is unchanged: modify VERSION to force tag" exit 0 fi # Fetch the version if [ ! -r VERSION ]; then echo Unable to read VERSION exit 4 fi ## if version is unchanged... if [ `cvs diff VERSION > /dev/null 2>&1; echo $?` = 0 ]; then if [ -n "$FORCE" ]; then echo WARNING: Continuuing with VERSION unchanged else echo Modify VERSION before commiting changes exit 5 fi VERSIONCHANGE= else VERSIONCHANGE=true fi VERSION=`cat VERSION` if [ $? != 0 -o "$VERSION" = "" ]; then echo Unable to parse VERSION exit 6 fi # Record the new version. CHFILE=doc/changes.txt if [ -r $CHFILE ]; then mv $CHFILE $CHFILE.tmp if [ -n "$VERSIONCHANGE" ]; then echo "$VERSION "`date +"%d%b%y %H%M"`" - $MSG" > $CHFILE.ver else echo " "`date +"%d%b%y %H%M"`" - $MSG" > $CHFILE.ver fi cat $CHFILE.ver $CHFILE.tmp > $CHFILE rm $CHFILE.ver $CHFILE.tmp else echo $CHFILE not found -- change not recorded exit 7 fi # Commit changes. COMMITDONE= if [ -n "$COMMIT" ]; then echo echo Committing... cvs commit -m "$MSG" STAT=$? if [ $STAT != 0 ]; then echo Commit failed with error $STAT exit 8 fi COMMITDONE=true fi # Tag. TAGDONE= TVERSION=v`echo $VERSION | sed 's/\./-/g'` if [ -n "$TAG" ]; then echo if [ -n "$VERSIONCHANGE" ]; then echo Tagging... if [ -n "$BRANCH" ]; then cvs rtag -r $BRANCH $TVERSION $PKG else cvs rtag $TVERSION $PKG fi STAT=$? if [ $STAT != 0 ]; then echo Tag failed with error $STAT exit 8 fi TAGDONE=true else echo Version unchanged -- tag not applied fi fi echo # Display commit and tag status echo -n Changes to package $PKG if [ -z "$COMMITDONE" ]; then echo -n " not" fi echo -n " committed and" if [ -z "$TAGDONE" ]; then echo " not tagged" else echo " tagged $TVERSION" if [ -n "$BRANCH" ]; then echo " Tag applied to branch $BRANCH" fi fi