On the server side you can get the commit
that is trying to be pushed with git cat-file commit SHA
That said, it has a HEADER that gives you such information. That may be wrong or my be tampered, but that is available on the server side.
Something like this would do. In the following code, keep an eye on the three relevant variables: $CATAUTHOREMAIL, $CATAUTHOR and $CATEMAIL.
# --- Command line arguments
refname="$1"
oldrev="$2"
newrev="$3"
echo
echo '*** Checking your push update...'
MISSREVS=`git rev-list ${oldrev}..${newrev}`
CATAUTHOREMAIL=""
CMTMSG=""
for RV in ${MISSREVS} ; do
if [ -z "$CATAUTHOREMAIL" ] ; then
CATAUTHOREMAIL=`git cat-file commit ${RV} | grep author`
fi
CMTMSG="$CMTMSG "`git cat-file commit ${RV} | sed '1,/^$/d'`
done
REMSG="author (.*) <"
[[ $CATAUTHOREMAIL =~ $REMSG ]]
CATAUTHOR="${BASH_REMATCH[1]}"
REMSG="author.*<(.*)>.*"
[[ $CATAUTHOREMAIL =~ $REMSG ]]
CATEMAIL="${BASH_REMATCH[1]}"
echo "*** Last commit author = $CATAUTHOR"
echo "*** Last commit email = $CATEMAIL"
That is very useful. I wrote this answer inspired in the answer from @codewizard, because there it is only available for client side, not server side. And I needed "something" from server side. It is not fool-proof, but it is very useful.
If you analyse the commit header, you can grab more information; for example, you have also the "commiter's name" that is not necessarily the author of the commit.
The loop on the code above will iterate on all commits. You may want to get only the last (most recent) commit's author, like the code do with that if [ -z "$CATAUTHOREMAIL ]
, or you may want to save all of them in an array or something. That is up to you to change this template to your needs.
I used grep author
, but it would break if in the very commit message the word author appears... So, you may want to find a better filter, for example, separate the header from the body of the commit; that is, the first blank line.