CamelBlues
CamelBlues

Reputation: 3774

SVN post-commit hook sending a message back to client

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?

Upvotes: 11

Views: 6843

Answers (3)

VonC
VonC

Reputation: 1326666

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

Upvotes: 6

Jens
Jens

Reputation: 72697

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.

Upvotes: 4

pmod
pmod

Reputation: 11007

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.

Upvotes: 14

Related Questions