git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: post-receive-hook emailer

From
AMAbhijit Menon-Sen <ams@toroid.org>
Date
Jul 22, 2008, 10:40 UTC
Message-ID
<20080722104022.GA6621@toroid.org>
In-Reply-To
<00AEED4D-BD34-4584-B303-32C5F587EF0F@develooper.com>
Hi Ask.
At 2008-07-22 02:34:35 -0700, ask@develooper.com wrote:
>
> Anyway - anyone have a mailer that sends diffs and such? :-)

Not quite what you want, but I wrote the attached post-receive hook/hack to send change notifications by Jabber. "hooks.notify.recipients" should contain a list of jabber IDs; and you can change the "git log" line, for example by adding "-p --stat" or something, to change what gets sent.

It should be trivial to change the last twenty-odd lines to send email instead.

-- ams

#!/usr/bin/perl # Abhijit Menon-Sen <ams@oryx.com>

use Net::Jabber;

my $dir; chomp( $dir = qx(git rev-parse --git-dir 2>/dev/null) ); die "GIT_DIR not defined.\n" unless $dir; $ENV{GIT_DIR} = $dir;

my $r; chomp( $r = qx(git config hooks.notify.recipients) ); my @recipients = split /,\s*/, $r;

my @changes;
while ( <> ) {
    chomp;
    my ( $old, $new, $ref ) = split / /;
    $ref =~ s!refs/heads/!!;
    next unless $ref eq "some/branch";
    my $s = qx(git log --no-merges --reverse --find-copies-harder --raw -r $old..$new);
    $s =~ s/^:.*?\t/\t/gsm;
    push @changes, $s;
}

exit unless @changes; exit unless @recipients;

my $client = new Net::Jabber::Client ();
$client->Connect(
    hostname => 'example.com',
) or die "Cannot connect to jabber server: $!.\n";
my @r = $client->AuthSend(
    username => 'git',
    password => 'some-password',
    resource => 'git'
);
die "Cannot authenticate (@r).\n" if $r[0] ne "ok";
foreach my $c (@changes) {
    for my $r (@recipients) {
        my $msg = new Net::Jabber::Message ();
        $msg->SetMessage(
            to => $r,
            subject => 'Changes pushed to x:y.git/some/branch',
            body => $c
        );
        $client->Send( $msg );
    }
}
$client->Disconnect();
Previous: Ask Bjørn HansenNext: Vincent Kergonna
Message 2 of 3 in “post-receive-hook emailer”
  1. Ask Bjørn HansenJul 22, 2008
  2. Abhijit Menon-SenJul 22, 2008
  3. Vincent KergonnaJul 22, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.