1

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
David
  • 157
  • 2
  • 9

2 Answers2

1

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

Should do the trick.

gnur
  • 149
  • 7
1

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.

Sven
  • 98,649
  • 14
  • 180
  • 226