~adeodato/ blog/ entries/ 2008/ 05/ 21/ Commit diff emails with git

Commit diff emails with git

Now that I use Git at various places, I wanted a tool to send commit diffs. And, I couldn’t find one.

There is the contrib/hooks/post-receive-email script, which does a lot of smart stuff to interpret the stdin of the post-receive hook, but which can’t send out diffs, nor produce nice subjects by default.

Since, to be honest, post-receive-email scares me a bit, and I dreaded the idea of carrying a modified copy around everywhere I needed commit diffs, I went on and created a simple script to send out diffs.

The initial idea was stolen from Philipp Kern (kudos!): abuse git-format-patch to produce the emails, and send those. The first hurdle was that the post-receive hook can receive packed updates, whereas you get notified that a branch changed from rev. N to rev. N+4.

I really wanted to keep things simple, so I didn’t want to find out a list of all the revisions between those two, and invoke git-format-patch for each of those. And I didn’t want to generate temporary files, either (just git-format-patch —stdout).

Then, while doing the dishes, inspiration came, and I saw I could easily let git-format-patch generate a stream of emails, and use formail(1) to split them.

Anyway, this story is becoming larger than the script itself. You can fetch it with:

  % git clone http://chistera.yi.org/~adeodato/tmp/other/git-post-receive-diff.git

After a bit of using, and polishing it a bit more, I think I’ll submit it for contrib/ in git.