10

I am trying to create a very simple post-commit hook for a repository I have set up on my server. The script is as follows:

REPOS="$1"
REV="$2"

cd /var/www/directory && svn update --username user --password pass

When I run a commit from my SVN client, I get the following error:

post-commit hook failed (exit code 255) with no output.

However, when I run my post-commit hook from cli with sudo bash post-commit, it executes perfectly. Any ideas about what I am doing wrong?

Brendon Dugan
  • 2,138
  • 7
  • 31
  • 65

4 Answers4

6

255 means a file wasn't found, try using the absolute path to all files:

REPOS="$1"
REV="$2"

cd /var/www/directory && /usr/bin/svn update --username user --password pass

The PATH env variable of the environment in which the post commit hook is running probably isn't set to include wherever the SVN executable lives.

Peter Badida
  • 11,310
  • 10
  • 44
  • 90
chown
  • 51,908
  • 16
  • 134
  • 170
  • 1
    Hmmm... no luck. I have made this change, and verified that svn is located at /usr/bin, but I still get the same error. – Brendon Dugan Oct 20 '11 at 20:18
  • 4
    Make sure to chmod +x the hook script. I was getting "post-commit hook failed (exit code 255) with no output." I had copied post-commit.tmpl to post-commit but did not change it to be executable. – Mike Odie Nov 08 '14 at 19:22
  • Another thing to mindful of is that the server id ("apache" in my case) specifically needs execute permission to the file (either by ownership or group/world access). Personally ran into a project where my pre-commit script was group executable, but overlooked that apache was not in that project group. Since apache already owned pre-commit.tmpl, just moved that to pre-commit, as I did not want to add world execute nor hassle with managing apache's groups. – David Thompson Dec 03 '16 at 20:43
5

Ok, I have figured out the issue. It was a combination of a path issue (as suggested by chown, whose answer I will choose) and a permissions issue. I have written a blog post about the issue (as well as generally getting set up with SVN) which can be found at http://brennydoogles.wordpress.com

Brendon Dugan
  • 2,138
  • 7
  • 31
  • 65
1
  • Don't forget add #!/bin/sh in your post-commit hook.Use #!/bin/env python if you are using python
  • Make sure the permission chmod a+x post-commit
  • Make sure commands in your hook is installed and reachable.

I meet this problem when running SVN in a docker(base on ubuntu) and use a post-commit hook for my Redmine sync:

curl "http://my.redmine.ip/sys/fetch_changesets?id=myproject&key=ETji9KUfs3XxLyyr6cRN"

I got error Warning: post-commit hook failed (exit code 255) with no output.

Then I bash into my docker, run this hook manually and find out that 'curl' is not installed.

I install curl and run hook successfully, but still the same warning when commit.

After add #!/bin/sh like this:

#!/bin/sh
curl "http://my.redmine.ip/sys/fetch_changesets?id=myproject&key=ETji9KUfs3XxLyyr6cRN"

Everything is fine.

user3790229
  • 196
  • 5
1

Also if the svn server is running under apache, and the operating system is running SElinux, remember to give apache permission to run the script, as in:

% chcon -t httpd_exec_t /home/svn/repos/hooks/post-commit

Mac
  • 299
  • 2
  • 5