Subversion post-commit hook to update dev site is not working

Hi all,

I have successfully set up a subversion repository using the Virtualmin functionality and have checked out a working copy to my local system here.

Now, I want to to set up a post-commit hook to update my dev site every time a set of changes is committed by myself or one of my developers.

I cannot believe this is so difficult achieve, as without this, I fail to see the point of subversion;s existence at all.

I am committing changes through a subversion client (Versions on Mac OS X or SmartSVN on Windows). The problem is, whenever I attach a post-commit script, the commit throws an error:

Commit failed (details follow):
MERGE of '/svn/irbsandc.com/content': 200 OK (http://irbsandc.com)

I have tried running the post-commit hook in two ways: firstly, by running this:

/usr/bin/svn update /home/irbsandc.com/domains/dev.irbsandc.com/public_html >> /home/irbsandc.com/logs/subversion_log

And, suspecting that the problem may have something to do with the user performing the operation not having appropriate privileges, I compiled an executable binary as instructed here:
http://www.frenssen.be/content/using-subversion-automatically-update-live-website
and ran this:

/home/irbsandc.com/svn/autoupdate/autoupdate

where autoupdate is a compile of this

#include <stddef.h>
#include <stdlib.h>
#include <unistd.h>
int main(void)
{
  execl("/usr/bin/svn", "svn", "update",
"/home/irbsandc.com/domains/dev.irbsandc.com/public_html/",
        (const char *) NULL);
  return(EXIT_FAILURE);
}

In both cases, running the same code from the command line when logged in as the user who owns the domain, runs fine with no errors at all and the dev site is immediately updated.

When I look in the error log for my irbsandc.com domain, I see this:

user apache not found: /svn/irbsandc.com

every time the commit is attempted.

One other thing I should add - the commit does in fact succeed, even though it throws the error, so the amended files do make it into the respository. But then I have to run an update before I can continue working, and then run the update manually… and I end up wishing I was still using good old FTP.

Any help would be sincerely appreciated.

One further piece of info - the Virtualmin generated ‘auto email’ post-commit hook runs fine after a commit from the Subversion client.

I even tried just sneaking my line in on the end of that script… but no, that brings back the error.

OK, I got this.

The errors were occurring because my SVN client was accessing the repository over the http protocol, and it must be the case that over that protocol, while you can run a script which generates a notification email (as Virtualmin will generate for you) you can’t run an svn update.

As soon as I re-jigged by repository settings in my SVN client and checked out the project over svn+ssh, the post-commit ran fine.

I will add here, for anyone finding this thread who is trying to do the same thing, that you will read many postings here and there which suggest that to run an svn update automatically you have to create a compiled binary, so that the process runs as the owner of the domain rather than as apache.

In the Virtualmin environment, I have found this not to be the case, and I am guessing that this is because my virtual server is set to run CGI scripts as domain owner. Therefore, there is no conflict between the user running the commit and the user who is needed to run the post-commit hook.

So, the following is sufficient to perform an automatic update of a dev site when a change is committed to the repository by a developer:

#!/bin/sh
/usr/bin/svn update /home/irbsandc.com/domains/dev.irbsandc.com/public_html >> /home/irbsandc.com/logs/subversion_log

(The second part of that line being an instruction to update a log file I created in the logs folder of the virtual server.)