Subject: [PATCH 4/4] update-hook: allow for the possibility that a tagged object is not a commit

From: Andy Parkins <[email-masked]>
Date: Tue, 20 Mar 2007 10:58:47 +0000

Tags are normally used to tag commits; however this isn't a requirement
so the update hook shouldn't assume it.

This patch only calculates the replacement tag if it is a commit tag -
non-commit tags don't represent a line of development so it would be
meaningless.  Similarly, the short log is not shown for non-commit tags.

Signed-off-by: Andy Parkins <[email-masked]>
---
 templates/hooks--update |   30 ++++++++++++++++++++----------
 1 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/templates/hooks--update b/templates/hooks--update
index fd4c081..cf2a31a 100644
--- a/templates/hooks--update
+++ b/templates/hooks--update
@@ -234,16 +234,20 @@ case "$refname_type" in
 			esac
 		done <<< "$(git cat-file tag $newrev | head -q -n 4)"
 
-		# If this tag succeeds another, then show which tag it replaces
-		prevtag=$(git describe --abbrev=0 $newrev^ 2>/dev/null)
-		if [ -n "$prevtag" ]; then
-			echo "  replaces  $prevtag"
-		fi
-
 		# Extract user and time from tagger variable
 		eval $(sed -n 's/\([^>]*>\)[^0-9]*\([0-9]*\).*/tagger="\1" ts="\2"/p' <<< "$tagger")
 		tagged=$(date --date="1970-01-01 00:00:00 +0000 $ts seconds" +"$DATEFORMAT")
 
+		echo "   tagging  $tagobject ($tagtype)"
+		if [ "$tagtype" = "commit" ]; then
+			# If the tagged object is a commit, then we assume this is a
+			# release, and so we calculate which tag this tag is replacing
+			prevtag=$(git describe --abbrev=0 $newrev^ 2>/dev/null)
+
+			if [ -n "$prevtag" ]; then
+				echo "  replaces  $prevtag"
+			fi
+		fi
 		echo " tagged by  $tagger"
 		echo "        on  $tagged"
 
@@ -257,10 +261,16 @@ case "$refname_type" in
 		git cat-file tag $newrev | tail -q -n +5
 
 		echo ""
-		if [ -n "$prevtag" ]; then
-			git rev-list --pretty=short "$prevtag..$newrev" | git shortlog
-		else
-			git rev-list --pretty=short $newrev | git shortlog
+		if [ "$tagtype" = "commit" ]; then
+			# Only commit tags make sense to have rev-list operations performed
+			# on them
+			if [ -n "$prevtag" ]; then
+				# Show changes since the previous release
+				git rev-list --pretty=short "$prevtag..$newrev" | git shortlog
+			else
+				# No previous tag, show all the changes since time began
+				git rev-list --pretty=short $newrev | git shortlog
+			fi
 		fi
 
 		echo $LOGEND
-- 
1.5.0.3.402.g0c48