I am expecting the following format in the svn commit message.
Description: (some description of the change)
Entity: (change request number)
If the comment while committing doesn't follow the above format an error message should be thrown. The idea is to check for the key strings "Description" and "Entity" in the commit message. I am also checking the presence of a comment in the message.
I am using the following code but I am not able to get that check for the string "Description" working. (The check for null comment is working fine though.) Could you please tell what I might be doing wrong?
REPOS=$1
TXN=$2
LOG="/home/svn/testSVN/logs/precommithook.log"
GREP=/bin/grep
ECHO=/bin/echo
SVN="/usr/bin/svn";
SVNLOOK="/usr/bin/svnlook";
#Logs the current Transaction ID
"${ECHO}" "Transcation Id ${TXN}" >> "$LOG"
$SVNLOOK log "$REPOS" -t "$TXN" | grep "[a-zA-Z0-9]" > /dev/null
GREP_STATUS=$?
if [ $GREP_STATUS -ne 0 ]
then
"${ECHO}" "No Log comments present" >> "${LOG}"
echo "Your commit has been blocked because you didn't give any log message" 1>&2
echo "Please write a log message describing the purpose of your changes and" 1>&2
echo "then try committing again. -- Thank you" 1>&2
exit 1
fi
$SVNLOOK log "$REPOS" -t "$TXN" | grep [a-zA-Z0-9] | grep -q "Description" > /dev/null
GREP_DESCRIPTION_STATUS=$?
if [ $GREP_DESCRIPTION_STATUS –ne 0 ]
then
"${ECHO}" "Description not found in the comment" >> "${LOG}"
echo "Your commit has been blocked because you didn't give the Description in your commit message" 1>&2
echo "Please write a log message describing the purpose of your changes and" 1>&2
echo "then try committing again. -- Thank you" 1>&2
exit 1
fi
exit 0
I tried with simple grep "Description" as well as grep -w "Description" too. Still couldnt get it.