{"thread":{"id":"2965","subject":"[PATCH] update-hook: Major overhaul (handling tags, mainly).","startedAt":"2006-01-04T16:17:59Z","lastAt":"2006-01-06T22:37:48Z","messageCount":2,"participants":["Andreas Ericsson","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"14164","messageId":"20060104161729.7FD9C5BE85@nox.op5.se","threadId":"2965","inReplyTo":null,"subject":"[PATCH] update-hook: Major overhaul (handling tags, mainly).","fromName":"Andreas Ericsson","fromEmail":"ae@op5.se","sentAt":"2006-01-04T16:17:59Z","receivedAt":"2006-01-04T16:17:59Z","isPatch":true,"sender":{"key":"ae@op5.se","avatar":"https://gravatar.com/avatar/426e89595c75a8f5252dd0c989e5fabe5bcac616e68557427ad9aef6b0ca342a?d=mp&s=160"},"body":"This is the update hook we use in all our git-repos.\n\nIt has some improvements over the original version, namely:\n* Don't send every commit since dawn of time when adding a new tag.\n* When updating an annotated tag, just send the diffs since the last tag.\n* Add diffstat output for 'normal' commits (top) and annotated tags (bottom).\n* Block un-annotated tags in shared repos.\n\nI'm a bit uncertain about that last one, but it demonstrates how to\ndisallow updates of a ref which we use, so I kept it.\n\nNote that git-describe is needed for the \"changes since last annotated tag\"\nthing to work.\n\nSigned-off-by: Andreas Ericsson <ae@op5.se>\n\n---\n\n templates/hooks--update |   71 +++++++++++++++++++++++++++++++++++++++++++----\n 1 files changed, 65 insertions(+), 6 deletions(-)\n\nf10cd7de04bb84f381cc7a3d65ede0233900de44\ndiff --git a/templates/hooks--update b/templates/hooks--update\nindex 6db555f..27cea17 100644\n--- a/templates/hooks--update\n+++ b/templates/hooks--update\n@@ -1,6 +1,7 @@\n #!/bin/sh\n #\n # An example hook script to mail out commit update information.\n+# It also blocks tags that aren't annotated.\n # Called by git-receive-pack with arguments: refname sha1-old sha1-new\n #\n # To enable this hook:\n@@ -8,16 +9,74 @@\n # (2) make this file executable by \"chmod +x update\".\n #\n \n-recipient=\"commit-list@example.com\"\n+project=$(cat $GIT_DIR/description)\n+recipients=\"commit-list@somewhere.com commit-list@somewhereelse.com\"\n \n-if expr \"$2\" : '0*$' >/dev/null\n+ref_type=$(git cat-file -t \"$3\")\n+\n+# Only allow annotated tags in a shared repo\n+# Remove this code to treat dumb tags the same as everything else\n+case \"$1\",\"$ref_type\" in\n+refs/tags/*,commit)\n+\techo \"*** Un-annotated tags are not allowed in this repo\" >&2\n+\techo \"*** Use 'git tag [ -a | -s ]' for tags you want to propagate.\"\n+\texit 1;;\n+refs/tags/*,tag)\n+\techo \"### Pushing version '${1##refs/tags/}' to the masses\" >&2\n+\t# recipients=\"release-announce@somwehere.com announce@somewhereelse.com\"\n+\t;;\n+esac\n+\n+# set this  to 'cat' to get a very detailed listing.\n+# short only kicks in when an annotated tag is added\n+short='git shortlog'\n+\n+# see 'date --help' for info on how to write this\n+# The default is a human-readable iso8601-like format with minute\n+# precision ('2006-01-25 15:58 +0100' for example)\n+date_format=\"%F %R %z\"\n+\n+(if expr \"$2\" : '0*$' >/dev/null\n then\n-\techo \"Created a new ref, with the following commits:\"\n-\tgit-rev-list --pretty \"$3\"\n+\t# new ref\n+\tcase \"$1\" in\n+\trefs/tags/*)\n+\t\t# a pushed and annotated tag (usually) means a new version\n+\t\ttag=\"${1##refs/tags/}\"\n+\t\tif [ \"$ref_type\" = tag ]; then\n+\t\t\teval $(git cat-file tag $3 | \\\n+\t\t\t\tsed -n '4s/tagger \\([^>]*>\\)[^0-9]*\\([0-9]*\\).*/tagger=\"\\1\" ts=\"\\2\"/p')\n+\t\t\tdate=$(date --date=\"1970-01-01 00:00:00 $ts seconds\" +\"$date_format\")\n+\t\t\techo \"Tag '$tag' created by $tagger at $date\"\n+\t\t\tgit cat-file tag $3 | sed -n '5,$p'\n+\t\t\techo\n+\t\tfi\n+\t\tprev=$(git describe \"$3^\" | sed 's/-g.*//')\n+\t\t# the first tag in a repo will yield no $prev\n+\t\tif [ -z \"$prev\" ]; then\n+\t\t\techo \"Changes since the dawn of time:\"\n+\t\t\tgit rev-list --pretty $3 | $short\n+\t\telse\n+\t\t\techo \"Changes since $prev:\"\n+\t\t\tgit rev-list --pretty $prev..$3 | $short\n+\t\t\techo ---\n+\t\t\tgit diff $prev..$3 | diffstat -p1\n+\t\t\techo ---\n+\t\tfi\n+\t\t;;\n+\n+\trefs/heads/*)\n+\t\tbranch=\"${1##refs/heads/}\"\n+\t\techo \"New branch '$branch' available with the following commits:\"\n+\t\tgit-rev-list --pretty \"$3\"\n+\t\t;;\n+\tesac\n else\n \tbase=$(git-merge-base \"$2\" \"$3\")\n \tcase \"$base\" in\n \t\"$2\")\n+\t\tgit diff \"$3\" \"^$base\" | diffstat -p1\n+\t\techo\n \t\techo \"New commits:\"\n \t\t;;\n \t*)\n@@ -25,6 +84,6 @@ else\n \t\t;;\n \tesac\n \tgit-rev-list --pretty \"$3\" \"^$base\"\n-fi |\n-mail -s \"Changes to ref $1\" \"$recipient\"\n+fi) |\n+mail -s \"$project: Changes to '${1##refs/heads/}'\" $recipients\n exit 0\n-- \n1.0.6-g58e3\n"},{"id":"14205","messageId":"7vd5j5rnib.fsf@assigned-by-dhcp.cox.net","threadId":"2965","inReplyTo":"20060104161729.7FD9C5BE85@nox.op5.se","subject":"Re: [PATCH] update-hook: Major overhaul (handling tags, mainly).","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-01-06T22:37:48Z","receivedAt":"2006-01-06T22:37:48Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Andreas Ericsson <ae@op5.se> writes:\n\n> This is the update hook we use in all our git-repos.\n>\n> It has some improvements over the original version, namely:\n> * Don't send every commit since dawn of time when adding a new tag.\n> * When updating an annotated tag, just send the diffs since the last tag.\n> * Add diffstat output for 'normal' commits (top) and annotated tags (bottom).\n> * Block un-annotated tags in shared repos.\n>\n> I'm a bit uncertain about that last one, but it demonstrates how to\n> disallow updates of a ref which we use, so I kept it.\n>\n> Note that git-describe is needed for the \"changes since last annotated tag\"\n> thing to work.\n>\n> Signed-off-by: Andreas Ericsson <ae@op5.se>\n\ntemplates/hooks--* is a good place to showcase these \"best\ncurrent practices\", but unfortunately we can have only one BCP\nper script there.  If nobody objects I'd take this patch.\n\nI have been wondering if we would want to have an \"examples/\"\ndirectory in the source tree.\n"}]}