1#!/bin/sh 2# 3# An example hook script to mail out commit update information. 4# It also blocks tags that aren't annotated. 5# Called by git-receive-pack with arguments: refname sha1-old sha1-new 6# 7# To enable this hook: 8# (1) change the recipient e-mail address 9# (2) make this file executable by "chmod +x update". 10# 11 12project=$(cat $GIT_DIR/description) 13recipients="commit-list@somewhere.com commit-list@somewhereelse.com" 14 15ref_type=$(git cat-file -t "$3") 16 17# Only allow annotated tags in a shared repo 18# Remove this code to treat dumb tags the same as everything else 19case"$1","$ref_type"in 20refs/tags/*,commit) 21echo"*** Un-annotated tags are not allowed in this repo">&2 22echo"*** Use 'git tag [ -a | -s ]' for tags you want to propagate.">&2 23exit1;; 24refs/tags/*,tag) 25echo"### Pushing version '${1##refs/tags/}' to the masses">&2 26# recipients="release-announce@somwehere.com announce@somewhereelse.com" 27;; 28esac 29 30# set this to 'cat' to get a very detailed listing. 31# short only kicks in when an annotated tag is added 32short='git shortlog' 33 34# see 'date --help' for info on how to write this 35# The default is a human-readable iso8601-like format with minute 36# precision ('2006-01-25 15:58 +0100' for example) 37date_format="%F %R %z" 38 39(ifexpr"$2":'0*$'>/dev/null 40then 41# new ref 42case"$1"in 43 refs/tags/*) 44# a pushed and annotated tag (usually) means a new version 45 tag="${1##refs/tags/}" 46if["$ref_type"= tag ];then 47eval $(git cat-file tag $3| \ 48sed-n'4s/tagger \([^>]*>\)[^0-9]*\([0-9]*\).*/tagger="\1" ts="\2"/p') 49date=$(date --date="1970-01-01 00:00:00 $ts seconds" +"$date_format") 50echo"Tag '$tag' created by$taggerat$date" 51 git cat-file tag $3|sed-n'5,$p' 52echo 53fi 54 prev=$(git describe "$3^" | sed 's/-g.*//') 55# the first tag in a repo will yield no $prev 56if[-z"$prev"];then 57echo"Changes since the dawn of time:" 58 git rev-list --pretty$3|$short 59else 60echo"Changes since$prev:" 61 git rev-list --pretty$prev..$3|$short 62echo --- 63 git diff--stat$prev..$3 64echo --- 65fi 66;; 67 68 refs/heads/*) 69 branch="${1##refs/heads/}" 70echo"New branch '$branch' available with the following commits:" 71 git-rev-list --pretty"$3"$(git-rev-parse --not --all) 72;; 73esac 74else 75 base=$(git-merge-base "$2" "$3") 76case"$base"in 77"$2") 78 git diff--stat"$3""^$base" 79echo 80echo"New commits:" 81;; 82*) 83echo"Rebased ref, commits from common ancestor:" 84;; 85esac 86 git-rev-list --pretty"$3""^$base" 87fi) | 88mail-s"$project: Changes to '${1##refs/heads/}'"$recipients 89exit0