代码之家  ›  专栏  ›  技术社区  ›  Jan

如何调试/正确设置git multimail

  •  2
  • Jan  · 技术社区  · 8 年前

    我想用 git-multimail 作为我的一个git存储库中的post-receive挂钩(未使用gitolite)。不幸的是,我无法使它工作,而且我几乎没有使用Python的经验。

    迄今为止我所做的:

    1. 我将以下块添加到 project.git/config 文件:

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

    请注意,我不知道“smtp”是否在 mailer 变量,安装在我的机器上。

    1. 我复制了当前 git_multimail.py project.git/hooks .
    2. 我创建了一个 project.git/hook/post-receive 包含以下内容的文件。该文件是可执行的,我从 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)
    

    发生了什么:

    当我推送更改时,文件 project.git/hooks/git_multimail.pyc 已创建,但未发送电子邮件。

    使用执行配置测试 GIT_MULTIMAIL_CHECK_SETUP=true python git_multimail.py 如上所述 https://github.com/git-multimail/git-multimail/blob/master/doc/troubleshooting.rst 告诉我 git-multimail seems properly set up

    有没有办法记录类似脚本输出的内容?我可以做些什么来找出什么不起作用?我的文件中有错误吗?

    提前谢谢。

    2 回复  |  直到 8 年前
        1
  •  2
  •   Matthieu Moy    8 年前

    使用 post-receive.example 到目前为止不是最简单的设置方法 git_multimail.py

    使用git multimail的最简单方法是使用脚本 git_multimail。直接将py作为post-receive钩子,并对其进行配置 使用Git的配置文件和命令行参数。

    换句话说,只是

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

    你已经准备好了(因为你已经 project.git/config 已填写)。看见 Invocation in git-multimail's README

    (注:请注意,对于初学者来说,文档不是很清楚, I'll try to improve that when I get time )

        2
  •  0
  •   Jan    8 年前

    sys.exit(1) 命令未缩进。

    所以,我问题的错误版本是:

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

    CORRECT是(比较最后一行):

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

    正如我所说,我几乎不懂Python,所以我没有注意缩进。更正之后,电子邮件就发送了,所以请随意使用上述步骤作为一个小教程,以“最简单”的方式设置git multimail。(我没有找到这个精确解决方案的教程。)