0

I have a post-commit hook in svn that runs fine from the command line when I run

env - ./foo.sh /path/to/svn/repos/ 12345

but when the script is called from svn it does not appear to work.

What I am basically doing is checking the committed files and if a particular file is modified, I do an svn export of it to a network share. Works fine from the command line.

The post-commit script is as follows:

#!/bin/sh

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

CHANGED=`/usr/bin/svnlook changed -r "$REV" "$REPOS"`
SOURCE="svn+ssh://localhost/path/to/svn/repos/somefile.zip"
DEST="/mnt/build/somefile-r$REV.zip"

if [[ "$CHANGED" =~ "trunk/somedir/somefile.zip" ]]
then
        `/usr/bin/svn export --non-interactive --trust-server-cert $SOURCE $DEST`
fi

exit 0

Is there a way to output any error messages to a file when the script runs, or specifically the svn export line (where I think there might be an issue)?

1
  • for the curious, i discovered that the script, when invoked from svn, is run as the user that checked in the file(s). Switching from using the svn+ssh:// scheme to file:// instead fixed it Commented Apr 2, 2010 at 18:33

1 Answer 1

1

The standard output from a hook script is discarded, but the standard error goes back to the client, at least in recent versions of Subversion. I thought it had been like this for a while, but the svn 1.4 book says that the output is discarded, so you might like to check that you're running an up-to-date version of the server -- seeing the standard error stream is a good way to get early warning of common types of error.

To send the output from a command to a file, and include the standard error output in the file too to keep it all in one place, do

command >/path/to/logfile 2>&1

Use >> rather than > to append to the file:

command >>/path/to/logfile 2>&1

Because the standard error output is sent back to the svn client, you can also pass the information from the standard output back that way, either for a single command,

command 1>&2

or for the whole script, by putting

exec 1>&2

at the top of the script.

At a glance, I do see one issue with your script: assuming the backquotes on the svn export line are not an artefact of the markup, you should remove them. (They will execute the export command that you've written, and then take its output, and execute that output as another command -- almost certainly not what you intended.)

if [[ "$CHANGED" =~ "trunk/somedir/somefile.zip" ]]
then
        /usr/bin/svn export --non-interactive --trust-server-cert $SOURCE $DEST 1>&2
fi

(I didn't know about the double-square-bracket test syntax in bash, that's a nice new discovery for me!)

Sign up to request clarification or add additional context in comments.

1 Comment

thanks! i ended up adding "exec >> /tmp/foo.log" at the top of my script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.