0
votes

I need most basic hook to prevent empty comment checkins. Googled, found sample bash script. Made it short and here is what I have:

#!/bin/sh

REPOS="$1"
TXN="$2"

# Make sure that the log message contains some text.
SVNLOOK=/usr/bin/svnlook
ICONV=/usr/bin/iconv

SVNLOOKOK=1
$SVNLOOK log -t "$TXN" "$REPOS" | \
grep "[a-zA-Z0-9]" > /dev/null || SVNLOOKOK=0
if [ $SVNLOOKOK = 0 ]; then
  echo "Empty log messages are not allowed. Please provide a proper log message." >&2
  exit 1
fi

# Comments should have more than 5 characters
LOGMSG=$($SVNLOOK log -t "$TXN" "$REPOS" | grep [a-zA-Z0-9] | wc -c)

if [ "$LOGMSG" -lt 6 ]; then
  echo -e "Please provide a meaningful comment when committing changes." 1>&2
  exit 1
fi

Now I'm testing it with Tortoise SVN and here is what I see:

Commit failed (details follow): Commit blocked by pre-commit hook (exit code 1) with output: /home/svn/repos/apress/hooks/pre-commit: line 11: : command not found Empty log messages are not allowed. Please provide a proper log message. This error was generated by a custom hook script on the Subversion server. Please contact your server administrator for help with resolving this issue.

What is the error? svnlook is in /usr/bin I'm very new to Linux, don't understand what happens..

3

3 Answers

1
votes

To debug your script you'll have to run it manually. To do that you'll have to get the sample values for the parameters passed to it. Change the beginning of your script to something like

#!/bin/sh

REPOS="$1"
TXN="$2"

echo "REPOS = $REPOS, TXN = $TXN" >/tmp/svnhookparams.txt

Do a commit and check the file /tmp/svnhookparams.txt for the values.

Then do another change to the script:

#!/bin/sh

set -x

REPOS="$1"
TXN="$2"

This will enable echo of all commands run by the shell.

Now run you script directly from terminal passing to it the values you got previously.

Check the output for invalid commands or empty variable assignments. If you have problems with that, post the output here.

1
votes

$PATH is empty when running hook scripts. Thus you need to specify full paths for every external command. My guess, is that grep is not found.

0
votes

I'm answering my own question.

This didn't work:

$SVNLOOK log -t "$TXN" "$REPOS" | \
grep "[a-zA-Z0-9]" > /dev/null || SVNLOOKOK=0

It had to be 1 line:

$SVNLOOK log -t "$TXN" "$REPOS" | grep "[a-zA-Z0-9]" > /dev/null || SVNLOOKOK=0