Jan Jan - 1 month ago 16
Python Question

How to debug / correctly setup git-multimail

I would like to use git-multimail as post receive hook in one of my git repositories (no gitolite used). Unfortunately, I cannot get it work, and I have hardly any experience using Python.

What I did so far:




  1. I added the following block to the
    project.git/config
    file:



 

[multimailhook]
mailingList = email@example.com
from = email@example.com
envelopeSender = email@example.com
mailer = smtp
smtpServer = smtp.mydomain.com
smtpUser = myUser
smtpPass = myPassword


Please note that I do not know whether "smtp", which is defined in the
mailer
variable, is installed on my machine.


  1. I copied the current
    git_multimail.py
    file into
    project.git/hooks
    .

  2. I created a
    project.git/hook/post-receive
    file with the following content. The file is executable, I copied this from https://github.com/git-multimail/git-multimail/blob/master/git-multimail/post-receive.example



 

#! /usr/bin/env python

import sys
import os
import git_multimail

config = git_multimail.Config('multimailhook')

try:
environment = git_multimail.GenericEnvironment(config=config)
#environment = git_multimail.GitoliteEnvironment(config=config)
except git_multimail.ConfigurationException:
sys.stderr.write('*** %s\n' % sys.exc_info()[1])
sys.exit(1)

mailer = git_multimail.choose_mailer(config, environment)

git_multimail.run_as_post_receive_hook(environment, mailer)


What happens:



When I push a change, a file
project.git/hooks/git_multimail.pyc
is created, but no email is sent.

Doing a configuration test using
GIT_MULTIMAIL_CHECK_SETUP=true python git_multimail.py
as described on https://github.com/git-multimail/git-multimail/blob/master/doc/troubleshooting.rst tells me that
git-multimail seems properly set up


Is there a way to log something like an output of the script? What can I do to find out what is not working? Are there even errors in my files?

Thanks in advance.

Jan Jan
Answer

OK guys, the error was probably as little as it could be. I did just one very little mistake in the post receive hook file: The sys.exit(1) command is not indented.

So, the WRONG version from my question:

try:
    environment = git_multimail.GenericEnvironment(config=config)
except git_multimail.ConfigurationException:
    sys.stderr.write('*** %s\n' % sys.exc_info()[1])
sys.exit(1)

CORRECT is (compare last line):

try:
    environment = git_multimail.GenericEnvironment(config=config)
except git_multimail.ConfigurationException:
    sys.stderr.write('*** %s\n' % sys.exc_info()[1])
    sys.exit(1)

Like I said, I hardly know Python, so I did not pay attention to the indents. After correcting this, the email was sent, so feel free to use the above steps as a little tutorial for setting up git-multimail the "easiest" way. (I did not find a tutorial for this exact solution.)