First time I'm doing an hook like this..
I need a pre-commit hook that scan all the java classes to commit, it should check for the presence of some character into the class and avoid the commit if found some of them, chars like † or ¥ and so on, i think a good way to make this dynamically change could be put all these invalid chars into a plan file in order to change it easily if we need to...
I'm starting from a simple hook that i wrote long time ago..
Now the BIG problem is getting the location of the working copy files.. The one I should scan the content.
I tried many svnlook commands, but I'm really unable to catch this information into the pre-commit hook....
Getting a lot of information but not the local path of the file. I'm using this to scan for content...
OUTPUT="$($SVNLOOK changed -t $TXN $REPOS)"
echo $SVNLOOK changed -t $TXN $REPOS 1>&2
echo "$BASEDIR" 1>&2
echo "${OUTPUT}" 1>&2
echo "$TXN $REPOS" 1>&2
Maybe it is my approach that is wrong?
Thanks a lot!
UPDATED
Thanks "CaffeineAddiction", you know it is always a "BIG QUESTION" when you do something for the first time.
In reality, the real issue in the end, after one day of attempts was another one, a SVN Bug related to the client char coding:
Error output could not be translated from the native locale to UTF-8
Now also this last issue is solved and the script works as well, you can see it below, it just need to be beautified, by the way thanks for yours, i'll get some ideas from yours:
REPOS="$1"
TXN="$2"
SVNLOOK=/usr/bin/svnlook
OUTPUT="$($SVNLOOK changed -t $TXN $REPOS | awk '{print $2}')"
for LINE in $OUTPUT
do
FILE=`echo $LINE`
MESSAGE=`$SVNLOOK cat -t "$TXN" "$REPOS" "${FILE}"`
echo "File is: $FILE" 1>&2
echo "${MESSAGE}" > /tmp/app.txt
grep -P -n '[\x80-\xFF]' /tmp/app.txt | cut -f1 -d: 1>&2
done
This is not a full answer, but it might be enough to get you headed in the right direction. A while back I was asked to run gjslint against javascript files before allowing them to be checked into SVN. Here is the pre-hook I used for the task:
#!/bin/sh
SVNLOOK=/usr/bin/svnlook
GJSLINT=/usr/local/bin/gjslint
ECHO=$(which echo)
GREP=$(which grep)
SED=$(which sed)
## Used for Debug
#MYRUNLOG=/run/svn-pre-commit/pre-commit.log
#touch $MYRUNLOG
#echo "" > $MYRUNLOG
MYTEMPJS=/run/svn-pre-commit/temp.js
touch $MYTEMPJS
echo "" > $MYTEMPJS
MYTEMPLOG=/run/svn-pre-commit/gjslint.log
touch $MYTEMPLOG
echo "" > $MYTEMPLOG
REPOS="$1"
TXN="$2"
FILES_CHANGED=`$SVNLOOK changed -t$TXN $REPOS | $SED -e "s/^....//g"`
LINTERROR=0
for FILE in $FILES_CHANGED
do
if $ECHO $FILE | $GREP "\.js$"
then
if ! $ECHO "$REPOS/$FILE" | $GREP "/paweb5/\|/pamc/"; then exit 0; fi
if $ECHO "$REPOS/$FILE" | $GREP "/doc/"; then exit 0; fi
if $ECHO "$REPOS/$FILE" | $GREP "/docs/"; then exit 0; fi
$SVNLOOK cat -t$TXN $REPOS $FILE > $MYTEMPJS
$ECHO "$REPO/$FILE" >> $MYTEMPLOG
$GJSLINT --strict --disable 0001 $MYTEMPJS >> $MYTEMPLOG
GJSL_ERROR_CODE=$?
if [ $GJSL_ERROR_CODE != 0 ]
then
LINTERROR=1
fi
$ECHO "~~~" >> $MYTEMPLOG
fi
done
if [ $LINTERROR != 0 ]
then
echo "..........................................................................." >&2
while read line; do
if $ECHO $line | $GREP "Line\|no errors\|new errors\|paweb5\|~~~"
then
echo $line >&2
fi
done < $MYTEMPLOG
echo "..........................................................................." >&2
exit 1
fi
# If we got here, nothing is wrong.
exit 0
I believe the answer to your "BIG problem" getting the location of the working copy files might lie within $SVNLOOK cat -t$TXN $REPOS $FILE > $MYTEMPJS
If you have questions about the script feel free to ask
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With