0
votes

I'm a newcomer in SVN and I'm trying to write a pre-commit hook that checks commit messages on the pattern ^ABC-[0-9]+|^CONFIG:+|^MERGE:. I am using this code:

if [ `/svn/bin/svnlook log -t "$TXN" "$REPOS" | egrep -v "^ABC-[0-9]+|^CONFIG:+|^MERGE:"` ];
then
    echo ""
        exit 1
fi;

But it does not work as I need and CLs with messages like "Test- test" can be commited anyway. What is the problem?

Thank you in advance!

1
The problem is result of grep that is strings. Following will work : $SVNLOOK log -t "$TXN" "$REPOS" | egrep -q -v "^ABC-[0-9]+|^CONFIG:|^MERGE:" if [ $? -eq 0 ];user498274

1 Answers

2
votes

The script below allows to commits only with the required pattern ^ABC-[0-9]+$|^CONFIG:|^MERGE:

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

# Make sure that the log message contains some text.
SVNLOOK=/usr/bin/svnlook
$SVNLOOK log -t "$TXN" "$REPOS" | \
 grep -E "^ABC-[0-9]+$|^CONFIG:|^MERGE:" > /dev/null || exit 1

# Exit on all errors.
set -e


# All checks passed, so allow the commit.
exit 0