سؤال

I am writing a post-commit hook that publishes certain files to a webserver if they are changed.

I want to make it clear to the client / user what happens after he commited.

Thats why I added echo commands returning information to the client.

I read this post : SVN post-commit hook sending a message back to client which says that post commit hooks can only return information if I use exit 1.

This works great but it confuses clients because this message appears:

Warning: post-commit hook failed (exit code 1) with output:

Is there a way to circumvent this output?

If it helps, my script so far:

echo "Everything OK. Checking if publishing dir was changed." >&2

svn status /var/www/dev/test/public/projektbereich1/http | grep [AMCDG]
if [ $? -eq 0 ]  ; then
    echo "Dir has changed. Publishing files." >&2
cp -R /var/www/dev/test/public/projektbereich1/http /var/www/public/

else
    echo "Dir has not changed. Webserver does not get updated." >&2
fi

exit 1
هل كانت مفيدة؟

المحلول 3

thanks to Stephane i searched for the meaning of 2>/dev/null , 2>&1 and so on.

it turns out that programs use 3 pipes to transfer information:

  • 0: normal output (STDOUT)
  • 1: normal input (STDIN)
  • 2: error output (STDERR)

so i just needed to pipe my echos to the programoutput which is >&0

for example: echo "Everything OK. Checking if publishing dir was changed." >&0

نصائح أخرى

You're explicitly exiting with a return code of 1, which indicates an error. Change the exit 1 to exit 0 and you should be good to go.

Alternatively, set a variable to hold the return code in each branch of the else. 0 if successful, 1 if failure, then exit $myreturncode at the end.

I understand that you think that you need to return 1, but in my post-commit hook I generate and send the email and then return 0.

You only need to return 1 if you want the svn framework to send the error for you. In the case of success you need to handle the "it worked!" message/email yourself.

If your problem is to mask svn error message, you can do:

svn status /var/www/dev/test/public/projektbereich1/http 2>/dev/null | grep [AMCDG]
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top