I am new to Linux as well as for Subversion. I had a task to check the syntax of the commit message to contain PRODUCT ID. If its not present I have pass a message to user saying an invalid format using SHELL SCRIPT.
Below are the steps I had followed after a lot search in google,
For the PRE-COMMIT hook the code is:
#!/bin/sh
set -e
/PATH-TO-REPOSITORY/hooks/CommentSyntax.sh "$1" "$2"
My CommentSyntax.sh script is,
#!/bin/sh
REPOS="$1"
TXN="$2"
SVNLOOK=/usr/bin/svnlook
regex="PRODUCT-[0-9]*"
if [ `"$SVNLOOK" log -t "$TXN" "$REPOS"` =~ ${regex} ]; then
exit 0
else
echo "" 1>&2
echo "Please make your commit comment start with PRODUCT-XXX" 1>&2
exit 1
fi
Whenever I am trying to check-in the code, am getting the below error,
srikanth:~/testing$ svn ci -m "PRODUCT-123"
Sending two.java
Transmitting file data .svn: Commit failed (details follow):
svn: Commit blocked by pre-commit hook (exit code 1) with output:
[: 22: PRODUCT-123: unexpected operator
Please make your commit comment start with PRODUCT-XXX
I am not sure where I gone wrong. Request your valuable advice on the same.
The test command knows no
=~operator. Relpace theline by
head -n1select the first line of the commit,grepchecks the regexp.