git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
APAndy Parkins <andyparkins@gmail.com>
Date
Mar 20, 2007, 10:58 UTC
Message-ID
<200703201058.47485.andyparkins@gmail.com>

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 <andyparkins@gmail.com>
---
 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
Message 1 of 1 in “update-hook: allow for the possibility that a tagged object is not a commit”
  1. 4/4 update-hook: allow for the possibility that a tagged object is not a commitAndy Parkins, Mar 20, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.