1

I've written a Perl post-commit hook that sends out emails via the Perl Net::SMTP module. I was getting the following error when I try to do a commit:

Sending        subversion/README
Transmitting file data .svn: Commit failed (details follow):
svn: MERGE of '/mfxcm/trunk/subversion': 200 OK (http://source)

The commit actually had worked, but the revision of my working copy wasn't updated until I did a "svn up":

$ svn commit -m"Finding what's causing commit errors. I think it's the post-commit script"
Sending        subversion/README
Transmitting file data .svn: Commit failed (details follow):
svn: MERGE of '/mfxcm/trunk/subversion': 200 OK (http://source)
david@DaveBook.local:~/workspace/svn-cm-trunk/subversion
$ svn up
G    README
Updated to revision 94.

I've played around with my post-commit script. First I wrote a simple one that just prints out a simple text message just to make sure things work. Then, I used mine and exited at various times to see where the MERGE issue was coming from.

I got to the point in my script where I created a new Net::SMTP object:

    if ($smtpUser) {
        $smtp->auth( $self->SmtpUser, $self->SmtpPassword)
            or croak qq(Unable to connect to mailhost "@{[$self->SmtpHost]}")
        . qq( as user "@{[$self->SmtpUser]}");
    }

If this line is enabled in my script, I get the MERGE issue. Otherwise, my entire script runs more or less as expected.

I can also run the script from the command line, and everything works just fine. It's only when triggered as a post-commit hook where things fail. I've even logged in as Apache and ran the script without any problems.

What does that MERGE error mean, and why do I get it when Subversion runs the post-commit hook?

David W.
  • 105,218
  • 39
  • 216
  • 337
  • I've traced the problem down to Net::SMTP where it tries `$obj->response() == CMD_OK`. For some reason, something is crashing at that point. SMTP.pm is the latest revision and so is Net::Cmd. – David W. Nov 03 '11 at 19:26

1 Answers1

0

SVN post-commit hooks run under a special account in Windows, and I'd guess the same is true for UNIX/Linux, which it looks like you're using. We ran into something like this in Windows.

Is it possible that this account is unable to send mail thru that server?

The script would work fine when run directly (as you), but not when run in a post-commit hook. It's similar to certain cron systems, where your environment/permission could be very different than what you're used to in an interactive shell.

jimtut
  • 2,366
  • 2
  • 16
  • 37
  • Our repository is Linux using Apache httpd running under user `apache`. I am able to log into as user `apache` and run the hook from the command line without any problems. If there was an issue with the `Net::SMTP` being unable to connect, I would have expected that `$smtp` returning a `NULL` and I would fail my script with a croak. – David W. Nov 03 '11 at 18:15
  • I've further traced the issue down to Net::SMTP where it does an `$obj->response`. This is where something isn't happening. – David W. Nov 03 '11 at 19:27
  • Would you be willing to try sending the mail using Mail::Sendmail, or one of the many other modules for sending mail? That's the one we use, although not in any SVN hooks. It just might work better, and I don't think it's hard to use. – jimtut Nov 04 '11 at 17:34
  • I chose Net::SMTP because that's a standard Perl module. I'll try Mail::Sendmail and see if that works better. I am surprised that my program simply died and never gave me an error. – David W. Nov 04 '11 at 19:21
  • I've added the ability to use Mail::Sendmail. It's a really, really old module, but its simple and it works. I originally wanted to look at other email modules, but they require a lot more non-standard modules, and I wanted to keep things simple. If Mail::Sendmail isn't installed, I fall back to Net::SMTP which is a standard module. Thanks for the suggestion. – David W. Nov 09 '11 at 22:17
  • Yup, it's an oldie, but a goodie! I'd be curious to see your fallback code. It might be useful if we run into a similar module-not-available issue. – jimtut Nov 10 '11 at 06:07
  • The hook itself is available from my [public repository](http://dl.dropbox.com/u/433257/svn-hooks.zip). The file is called svn-watch.pl and the `sub SendMail` method in `package Watch` contains the fallback. I use an eval to see if `Mail::Sender` is installed, and if it is, the subroutine continues using `Mail::Sendmail`. If not, `sub _SendMail_Net_SMTP` is called and it uses `Net::SMTP`. – David W. Nov 10 '11 at 18:54