2

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
  • 1,040
  • 14
  • 29
  • For git-multimail related questions, don't hesitate to ask directly on [git-multimail's bug tracker](https://github.com/git-multimail/git-multimail/issues). Anyway, glad to see you answered your own question ;-). – Matthieu Moy Oct 27 '16 at 06:50

2 Answers2

2

Using post-receive.example is by far not the simplest way to set up git_multimail.py: as the header of post-receive.example script says:

The simplest way to use git-multimail is to use the script git_multimail.py directly as a post-receive hook, and to configure it using Git's configuration files and command-line parameters.

In other words, just

cp /path/to/git_multimail.py /path/to/project.git/hooks/post-receive

and you're all set (since you already have project.git/config filled-in). See Invocation in git-multimail's README for a bit more detail.

(note: admitedly, the doc is not so clear for beginners, I'll try to improve that when I get time)

Matthieu Moy
  • 15,151
  • 5
  • 38
  • 65
0

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.)

Jan
  • 1,040
  • 14
  • 29
  • 2
    You're making it more complex than it should be. No Python involved to set up git-multimail, just copy or link the file to hooks/post-receive. – Matthieu Moy Oct 27 '16 at 06:53