Reputation: 8116
My colleagues are very stubborn. At the beginning they would commit with no message so I tried to educate them and put in a pre-commit script to check for empty in case they forget. They would then put in messaged like "fixed" so I spoke to them again and updated the script to force it to link to the bug tracker. Now they are putting in the same commit message 8 times in a row for the same file (Bug ID: Bug Title).
After I talk to them about how this isn't helpful, how can I make a pre-commit hook that checks that the commit message isn't identical to one of the last 20 commit messages?
Upvotes: 2
Views: 381
Reputation: 8905
You can use SVN commands or any other shell command in pre-commit hooks. You just need to provide full paths to the installed tools. Remember this is running on the server so it has file:// access to the repository. So do an svnlook log
(preferred) or svn log
and check the resulting output for a match for the current log message.
Upvotes: 2
Reputation: 8116
svnlook has 2 options that combined together can sort this out.
svnlook log http://svnbook.red-bean.com/en/1.7/svn.ref.svnlook.c.log.html
svnlook youngest http://svnbook.red-bean.com/en/1.7/svn.ref.svnlook.c.youngest.html
Youngest gets the head revision. I then echo the last 20 commits to an temp. file and use grep to search for the commit message in the temp. file.
The grep options are F for using a file as input, x to match a whole line and q for quiet.
#Prevent people putting in the same commit message multiple times by looking for an identical message in the last 20 commits
ID=$(svnlook youngest $REPOS)
COMMITS=/tmp/svncommits.txt
rm $COMMITS
for (( i=$ID-20; i<=$ID; i++ ))
do
echo $(svnlook log $REPOS -r $i) >> $COMMITS
done
if $(grep -Fxq "$COMMIT_MSG" "$COMMITS") ; then
echo "Please describe what your change is, why you made it and don't use the same commit message every time." 1>&2
exit 1
fi
Upvotes: 1