1
votes

i'm trying to set up a svn post-commit hook on a windows server, so that every time a commit is made, it is connected to an issue of an existing project on my bug tracking website.

since there is no pre made post-commit hook for windows (or at least i haven't find one that would fit my needs), i tried to write the batch file for myself.

SET REPOS=%1
SET REV=%2
SET SVNLOOK="C:\Program Files (x86)\VisualSVN Server\bin\svnlook.exe"
SET PROJECT=3

%SVNLOOK% log -r %REV% "%REPOS%" > COMMIT_MSG
SET /p COMMIT_MSG= < COMMIT_MSG
echo %COMMIT_MSG%

C:\curl\bin\curl "http://www.mybugtrackingsite.de/vcs_integration/report/%PROJECT%/?passkey=KEY" --data-urlencode "msg=%COMMIT_MSG%"

when i'm setting REPOS and REV by myself and run the script from the command line it works, but when i make a commit it doesn't work and my COMMIT_MSG only contains "echo is on" instead of the actual message.

i've read, that the svn repository executes hook programs with an empty environment, means that no environment variables are set at all and that could be why my script runs fine by hand and not when run by svn.

but what variables do i have to set and how? my paths are already absolute, so that shouldn't be the problem. i'm not a windows guy and am not really into batch - so any help or ideas how i get this thing to work would be appreciated!

2
You are setting both REPOS and REV to the same thing: the first argument. This is actually the repository path. Is this just a typo or does your script actually do that? I bet that causes some problems. You would need to either use %2 or run a shift between setting the two variables.Ben
You can start by calling it batch not bash (that's for *nix).Slav
yeah that was actually just a typo. in my script it says %1 and %2, fixed it in the question, sorry for thatc7n

2 Answers

0
votes

When you redirect the commit message to the file you use a relative path 'COMMIT_MESSAGE'.

%SVNLOOK% log -r %REV% "%REPOS%" > COMMIT_MSG

The working directory which is used by the svn hook may not be the same as yours and the svn process has not the rights to write at this location. You may use an absolute path.

You can also try to redirect STDERR to see if you get an error from svnlook.

Also delete the file at the beginning of the hook script to ensure that you don't use a file from a previous run.

0
votes

Your are setting both REPOS and REV to %1. One of them should be %2

You should also place @ECHO OFF at the top of the file to avoid unnecessary output on screen