Is there a way for me to simplify this pre-commit hook? It seems a bit much to me

#!/bin/sh
message=`$SVNLOOK log -t "$TXN" "$REPOS"`

# Block any commits which don't reference a ticket
if echo $message | grep -q "re #"
then
    :
elif echo $message | grep -q "references #"
then
    :
elif echo $message | grep -q "refs #"
then
    :
elif echo $message | grep -q "see #"
then
    :
elif echo $message | grep -q "addresses #"
then
    :
else
    echo "Your commit must reference a ticket to be accepted. For example, re #1234"
fi
link|improve this question
feedback

2 Answers

up vote 1 down vote accepted

For this, you could use either gnur's variant or use a pattern file:

grep -q --file="matchpatterns.txt" 

which would contain every pattern you want to accept:

refs #
addresses #
ticket #
bug #
...

I like this more because this kind of list tends to become long very quick, making the inline pattern difficult to manage.

link|improve this answer
This is definitely the simplest and easiest to maintain! – David Sep 12 '11 at 1:31
feedback

if echo $message | grep -q '\(re\|references\|refs\|see\|addresses\|\) #'

Should do the trick.

link|improve this answer
very nice, I should have known that regex has OR syntax! – David Sep 12 '11 at 1:31
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.