0

I'm new to Apache SVN and I need some help to use a pre-commit script to filter which files are being upload to my repository.

I was searching a lot and found this script on another question, but it didn't work for me.

#!/bin/bash

REPOS=$1
TXN=$2
AWK=/usr/bin/awk
SVNLOOK="/usr/bin/svnlook";

#Put all the restricted formats in variable FILTER
FILTER=".(sh|xls|xlsx|exe|xlsm|XLSM|vsd|VSD|bak|BAK|class|CLASS)$"

# Figure out what directories have changed using svnlook.
FILES=`${SVNLOOK} changed -t ${REPOS}  ${TXN} | ${AWK} '{ print $2 }'` > /dev/null

for FILE in $FILES; do

#Get the base Filename to extract its extension
NAME=`basename "$FILE"`

#Get the extension of the current file
EXTENSION=`echo "$NAME" | cut -d'.' -f2-`

#Checks if it contains the restricted format
if [[ "$FILTER" == *"$EXTENSION"* ]]; then
echo "Your commit has been blocked because you are trying to commit a restricted file." 1>&2
echo "Please contact SVN Admin. -- Thank you" 1>&2
exit 1

fi

done
exit 0

If I try to use svnlook changed -t repodirectory it didn't work because had a missing subcommand. I overwrote my pre-commit.tmpl but it didn't work, can someone help me?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

1 Answers1

0

First - seems you incorrectly use svnlook. It should has parameters:

svnlook changed ${REPOS} -t ${TXN}

-t means 'read from transaction' and TXN - transaction name itself.

Second - not sure if I understand correctly, but hook file should has name pre-commit not pre-commit.tmpl

Third - pre-commit should has correct rights. For tests try a+rwx


update. It is not easy to obtain transaction object for tests, but you can use svnlook -r <revision> <repositiry_path> and experiment on already commited revisions.

Sergey Azarkevich
  • 2,641
  • 2
  • 22
  • 38
  • It worked, I didn't know that the extension .tmpl was for "templates". I can restrict the uploads now, but if i have a restricted file in my commit the whole commit will be blocked. – Iván Vega Jun 22 '15 at 09:06