summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBertrand Jacquin (Beber) <beber@meleeweb.net>2006-09-29 01:24:53 +0200
committerbeber <beber@lechuck.meleeweb.net>2006-09-29 01:24:53 +0200
commit82d7dd838930d8709f06e13d072ccb0251c9c1a8 (patch)
tree10384d636af544b5f2bdaea794e54a7164434250
parentAdd my init script for typo for gentoo (diff)
downloadperso-82d7dd838930d8709f06e13d072ccb0251c9c1a8.tar.gz
update git hooks
Diffstat
--rwxr-xr-xgit/hooks/pre-update6
-rwxr-xr-xgit/hooks/update205
2 files changed, 126 insertions, 85 deletions
diff --git a/git/hooks/pre-update b/git/hooks/pre-update
index cd42ca3..62c27da 100755
--- a/git/hooks/pre-update
+++ b/git/hooks/pre-update
@@ -6,6 +6,6 @@
# 2664 for files
# 2775 for reps
# owned by git group
-sudo find refs objects info -type d \! -perm 2775 -exec chmod 2775 {} \;
-sudo find refs objects info -type f \! -perm 2775 -exec chmod 2775 {} \;
-sudo find refs objects info \! -user apache -exec chown apache:git {} \;
+find refs objects info -type d \! -perm 2775 -exec chmod 2775 {} \;
+find refs objects info -type f \! -perm 2775 -exec chmod 2775 {} \;
+find refs objects info \! -user apache -exec chgrp git {} \;
diff --git a/git/hooks/update b/git/hooks/update
index 53a5ae7..5369960 100755
--- a/git/hooks/update
+++ b/git/hooks/update
@@ -1,144 +1,185 @@
#!/bin/sh
+
+# (c) 2006 Bertrand Jacquin <beber:meleeweb.net>
#
-# (c) 2006 Bertrand Jacquin <beber_AT_meleeweb.net>
+# File: sh/git/hooks/update
+# Description: Send mail on push
#
# Depends on :
-# git http://kernel.org/pub/software/scm/git/docs/
-# cogito http://kernel.org/pub/software/scm/cogito/docs/
+# git: http://kernel.org/pub/software/scm/git/docs/
+# sendxmpp: http://www.djcbsoftware.nl/code/sendxmpp/
#
# Called by git-receive-pack with arguments :
# $1 : refname
# $2 : sha1-old
# $3 : sha1-new
-
+#
# TODO:
+# Need to track merge
# Config
-gitweburl="http://guybrush.ath.cx/gitweb" # Git web URL, can be empty if no gitweb, so mail will not contain any URL link.
-maintainer="beber@meleeweb.net" # Maintainer email for bugs reports, can be empty too
-mailprefix="Melee:" # Prefix for mail
+gitweburl="http://git.meleeweb.net" # Git web URL, can be empty if no gitweb, so mail will not contain any URL link.
+maintainer="beber@meleeweb.net" # Maintainer email for bugs reports, can be empty too
smtpserver="localhost" # SMTP server address (default is localhost)
-mailonlyforrefs=( "master" "pr/my_passwd" ) # Track and send mail for only theses refs. It can be multiple (ex: mailonlyforrefs=( "master" "upstream" )
+from="Stan <git@meleeweb.net>"
+to="Meleeweb Commits Mailing-list <git@list.meleeweb.net>"
export TERM=dumb
-export LC_ALL=C
+export LC_ALL=fr_FR.utf8
export PAGER=cat
echo "$@" > /tmp/git-update-${2}-${3}-$$.log # Debugging
log=/tmp/git-update-log-${2}-${3}-$$.log # Log
echo "$(date)" > ${log}
echo "$(pwd)" >> ${log}
-echo "$@" >> ${log}
+echo "$0 $@" >> ${log}
# Change perms
-hooks/pre-update # Unneeded when using cg-admin-setuprepo(1)
+hooks/pre-update # Unneeded when using cg-admin-setuprepo(1)
-# Email is directly send to project owner (declared in info/owner)
-if [ -e info/owner ]; then
- to=$(cat info/owner)
-else
- # No project owner, no mail
- echo "No project owner, no mail" >> ${log}
- exit 0
-fi
-
-if [ ! -z "${maintainer}" ]; then
- echo "Reports bugs or strange things to ${maintainer}" 1>&2
-else
- echo "No \$maintainer declared" >> ${log}
-fi
-
-# Email is send also to each members declared in info/mailto
-if [ -e info/mailto ]; then
- for rcpt in $(cat info/mailto); do
- cc="${cc} ${rcpt}"
- done
- # Replace " " with ", "
- cc=$(echo ${cc} | sed 's/\ /, /g')
-fi
+echo "Reports bugs or strange things to ${maintainer}" 1>&2
# Change /var/git to your need
gitrepopath=$(pwd)
gitrepopath=${gitrepopath#/var/git/}
-gitrepopath=${gitrepopath#public/} # public/private are just here for MY need, you can delete this
-gitrepopath=${gitrepopath#private/}
updateref=${1}
firstcommitid=${2}
lastcommitid=${3}
id_from=${firstcommitid}
-# Check if updated refs need a mail commit
-# Config that in mailonlyforrefs, see below
-# You can have multiple refs to track so imply that shit
-nb_refs_to_check=${#mailonlyforrefs[@]}
-while [ ${nb_refs_to_check} -ne 0 ]; do
- # Bash start table at 0, so we start from the end - 1
- nb_refs_to_check=$((${nb_refs_to_check}-1))
-
- if [ "${updateref/refs\/heads\//}" = "${mailonlyforrefs[${nb_refs_to_check}]}" ]; then
- ok_for_mail=1
- fi
-done
+objtype=${updateref/refs\//}
+objtype=${objtype%/*}
+
+if [ ${objtype} = "tags" ]; then
+ mailfile=/tmp/.git-mail-${id_from}-${id_to}-$$
+ touch ${mailfile}
+ chmod 600 ${mailfile}
+
+ env >> ${log}
+ export >> ${log}
+
+ tag=${updateref#*${objtype}/}
+ id_tag=${lastcommitid}
+
+ # Get the Subject oneline log
+ subject="New tag ${tag}"
+ author=$(git-cat-file tag ${tag} | head -n 4 | tail -n 1 | cut -c 8- | sed -r 's/(.*) <(.*)/\1/')
+
+ # Format mail
+ echo >> ${mailfile}
+ echo "Update in $(pwd)/${updateref}" >> ${mailfile}
+
+ echo "${gitweburl}/?p=${gitrepopath};a=summary" >> ${mailfile}
+ echo "${gitweburl}/?p=${gitrepopath};a=commit;h=${id_tag}" >> ${mailfile}
+ echo >> ${mailfile}
+
+ echo "---" >> ${mailfile}
+ echo >> ${mailfile}
+
+ git-cat-file tag ${tag} >> ${mailfile}
+
+ echo >> ${mailfile}
+ echo "Reports bugs or strange things to ${maintainer}" >> ${mailfile}
+
+ # Send mail !
+ git-send-email --from "${from}" --to "${to}" \
+ --no-signed-off-cc --no-chain-reply-to \
+ --smtp-server ${smtpserver} \
+ --subject "${author} - ${subject}" ${mailfile} > /dev/null 2>&1
+
+ cat ${mailfile} >> ${log}
+ rm ${mailfile}
-if [ -z "${ok_for_mail}" ]; then
- # Don't mail for that refs, quit
- echo "Don't mail for head ${updateref}, quit ($mailonlyforrefs)" >> ${log}
exit 0
fi
-allrev=$(git rev-list --no-merges ${firstcommitid}..${lastcommitid} | tac)
+if [ ${firstcommitid} = "0000000000000000000000000000000000000000" ]; then
+ allrev=$(git-rev-list ${lastcommitid} | tac)
+else
+ allrev=$(git-rev-list ${firstcommitid}..${lastcommitid} | tac)
+fi
# Send mail for all commit since last push
-for id_to in ${allrev}
-do
+for id_to in ${allrev} ; do
# Create temporary mail file to send
mailfile=/tmp/.git-mail-${id_from}-${id_to}-$$
+
+ [ -f ${mailfile} ] && rm -f {mailfile}
touch ${mailfile}
chmod 600 ${mailfile}
- author=$(git log ${id_from}..${id_to} | grep 'Author' | sed -r 's/(.*)<(.*)>(.*)/\2/')
-
- # If author is the project owner, don't send mail to both, unneeded
- if [ "${author}" = "${to}" ]; then
- to_="${to}"
- else
- to_="${to}, ${author}"
- fi
+ env >> ${log}
+ export >> ${log}
# Get the Subject oneline log
- simplelog=$(git log --pretty=oneline ${id_from}..${id_to} | cut -c 42-)
+ subject=$(git log --max-count=1 --pretty=oneline ${id_to} | head -n 1 | cut -c 42-)
+ author=$(git-log --max-count=1 ${id_to} | grep '^Author:' | head -n 1 | sed -r -e 's/^Author: (.*) <(.*)/\1/')
# Format mail
echo >> ${mailfile}
echo "Update in $(pwd)/${updateref}" >> ${mailfile}
- if [ ! -z "${gitweburl}" ]; then
- echo "${gitweburl}/?p=${gitrepopath};a=summary" >> ${mailfile}
- echo "${gitweburl}/?p=${gitrepopath};a=commit;h=${id_to}" >> ${mailfile}
- echo >> ${mailfile}
- fi
+ echo "${gitweburl}/?p=${gitrepopath};a=summary" >> ${mailfile}
+ echo "${gitweburl}/?p=${gitrepopath};a=commit;h=${id_to}" >> ${mailfile}
+ echo >> ${mailfile}
- # It could be usefull to use git log --pretty=raw, but date format is bad :(
- cg log -r ${id_from}..${id_to} >> ${mailfile}
- echo "---" >> ${mailfile}
- echo >> ${mailfile}
+ parents="$(git-cat-file commit "${id_to}" | awk '/^parent/{print $2};/^$/{exit}')"
+ nb_parents=$(git-cat-file commit "${id_to}" | awk '/^parent/{print $2};/^$/{exit}' | wc -l)
- cg diff -r ${id_from}..${id_to} | git apply --stat --summary >> ${mailfile}
- echo >> ${mailfile}
+ if [ "${nb_parents}" -gt 1 ] ; then
+
+ parent1=$(echo ${parents} | awk '{print $1}')
+ parent2=$(echo ${parents} | awk '{print $2}')
+
+ git-log --max-count=1 ${id_to} \
+ | grep -vE '^Merge:' \
+ | sed -r -e '1 s/commit (.*)/Commit: \1\nParent:\nParent:/' \
+ | sed -e "2 s/^Parent:/Parent: ${parent1}/" \
+ | sed -e "3 s/^Parent:/Parent: ${parent2}/"
+
+ mergebase=$(git-merge-base ${parents[*]})
+ nb_commits=$(git-log --pretty=oneline ${mergebase}..${id_to} \
+ | cut -c 42- | sed -r -e 's/(.*)/\to \1/g' | wc -l)
+
+ echo
+ echo "${nb_commits} commits:"
- cg diff -r ${id_from}..${id_to} >> ${mailfile}
+ git-log --pretty=oneline ${mergebase}..${id_to} \
+ | cut -c 42- | sed -r -e 's/(.*)/\to \1/g'
- if [ ! -z "${gitweburl}" ]; then
- echo >> ${mailfile}
- echo "Reports bugs or strange things to ${maintainer}" >> ${mailfile}
- fi
+ echo
+ echo "---"
+ echo
+
+ git-diff --stat ${mergebase}..${id_to}
+ else
+ # It could be usefull to use git log --pretty=raw, but date format is bad :(
+ git-log --max-count=1 --pretty=medium ${id_to} \
+ | sed '1 s/commit/Commit: /'
+
+ echo
+ echo "---"
+ echo
+
+ git-diff ${id_from}..${id_to} \
+ | git-apply --stat --summary
+ echo
+
+ git-diff ${id_from}..${id_to}
+ fi >> ${mailfile} 2>&1
+
+ echo >> ${mailfile}
+ echo "Reports bugs or strange things to ${maintainer}" >> ${mailfile}
# Send mail !
- git send-email --from ${author} --to "${to_}" --cc "${cc}" \
- --no-signed-off-cc --no-chain-reply-to --quiet \
+ git-send-email --from "${from}" --to "${to}" \
+ --no-signed-off-cc --no-chain-reply-to \
--smtp-server ${smtpserver} \
- --subject "${mailprefix} ${gitrepopath} - ${simplelog}" ${mailfile} 2>&1 2> /dev/null
+ --subject "$gitrepopath: ${author} - ${subject}" ${mailfile} > /dev/null 2>&1
+
+ # Send annonce in jabber chat room
+# echo -n "*Commit*: ${author} - ${subject}" | sendxmpp -c else@chat.jabberfr.org -f xmppconfig
cat ${mailfile} >> ${log}
rm ${mailfile}