i'm trying to write a SVN pre-commit hook script in Linux Bash that will reject a commit if the files can not be parsed as UTF-8.
So far I have written this script:
REPOS="$1"
TXN="$2"
SVNLOOK=/usr/bin/svnlook
ICONV=/usr/bin/iconv
# Make sure that all files to be committed are encoded in UTF-8
for FILE in $($SVNLOOK changed -t "$TXN" "$REPOS"); do
if [$ICONV -f UTF-8 $FILE -o /dev/null]; then
echo "Only UTF-8 files can be committed ("$FILE")" 1>&2
exit 1
fi
# All checks passed, so allow the commit.
exit 0
The problem is that iconv requires the path to the committed files (or the text in some other form), and I don't know how to get it.
Can anyone help?
Use svnlook cat
to get the contents of a file from a transaction:
$SVNLOOK cat -t "$TXN" "$REPOS" "$FILE"