2
votes

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?

2
Don't waste your time building walls. Your colleagues will always find a way to climb it.Álvaro González
Show them the value of informative commit messages. They don't want to be told what to do, you need to show them the benefits (what's in it for me). Putting more restrictive barriers in place will just get them angrier at you and lead to less useful content and discussion.alroc
I was hoping that the context at the beginning of the question would avoid comments like these. As mentioned, I have spoken to them multiple times and now need to get draconian.opticyclic
Eventually you will encounter a problem that you need to look at the logs to determine when a certain change was introduced, or to determine the reasons behind a certain change. When this happens, show your colleagues how useless their commit messages are to perform that task, and how much time could be saved by doing it differently. Honestly I think if you succeed in creating your pre commit hook, you'll start getting messages like "fixed more stuff", "fixed stuff again", "fix1", "fix2", "fix3", etc. You really need to convince them of the WHY or they'll continue to find ways around it.Ben
@ben I think that you should add this as an answer. Devs will stick to their current "approach" till *hit hits the fan.bahrep

2 Answers

2
votes

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.

1
votes

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