Pergunta

I've created a bare (central) repository on a windows machine. My colleagues and myself are now using this repository. I want the git to send out an email notification whenever it's updated. I know that we need to write some script in post-receive hook and configure mailinglist and emailprefix properties. But what i need is the script (in post-receive), which sends out a mail in windows machine.

Note: There is a similar question asked here. But the answer is 'what to do?' not 'how to do?. Can I have git send out an email with the post-receive-email scripts if my repo is on a Windows machine?

Thanks in advance.

Foi útil?

Solução

You can do this pretty much as described in the comments in the stock post-receive sample script but with the exception that Git for Windows provides msmtp and not sendmail. If you paste the contributed script from contrib/hooks into the post-receive script you then just need to make a couple of changes. Firstly, you will need to specify a smtp server so I suggest adding the config variable sendemail.smtpserver and set it to the name of your server. If you need authentication and so on then look up the config variables for those and ammend the script to make use of them.

In the pasted in email script - replace sendmail with msmtp as follows

send_mail()
{
    if [ -n "$envelopesender" ]; then
        msmtp --host="$smtpserver" -t -f "$envelopesender"
    else
        msmtp --host="$smtpserver" -t
    fi
}

And finally, near the end of the file is a section that reads in the git config variable so add a new line to read server values:

smtpserver=$(git config sendemail.smtpserver)

With those two changes in place, the script works fine for me, sending mail to the hooks.mailinglist account on push.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top