SVN post-commit hook sending a message back to client
Asked Answered
B

3

11

I'm writing a post-commit script in bash, and I'd like to pass messages back to the client who's making a commit. However

echo my message >&2

isn't making it back to the client. Is it even possible to send messages back with a post-commit hook?

Binturong answered 8/12, 2011 at 0:32 Comment(0)
V
6

Condering a post-commit hook does:

anything that the hook printed to stderr will be marshalled back to the client, making it easier to diagnose hook failures.

you can check if this isn't a simple quote issue:

echo "my message" >&2

You can see in those hook examples that any echo to >&2 includes quotes.

The bash chapter on redirection also includes examples with quotes.

However, as pmod details in his answer, that stderr message won't be visible unless the exit status of the script differs from 0, as illustrated in "subversion post-commit hook: print an error message that the user can see?"

#!/bin/bash
echo "test" >&2
exit 1
Vibrio answered 8/12, 2011 at 7:4 Comment(2)
As pmod says below, the stderr screen is only printed to the client if this (or any) hook returns a nonzero return value. That was probably the issue @Binturong encountered.Create
This answer is wrong. Pmod has it right that the script must return a non 0 value.Ji
P
14

Hook will show STDERR only if it fails (and as you may now, hook doesn't display STDOUT). Thus, you have to return non-zero code from your script to pass "my message" to user (just add exit 1 after echo).

Take a look here:

If the post-commit hook returns a nonzero exit status, the commit will not be aborted since it has already completed. However, anything that the hook printed to stderr will be marshalled back to the client, making it easier to diagnose hook failures.

Paving answered 8/12, 2011 at 7:2 Comment(0)
V
6

Condering a post-commit hook does:

anything that the hook printed to stderr will be marshalled back to the client, making it easier to diagnose hook failures.

you can check if this isn't a simple quote issue:

echo "my message" >&2

You can see in those hook examples that any echo to >&2 includes quotes.

The bash chapter on redirection also includes examples with quotes.

However, as pmod details in his answer, that stderr message won't be visible unless the exit status of the script differs from 0, as illustrated in "subversion post-commit hook: print an error message that the user can see?"

#!/bin/bash
echo "test" >&2
exit 1
Vibrio answered 8/12, 2011 at 7:4 Comment(2)
As pmod says below, the stderr screen is only printed to the client if this (or any) hook returns a nonzero return value. That was probably the issue @Binturong encountered.Create
This answer is wrong. Pmod has it right that the script must return a non 0 value.Ji
P
4

I had the same problem, with Apache and mod_svn. It turned out that the marshalling fails when the text being marshalled contained &, < or > characters. After substituting them with &amp;, &lt; and &gt; the text got through.

Pretonic answered 7/3, 2012 at 16:29 Comment(1)
Thanks! This is exactly what we were facing with mod_svn. Never would've figured it out...Fadge

© 2022 - 2024 — McMap. All rights reserved.