Reputation: 31
My pre-commit is calling a perl script commit_log.pl
.The script is doing so many pre-checks.Now I am trying to send out a mail after commit approval.We are not able to set up post-commit hooks due to some permission issues.So I am trying to call the send mail in the pre-commit script itself.
In my commit_log.pl
if the exit code is zero ,even printf
is not working.
If exit code is 1 everything is working fine
pre-commit
:
log=`$SVNLOOK log -t "$TXN" "$REPOS"`
author=`$SVNLOOK author -t "$TXN" "$REPOS"`
CHANGED=`$SVNLOOK changed -t "$TXN" "$REPOS"`
/usr/bin/perl /isource/svnroot/fgw_ins/hooks/user/commit_log.pl "$log" "$author" "$CHANGED" "$0" 1>&2
if [ "$?" -eq "1" ];
then
exit 1
else
exit 0
fi
# if does not match..fail...
exit 1
---------------------------------------------------------------------------------
commit_log.pl
------------------------
}
else
{
print("Commit approved\n");#this printf itself is not working
`python $path/send_mail.py $comment $committed_filepath`;
exit 0;
}
Upvotes: 1
Views: 874
Reputation: 107060
Can't add much more to Avi's answer: STDOUT is swallowed by the hook. You will NEVER see STDOUT. STDERR is only seen by the client if the hook script returns a non-zero exitcode -- which usually means the hook failed, and in a pre-commit hook prevents the commit.
If you need to send mail out after a commit, and you can't use a post-commit hook, I suggest you use a continuous build system like Jenkins. You can have Jenkins watch your repository, and when it sees a new revision, send out email to those involved.
Jenkins is a continuous build system which can do a build after every commit, but there's no reason why you need to do a build (except it is usually a good idea anyway). Jenkins can be setup to do any action post commit, so you could have Jenkins simply email those involved.
Yes, it's a bit of an overkill having an entire system like Jenkins just to send out email. Why not simply write your own script? However, you can download, install, and configure Jenkins in an hour or two. It'll take you longer just to layout what you think needs to be done.
Besides, once you have Jenkins, you'll find plenty of other uses for it.
Upvotes: 1
Reputation: 20142
I'm not sure where standard output from the pre-commit hook is sent to. According to the SVN book, the standard error is sent back to the client, but only if there is an error (i.e. it exited with a non-zero exit code).
I would try writing to a specific location, rather than to standard output (e.g. /tmp/pre-commit.log for testing purposes).
Also, in general, you probably should avoid as much as possible doing work in the pre-commit script that assumes the commit was successful. The commit may still fail after the pre-commit script runs, such as during the commit itself, which is why the post-commit script exists.
Upvotes: 0