I am having some issues getting post-commit hooks to work. Subversion doesn't appear to be triggering my post-commit hook when I commit a changed file to my repository.
I am using TortoiseSVN and VisualSVN with Subversion, I was able to go into the VisualSVN user interface and create a hook within there that worked however what I would like to do is use the post-commit executable hook in the hooks folder of my installation to execute my hook.
I have changed the name from post-commit.tmpl
to post-commit.bat
in the /hooks folder of my repository and am just doing a simple update within the batch file:
"C:\Program Files\TortoiseSVN\bin\svn.exe" update "C:\mypath\myworkingcopy"
When I run the batch file on its own it updates my working folder so I am thinking it is not being triggered when I commit for some reason. It doesn't appear to be a permissions issue since everything is being done locally on my machine however I have set it to run as a network service but still experience the same problem...any suggestions?
First of all, all hooks are executed on the SERVER and not on the various client machines. Is that
C:\mypath\myworkingcopy
on the server? If not, it's not going to get updated.Second of all, it's bad form to do anything in a hook that might take too much time. If your hook needs something more than
svnlook
, chances are you're doing it wrong. For example, how long could it take to update that working copy? 10 seconds? 30 seconds? a minute? That's the added time a developer has to sit and wait for their Subversion commit to complete.It is much, much better to use something that can respond to commit events and have that do things like working copy updates or deployments to web servers outside of a post-commit hook. I highly recommend Jenkins for this job. Jenkins has several nice features:
Now back to your question:
First make sure the hook is running. Add to the bottom of the batch script this one line:
That will make Subversion think the post-commit hook has failed and you should get an error message on commit. If not, your post-commit script isn't running. Make sure the script is executable by the account that's running the Subversion server.
If you do get an error message, the script is running. However, the svn command may not be returning an error that's getting picked up by the post-commit process. I normally don't recommend writing hooks in Windows batch programming language because of its limitations. Use Python or Perl or PowerShell. These are better at detecting error conditions and you can exit out of your script when detected.
Then again, things are working perfectly, but you're looking at the wrong working copy (the one on your machine and not the one on the server). When you run hooks outside of the subversion server for testing, run them on the server as the Subversion user running the server process.
Try these things and see if that corrects your problem.
Additional Comments
I created a repository with
svnadmin create
and ran it usingsvnserve
. I updatedsvnserve.conf
to allow me to checkout and commit code.I went into the
hooks
directory, renamedpre-commit.tmpl
topre-commit.bat
and set it as:When I attempted to commit my changes, I got:
The hook is supposed to remove the environment (including the PATH), but I guess that's only on Unix and not Windows. You can see
PATHEXT
defined.I then renamed
pre-commit.bat
topre-commit.tmpl
and created a post-commit.bat` that looks like this:During a commit, I got the following:
It looks like everything is working as planned. I'm not using VisualSVN, and I'm not running as a service. I wonder if there might be an issue with your
PATHEXT
environment variable.Maybe take a look how it is set on your account that's running the Subversion server and see if
.BAT
is in there.I can't think of anything else right off hand.
Extended version of David's answer
echo ANYTHING
and on commit from CLI you must to see ANYTHING output'ed to screen (in case of TSVN in will be in commit window)>svn up "z:\wc"
Updating 'wc':
At revision 3.
Edits and fixes
Thanks to David for mentioning my idiotic errors and refreshing memory. While bahrep's version with file-logging will work, this type of post-commit hook (in post-commit.bat)
transmit all hook's output to screen on commit
I had the same problem when doing
post-commit.bat
. I figured Subversion on Windows runs post-commit when the script has.exe
as extension.Try compiling your batch post-commit into executable with Bat2Exe or bat2exe.net and see if that runs.
I almost got crazy with this, my problem was that the exit 2, was not sending anything in the post-commit to my svn client. It was working good in the start-commit, pre-commit, but in the post-commit, i was never getting any error. So my main problem was just the full path calls in the script itself.
So if it seems to you that the post-commit is never working, and you tried the exit 1 in the script and you are getting no errors, try something like this:
Provide Network Service account with access to the working copy's folder
C:\mypath\myworkingcopy
and toC:\Program Files\TortoiseSVN\bin\svn.exe
.If it does not work, then let's capture the hook output to a log file to get some clues on the root cause:
post-commit.bat
file topost-commit-run.bat
.post-commit.bat
file: