Code

attribute macro support
[git.git] / templates / hooks--update
index 9863a800c8b945494f284c58112388b9c865ec58..0ff03309e69aed6b506e333e087f23099ad80290 100644 (file)
@@ -1,89 +1,72 @@
 #!/bin/sh
 #
-# An example hook script to mail out commit update information.
-# It also blocks tags that aren't annotated.
+# An example hook script to blocks unannotated tags from entering.
 # Called by git-receive-pack with arguments: refname sha1-old sha1-new
 #
-# To enable this hook:
-# (1) change the recipient e-mail address
-# (2) make this file executable by "chmod +x update".
+# To enable this hook, make this file executable by "chmod +x update".
+#
+# Config
+# ------
+# hooks.allowunannotated
+#   This boolean sets whether unannotated tags will be allowed into the
+#   repository.  By default they won't be.
 #
 
-project=$(cat $GIT_DIR/description)
-recipients="commit-list@somewhere.com commit-list@somewhereelse.com"
+# --- Command line
+refname="$1"
+oldrev="$2"
+newrev="$3"
 
-ref_type=$(git cat-file -t "$3")
+# --- Safety check
+if [ -z "$GIT_DIR" ]; then
+       echo "Don't run this script from the command line." >&2
+       echo " (if you want, you could supply GIT_DIR then run" >&2
+       echo "  $0 <ref> <oldrev> <newrev>)" >&2
+       exit 1
+fi
 
-# Only allow annotated tags in a shared repo
-# Remove this code to treat dumb tags the same as everything else
-case "$1","$ref_type" in
-refs/tags/*,commit)
-       echo "*** Un-annotated tags are not allowed in this repo" >&2
-       echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2
-       exit 1;;
-refs/tags/*,tag)
-       echo "### Pushing version '${1##refs/tags/}' to the masses" >&2
-       # recipients="release-announce@somwehere.com announce@somewhereelse.com"
-       ;;
-esac
+if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then
+       echo "Usage: $0 <ref> <oldrev> <newrev>" >&2
+       exit 1
+fi
 
-# set this  to 'cat' to get a very detailed listing.
-# short only kicks in when an annotated tag is added
-short='git shortlog'
+# --- Config
+allowunannotated=$(git-repo-config --bool hooks.allowunannotated)
 
-# see 'date --help' for info on how to write this
-# The default is a human-readable iso8601-like format with minute
-# precision ('2006-01-25 15:58 +0100' for example)
-date_format="%F %R %z"
+# check for no description
+if [ -z "$projectdesc" -o "$projectdesc" = "Unnamed repository; edit this file to name it for gitweb" ]; then
+       echo "*** Project description file hasn't been set" >&2
+       exit 1
+fi
 
-(if expr "$2" : '0*$' >/dev/null
-then
-       # new ref
-       case "$1" in
-       refs/tags/*)
-               # a pushed and annotated tag (usually) means a new version
-               tag="${1##refs/tags/}"
-               if [ "$ref_type" = tag ]; then
-                       eval $(git cat-file tag $3 | \
-                               sed -n '4s/tagger \([^>]*>\)[^0-9]*\([0-9]*\).*/tagger="\1" ts="\2"/p')
-                       date=$(date --date="1970-01-01 00:00:00 $ts seconds" +"$date_format")
-                       echo "Tag '$tag' created by $tagger at $date"
-                       git cat-file tag $3 | sed -n '5,$p'
-                       echo
-               fi
-               prev=$(git describe "$3^" | sed 's/-g.*//')
-               # the first tag in a repo will yield no $prev
-               if [ -z "$prev" ]; then
-                       echo "Changes since the dawn of time:"
-                       git rev-list --pretty $3 | $short
-               else
-                       echo "Changes since $prev:"
-                       git rev-list --pretty $prev..$3 | $short
-                       echo ---
-                       git diff --stat $prev..$3
-                       echo ---
+# --- Check types
+newrev_type=$(git-cat-file -t $newrev)
+
+case "$refname","$newrev_type" in
+       refs/tags/*,commit)
+               # un-annotated tag
+               short_refname=${refname##refs/tags/}
+               if [ "$allowunannotated" != "true" ]; then
+                       echo "*** The un-annotated tag, $short_refname, is not allowed in this repository" >&2
+                       echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2
+                       exit 1
                fi
                ;;
-
-       refs/heads/*)
-               branch="${1##refs/heads/}"
-               echo "New branch '$branch' available with the following commits:"
-               git-rev-list --pretty "$3" $(git-rev-parse --not --all)
+       refs/tags/*,tag)
+               # annotated tag
+               ;;
+       refs/heads/*,commit)
+               # branch
                ;;
-       esac
-else
-       base=$(git-merge-base "$2" "$3")
-       case "$base" in
-       "$2")
-               git diff --stat "$3" "^$base"
-               echo
-               echo "New commits:"
+       refs/remotes/*,commit)
+               # tracking branch
                ;;
        *)
-               echo "Rebased ref, commits from common ancestor:"
+               # Anything else (is there anything else?)
+               echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2
+               exit 1
                ;;
-       esac
-       git-rev-list --pretty "$3" "^$base"
-fi) |
-mail -s "$project: Changes to '${1##refs/heads/}'" $recipients
+esac
+
+# --- Finished
 exit 0