2011-01-13

Setting the sender of git post-receive hooks

There is a nice stackoverflow posting about how to set the sender of git post-receive hooks. I used this, slightly augmented:

#!/bin/sh

# Use the name and email address of the author of the last commit.
USER_EMAIL=$(git log -1 --format=format:%ae HEAD)
USER_NAME=$(git log -1 --format=format:%an HEAD)
. $(dirname $0)/post-receive-email

I then also changed the default post-receive-email script, to look like this in the send_mail() function:

send_mail()
{
  if [ -n "$envelopesender" ]; then
    /usr/sbin/sendmail -t -f "$envelopesender"
  else
    /usr/sbin/sendmail -t -F "$USER_NAME" -f "$USER_EMAIL"
  fi
}
This will let the emails come from the last user in the git log. This is only a hack, and might break or not make sense under certain circumstances, but is good enough for most of my needs.

2 comments:

  1. Eh, da hättest Du ja auch noch das SO-Posting verlinken können :-)

    -Volker

    ReplyDelete
  2. Hab ich doch! ;-)

    Danke für den Hinweis.

    ReplyDelete