threads / discuss / 21603

send an email with logs after push

Subject: send an email with logs after push

## tl;dr

4 messages between Nov 13, 2009 and Nov 13, 2009.

replies: 3people: 3as markdown or json

michele· Nov 13, 2009, 08:46 UTC · lore

Hi guys, I'm using git for a collaborative development and I'm trying to implement a notification system. I want to automatically send an email containing the log of each commit after a push. The email should contain the titles of the commits done between the previous and the last push. The push action publish the repository on a public_html directory in one other machine.

Do you have any suggestion to implement this?
Thanks
Pascal Obry· Nov 13, 2009, 08:55 UTC · re: michele · lore

Re: send an email with logs after push

Michele,
> Do you have any suggestion to implement this?
I'm doing that. In the post-receive hook I have:
<<
while read oldrev newrev ref; do
    trac_post_receive_record_log "$oldrev" "$newrev" "$ref" gtest
    send_mail_post_receive "$oldrev" "$newrev" "$ref" gtest \
	pascal@obry.net another@here.com
done
>>
the trac_post_receive_record_log is to add log into trac bug tracker.

the send_mail_post_receive is to send a message to the recipients listed. The 4th parameter is the name of the project.

The send_mail_post_receive function is:
function send_mail_post_receive() {
    oldrev=$1
    newrev=$2
    ref=$3
    MODULE="$4"
    git log -p $oldrev..$newrev > $log
    cat $log | mail -s "[$MODULE] $ref $oldrev..$newrev" $5 $6 $7 $8 $9
    rm -fr $root
}
You'll find a set of hook helper routines there:
   git clone http://repo.or.cz/r/git-scripts.git
Hope this helps!
Pascal.
-- 
--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|              http://www.obry.net
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595
Matthieu Moy· Nov 13, 2009, 10:42 UTC · re: Pascal Obry · lore

Re: send an email with logs after push

Pascal Obry <pascal@obry.net> writes:
Show 5 quoted lines
> Michele,
>
>> Do you have any suggestion to implement this?
>
> I'm doing that. In the post-receive hook I have:

See also post-receive-email in git/contrib/hooks/, probably installed somewhere like by your distro. In the .git/hooks/post-receive.sample installed by default by "git init", this should be a matter of uncommenting one line.

-- Matthieu Moy http://www-verimag.imag.fr/~moy/

michele· Nov 13, 2009, 14:18 UTC · re: Matthieu Moy · lore

Re: send an email with logs after push

On Fri, 13 Nov 2009 11:42 +0100, "Matthieu Moy" <Matthieu.Moy@grenoble-inp.fr> wrote:

> See also post-receive-email in git/contrib/hooks/, probably installed

Thank you for your suggestions. I've added a new post-receive hook using the code from post-receive-email. The hook is executable and is placed in the remote directory. The push is made from my local pc via ssh, but after the push nothing seems to happen: the hook is not executed on the server side. It does not depend from the code inside the hook: even the unique "touch foobar" command does not work. Where do I have to look?

Thanks

← back to recent threads