tags:

views:

362

answers:

3

Hi folks, I've been googling this stuff all day, and while I get tons of results, nothing seems to help me resolve the problem.

I've installed SVN on my remote Apache server. I set up my repository, and added all of my code files. No problem. I installed TortoiseSVN on my local windows machine, and can check out and commit files without issue. I've also checked out the files on the remote server, as the project is a web site. I want to do a post commit hook, so that every time I commit, the remote server's working directory does an update. I made a copy of post-commit.tmpl in the hooks directory, and set the executable flag for all users. My problem is that every time I do a commit via TortoiseSVN, I get back the following error:

post-commit hook failed with error output:

Never mind for the moment the actual contents of post-commit--it's simply not executing. I've been reading all these posts about users, groups, permissions, etc, and I just can't seem to get the big picture. A lot of folks mention that the post-commit must be owned by the same user that runs apache, or something like that. I need details! If true, exactly how do I find out which user and group is running Apache? Is that the end of the story? What about the credentials I use to commit to SVN via TortoiseSVN? Do they matter? Is it just the permissions and user on post-commit that matters, or is it the whole svn installation?

I've tried setting the owner of the entire svn working directory (hooks and all) to every conceivable combination I can think of (apache.apache,root.root,root.psaserv,apache.root), on and on. For the moment I'm using root/rootpassword as my Tortoise credentials.

Here's the contents of my hooks directory:

-rwxr-xr-x 1 apache apache 2061 Feb  2 18:04 post-commit
-rw-r--r-- 1 apache apache 2015 Feb  2 07:44 post-commit.tmpl
-rw-r--r-- 1 apache apache 1638 Feb  2 07:44 post-lock.tmpl
-rw-r--r-- 1 apache apache 2255 Feb  2 07:44 post-revprop-change.tmpl
-rw-r--r-- 1 apache apache 1567 Feb  2 07:44 post-unlock.tmpl
-rw-r--r-- 1 apache apache 2934 Feb  2 07:44 pre-commit.tmpl
-rw-r--r-- 1 apache apache 2038 Feb  2 07:44 pre-lock.tmpl
-rw-r--r-- 1 apache apache 2764 Feb  2 07:44 pre-revprop-change.tmpl
-rw-r--r-- 1 apache apache 1979 Feb  2 07:44 pre-unlock.tmpl
-rwxrwxrwx 1 apache apache    0 Feb  2 19:48 sanity.txt
-rw-r--r-- 1 apache apache 2137 Feb  2 07:44 start-commit.tmpl
-rwsr-sr-x 1 root   root   4802 Feb  2 14:32 svnupdate
-rw-r--r-- 1 apache apache  212 Feb  2 14:32 svnupdate.c

I'm at my wit's end, folks. Please, help a poor Linux newbie out!

A: 

Below are the first few lines of post-commit.tmpl from svn.apache.org

#!/bin/sh
# POST-COMMIT HOOK
#
# The post-commit hook is invoked after a commit. Subversion runs
# this hook by invoking a program (script, executable, binary, etc.)
# named 'post-commit' (for which this file is a template) with the
# following ordered arguments
#
# [1] REPOS-PATH (the path to this repository)
# [2] REV (the number of the revision just committed)
#
# The default working directory for the invocation is undefined, so
# the program should set one explicitly if it cares

The first line tells the shell this is a shell script and gives the path to /bin/sh as the interpreter for this script. The error message you're seeing means the shell can't find the interpreter. Try running

which sh

To check where sh is.

I asked you to unset PATH because a lot of common hook script errors relate to path issues.

Sam Post
when I type "which sh", the result is: "/bin/sh"
Max L
+2  A: 

You might be better able to diagnose it if you run it as follows:

$ unset PATH
$ <your_svn_repo>/hook/post-commit <your_svn_repo> <some_revision_number>

SVN's commit hooks run in a very constrained environment with nothing on the execution path, so you have to make sure that every script you write can be run that way as well.

Following up on your comment, what I believe is happening is that the first line in your file has a Windows line ending, not a unix one. Probably you edited the file in Notepad or some other Windows editor that isn't smart about line endings.

Probably your fastest route to getting it working (and this assumes that you're running on Linux or a system with dos2unix installed) is, at a command prompt:

dos2unix /var/www/vhosts/example.com/svn/hooks/post-commit

If there's no dos2unix command, then try opening the post-commit hook in an editor that lets you change line endings (on Windows, I believe that Notepad+ will, but I'm not a Windows guy) like Emacs, TextMate, or Vim, and remove the extra character at the end of the first line (and probably, all other lines).

Chris R
when I type this: "/var/www/vhosts/example.com/svn/hooks/post-commit /var/www/vhosts/example.com/svn 1" I get back this: "-bash: /var/www/vhosts/example.com/svn/hooks/post-commit: /bin/sh^M: bad interpreter: No such file or directory"
Max L
Looks like your shell script has Windows line endings instead of unix. Fix that.
larrys
I learned this from the other response... I type "which sh", and get back "/bin/sh". When I go into /bin and type "ls -la sh", I get "lrwxrwxrwx 1 root root 4 Oct 10 2008 sh -> bash". Does it matter that this file is owned by root.root, and post-commit is owned by apache.apache? The first line of post-commit is indeed #!/bin/sh
Max L
Windows line endings? Hmm, now that's an interesting angle. I'll look into that...
Max L
I misread your initial comment, and re-edited my answer to reflect the likely real problem. My bad for the initial off-the-cuff bad answer.
Chris R
It was the windows line endings! Thank you so much!
Max L
Feel free to upvote and accept the answer, if that's the case. Please see http://stackoverflow.com/faq#reputation for details
Chris R
A: 

As pointed out by larrys, my post-commit script had windows line endings (I was editing in notepad++, and uploading via FTP). I fixed this by opening the file in VIM and typing

:set fileformat=unix
Max L