Sunday, November 7, 2010

Code Freeze SVN

To implement Code freeze in SVN you can write pre-commit hook script. Here is a sample script which does this job on specified paths. You please remove all echo in case implementing on production.


REPOS="$1"
TXN="$2"

echo "value of REPOS is :$REPOS"  >> /svnroot/test_repo_precommit/hooks/precommit.log
echo "value of TXN is :$TXN"  >> /svnroot/test_repo_precommit/hooks/precommit.log

REPO_URL_TO_MATCH=(
                '/svnroot/test_repo_precommit/somepath1'
'/svnroot/test_repo_precommit/somepath2'
'/svnroot/test_repo_precommit/somepath2'
);

echo "printing REPO_URL_TO_MATCH array values : ${REPO_URL_TO_MATCH[@]}"  >> /svnroot/test_repo_precommit/hooks/precommit.log

for REPO_URL_TO_MATCH in ${REPO_URL_TO_MATCH[@]}
do

echo  "in for loop print REPO_URL_TO_MATCH :$REPO_URL_TO_MATCH" >> /svnroot/test_repo_precommit/hooks/precommit.log;

RESULT1=`svnlook dirs-changed "$REPOS" -t $TXN | grep -e "$REPO_URL_TO_MATCH"`;

echo " printing value of RESULT1 : $RESULT1"  >> /svnroot/test_repo_precommit/hooks/precommit.log;

for pattern in $RESULT1
do
 if [ ! -z "$pattern" ];
echo " Value of pattern is :$pattern " >> /svnroot/test_repo_precommit/hooks/precommit.log

then
echo "*** Your commit has been blocked because code is in freezed mode, Please contact repo administrator to remove code freeze from this path."
exit 1
fi
done
echo "Exit from Loop one " >> /svnroot/test_repo_precommit/hooks/precommit.log

done
echo `date` >> /svnroot/test_repo_precommit/hooks/precommit.log
echo "*********************This is end of script************************************" >> /svnroot/test_repo_precommit/hooks/precommit.log

No comments:

Post a Comment