We have an odd issue with SVN and its post-commit hook.
We have a number of sites, and this issue only affects one (at least that I've found). There's a post-commit hook with this code:
#!/bin/sh REPOS="$1" REV="$2" WC=/srv/www/sites/sitename date | tee -a $REPOS/hooks/log.txt cd $WC && svn update 2>&1 >> $REPOS/hooks/log.txt echo | tee -a $REPOS/hooks/log.txt
The hook runs when I commit; the directory exists; and the user it's run as has the correct permissions to access the directory (I've tweaked the code for the hook to echo both to the log file to check.)
When I su to the user, and change to the directory, I can run
svn update - it will update with the latest revision. When I do it through the hook, it won't.
I've done some poking, and discovered that when the hook is run,
svn update is triggered; but it's not doing anything with the new revision that's just been committed. I removed a file from the target directory, and commited a change - the file was restored, but from an earlier revision - the last revision I'd updated manually, in fact.
There's clearly something odd going on, but I can't figure out what. The configuration of the repository looks OK, but I don't know enough about SVN to narrow it down any further. I'd appreciate any hints anyone might have as to where to look next.
svn info gives me:
URL: file:///srv/svn/repos/sitename/trunk Repository Root: file:///srv/svn/repos/sitename Repository UUID: 8f30e7d8-358c-4aa0-ba90-4bb80c6b434e Revision: 132 Node Kind: directory Schedule: normal Last Changed Author: authorname Last Changed Rev: 132 Last Changed Date: 2013-06-17 09:47:46 -0400 (Mon, 17 Jun 2013)
The output from the logfile isn't helpful; when I just commit files, I'm seeing:
Mon Jun 17 10:05:08 EDT 2013
Which was the time the commit was last made.
svn update is not outputting anything into the log file.
I've just created a new revision - I've added a new file to my local copy of the repository, and deleted
README from the target directory. That gives me the following in the log file:
Mon Jun 17 10:11:44 EDT 2013 Restored 'README'
The revision I've just commited was 134. There's no sign of the new file , and
svn info tells me that the Last Changed Rec is still 132.
I've added some debug code to the hook, as requested:
echo $@ >> /tmp/tempfile; env | tee -a /tmp/tempfile;
/srv/svn/repos/sitename 150 OLDPWD=/ PWD=/srv/www/sites/sitename
150 is the revision I've just added.
As requested. The first one is from when I made a change and committed it (nothing was updated); the second is after I deleted a file, and committed again (the file was restored, but from an earlier version)
/srv/svn/repos/sitename 153 OLDPWD=/ PWD=/srv/www/sites/sitename /srv/svn/repos/sitename 154 OLDPWD=/ PWD=/srv/www/sites/sitename
Edit, again, again
I've created a new working directory, while logged in as www-data. I did the initial checkout as the same user; and then committed. And
svn update didn't do anything.
I'm as sure as I can be that this isn't an obvious file permission error. The hook is definitely running the
svn update command, because when I delete a file from the working directory and run a commit, it's restoring the file I deleted.
It's as though svn isn't seeing the new version. The command I'm currently using in the hook is:
REPOS="$1" REV="$2" WC=/srv/www/sites/sitename /usr/bin/svn update -r $REV "$WC" 2>&1
$1 is the right repository name.
$2 is the correct, latest, version number.
$WC is the correct directory.
- When I commit a file, the hook is run, but doesn't update (even with the -r flag set).
- When I run
svn commitas the right user, in the right directory, it updates properly
- When I delete a file from the working directory, and commit, that file is restored, but from the most recent revision run manually.
And in the interest of completness, I've also tried using older versions of the revision number. When I did
/usr/bin/svn update -r 10 "$WC" 2>&1 [that's about 140 revisions ago], it made no changes - nothing deleted, nothing added.
Update the fifth
svn update into cron did exactly the same as when it was started off by the post-commit hook; it would update to the last version I'd run
svn update for, but newer revisions would be omitted. If there were no differences between the working directory and that last version, it would do nothing. And yes, cron was being run. I tried this both as the correct user, and as root, being somewhat frustated at that point.
Additionally, I've just recreated the repo and the working directory. I added the content from my local working directory to the new repo, and it's behaving exactly the same way. Even though the setup is identical to a different development site which I set up this morning.
So I'm giving up at this point. The hassle involved in trying to fix this properly far outweighs the inconvenience of having to update it manually occasionally. Thank you all for reading this, and for your suggestions.