1

I am trying to set up a simple pre-commit hook script that rejects commits without a message. We use VisualSVN Server 2.5.8 and I have added a pre-commit hook that points to a .bat file.

The file is executed, but the parameters for REPOS-PATH and TXN-Name are empty. In my script I have tried logging %0 to a file, and i see that this is only returning the path to the script. So for some reason VisualSVN Server does not pass these parameters. What could be wrong?

The code for the test:

@echo off

setlocal enabledelayedexpansion

set REPOS=%1
set TXN=%2

set SVNLOOK="%VISUALSVN_SERVER%\bin\svnlook.exe"


echo "repos %REPOS%." >> C:\Repositories\Hooks\test.log
echo "txn %TXN%." >> C:\Repositories\Hooks\test.log

exit 0

After a commit, test.log contains:

"repos ."

"txn ."

Community
  • 1
  • 1
Andreas
  • 1,061
  • 1
  • 11
  • 26
  • Please show the code of your hook script. – bahrep Mar 21 '13 at 11:11
  • This pre-commit hook script works on my machine. Are you able to run other hook scripts? – bahrep Mar 21 '13 at 11:54
  • 1
    Start the batch file with `echo %1 %2 &pause` to see where the problem lies, as the batch file does log correctly passed values for me. If the values aren't getting into the batch in the first place, there's no point concentrating on the .bat .... also see http://stackoverflow.com/questions/2920189/visualsvn-pre-commit-rule – AjV Jsy Mar 21 '13 at 11:57
  • 2
    Plenty of info here http://stackoverflow.com/questions/247888/how-to-require-commit-messages-in-visualsvn-server – AjV Jsy Mar 21 '13 at 12:04
  • As i wrote, i have tried outputting these values and also %0. These values do not get into the script. I have also looked plenty on the page linked to - but this page does not mention anything about my situation. – Andreas Mar 21 '13 at 17:41

2 Answers2

0

Hook scripts execute in an empty environment - no variables are set, not %PATH%, not %VISUALSVN_SERVER%. You need to specify the full path to svnlook.exe without depending upon an environment variable that hasn't been defined in your script.

For the missing %REPOS% and %TXN%, I use the following in my hooks:

set "REPOS=%~1"
set "TXN=%~2"
alroc
  • 27,574
  • 6
  • 51
  • 97
  • I doubt that your answer is correct. No env. variables get removed, in fact. – bahrep Mar 21 '13 at 15:44
  • Hooks definitely *are* executed in an environment devoid of any pre-set environment variables, [per the manual](http://svnbook.red-bean.com/en/1.7/svn-book.html#svn.reposadmin.create.hooks) – alroc Mar 21 '13 at 17:26
  • I tried using set "REPOS=%~1" and set "TXN=%~2" instead. This makes no difference – Andreas Mar 21 '13 at 17:34
  • @alroc the manual is wrong on this point. On Windows no env variables get removed. – bahrep Aug 20 '15 at 12:29
0

You can use the VisualSVNServerHooks.exe check-logmessage pre-commit hook that comes with modern VisualSVN Server versions and is located in the %VISUALSVN_SERVER%bin directory. This simple tool will help you define the minimum allowed number of characters in the log message.

See the article KB140: Validating commit log messages in VisualSVN Server for instructions.

bahrep
  • 29,961
  • 12
  • 103
  • 150