Hi!
This is no question. I just want to put this script into the net. Maybe it helps others too. I found it under the same topic name and made some changes (enhancements I would say :-)).
It helps that users enters comments and should prevent the tags folder from changes. Sometimes someone checksout the tags folders, makes a change and commits the change (what hopefully wasn't his intention).
The deletion of tags folders is allowed because people sometimes want to clean up old tags. And it's allowed to have a tags folder in your project beneath trunk and branches. Here a changes allowed.
This script has a weakness: it uses svnlook cat to determine wheter a change entry is a file or a directory. Mabay there is a better way to do this. When someone has a better solution for this it would be nice to mail it.
Have fun!
Two files a used:pre-commit and pre-commit.awk
File pre-commit:
#!/bin/sh
#taken from
#base idea taken from http://svn.haxx.se/users/archive-2005-11/0056.shtml
########################
# repository
########################
DIRNAME=`dirname $0`
REPOS="$1"
# Transaction
TXN="$2"
#svnlook binary
LOGFILE=/tmp/tx-svn-pre-commit-hook.txt
#LOGFILE=/dev/null
PATH=/usr/bin:/usr/local/bin:/opt/svn/product/svn/bin
AWK=gawk
########################
#debug
########################
transaction=`svnlook -t $TXN changed $REPOS` 2>&1
author=`svnlook author $REPOS`
echo "###################" >> $LOGFILE
echo "pre-commit executed `date`" >> $LOGFILE
echo "DIRNAME:$DIRNAME" >> $LOGFILE
echo "PATH:$PATH" >> $LOGFILE
echo "REPOS:$REPOS" >> $LOGFILE
echo "TXN:$TXN" >> $LOGFILE
echo "author:$author" >> $LOGFILE
echo "transaction:" >> $LOGFILE
echo "$transaction" >> $LOGFILE
##########################
# user 'god' can do anything
##########################
# User=`svnlook author -t $TXN $REPOS`
# if ( $User == "god" ){ exit 0 }
#################################
# Log message contains some text.
#################################
logmsg=`svnlook log -t $TXN $REPOS`
echo "logmsg:$logmsg" >> $LOGFILE
svnlook log -t $TXN $REPOS | \
grep "[a-zA-Z0-9]" > /dev/null || { echo "Please write a meaningful comment!" >&2 ; exit 1 ; }
########################
# Protect tags directory
########################
# Deny transaction if any line writes to tags directory that exists.
# Get list of transactions in the 'tags' directory
TAGS_CHANGES=`svnlook changed -t $TXN $REPOS 2>/dev/null | \
$AWK -f $DIRNAME/pre-commit.awk 2>/dev/null`
echo "TAGS_CHANGES:" >> $LOGFILE
echo $TAGS_CHANGES >> $LOGFILE
# Get head revision number
YOUNGEST=`svnlook youngest $REPOS 2>/dev/null`
echo "YOUNGEST:$YOUNGEST" >> $LOGFILE
# For every line in transaction,
# check to see if directory in tags exists
for CHANGE in $TAGS_CHANGES; do
CHANGE=`echo $CHANGE | sed -e "s/#!#/ /g"`
echo "CHANGE:$CHANGE" >> $LOGFILE
ERRORTEXT="Cannot modify existing tag: $CHANGE"
# If directory in tags exists, deny transaction
if svnlook proplist -r $YOUNGEST "$REPOS" "$CHANGE" >/dev/null 2>&1 ;
then
#echo "then branch" >> $LOGFILE
#changes on directories should be allowd but not on files
#svnlook cat -t $TXN $REPOS "$CHANGE" >> $LOGFILE 2>&1
#echo "exitstatus:$?" >> $LOGFILE
svnlook cat -t $TXN $REPOS "$CHANGE" > /dev/null 2>&1 && \
{ echo "$ERRORTEXT" >&2 ; exit 1 ; }
else
# don't allow adding/deleting a file
#svnlook cat -t $TXN $REPOS "$CHANGE" >> $LOGFILE 2>&1
#echo "exitstatus:$?" >> $LOGFILE
svnlook cat -t $TXN $REPOS "$CHANGE" > /dev/null 2>&1 && \
{ echo "$ERRORTEXT" >&2 ; exit 1 ; }
echo "exitstatus:$?" >> $LOGFILE
fi
done
#######################
# Allow transaction
#######################
exit 0
File pre-commit.awk:
/ tags\/|\/tags\// {change=substr($0,5);
changecount=gsub(" ","#!#",change);
if ($0 !~ /trunk|branches/)
print change;
}
--
GMX DSL: Internet-, Telefon- und Handy-Flat ab 19,99 EUR/mtl.
Bis zu 150 EUR Startguthaben inklusive! http://portal.gmx.net/de/go/dsl
Received on 2010-06-09 16:20:33 CEST