# /usr/bin/env bash # # Determines the revision number of the next commit and replaces # the string "$REV" in CHANGES.features with it. Then it # passes all of its arguments on to "svn commit". # # Note that as we don't lock the repository there is a race # condition between determining the revision number and doing the # commit. Double-check the output; the revision number reported # at the beginning should match the one at termination. PATTERN='\$REV' CHANGES=CHANGES.features MSGTMP=bro-commit.msg # Find the CHANGES.features. for i in . .. ../.. ../../..; do if [ -e $i/$CHANGES ]; then changes=$i/$CHANGES break; fi done if [ "$changes" == "" ]; then echo Cannot find CHANGES.features. exit 1 fi count=`grep -c $PATTERN $changes` if [ "$count" == "0" ]; then echo No $PATTERN in $changes | sed 's/\\//g' exit 1 fi if [ "$count" != "1" ]; then echo More than one $PATTERN in $changes. exit 1 fi REPO=`svn info | grep 'Repository Root' | awk '{print $3}'` if [ "$REPO" == "" ]; then echo Cannot determine repository root. exit 1 fi # Extract commit message. cat $changes | awk '/^- /{msg=$0 "\n"; next;}/\$REV/{printf msg; exit;}{ msg = msg $0 "\n";}' >$MSGTMP echo Commit message in $MSGTMP: echo '------' cat $MSGTMP echo '------' revision=`svn log -r HEAD $REPO | awk 'NR==2{print substr($1, 2);}'` revision=`expr $revision '+' 1` echo Next revision is $revision echo Adapting $changes cp -f $changes $changes.bak cat $changes | sed "s/$PATTERN/r$revision/g" >$changes.tmp && mv $changes.tmp $changes args=$@ if [ "$args" == "" ]; then args="." fi svn commit $args CHANGES.features if [ "$?" != 0 ]; then echo "svn failed; restoring $changes" cp -f $changes.bak $changes exit 1 fi echo Double-check revision number: $revision rm -f $MSGTMP