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

[PATCH] Add support in sample hook script for denying annotated tags.

From
Boyd Stephen Smith Jr. <bss@iguanasuicide.net>
Date
Oct 31, 2010, 19:57 UTC
Message-ID
<201010311457.17817.bss@iguanasuicide.net>
Signed-off-by: "Boyd Stephen Smith Jr." <bss@iguanasuicide.net>
---
 templates/hooks--update.sample |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

In one project I'm in we are using a centralized Git repository that many developers have access to. As such, we want to prevent tags from being created by push operations and have them created by the administrators.

This is a modification to the sample update hook to allow this to simply be a configuration option.

receive.denyCreate actually seems to be what my project wants, but I can see more fine-grained support being nice-to-have. For example, we might want to allow developers to create branches in a developer-specific namespace but still disallow pushing annotated tags.

diff --git a/templates/hooks--update.sample b/templates/hooks--update.sample
index fd63b2d..c783973 100755
--- a/templates/hooks--update.sample
+++ b/templates/hooks--update.sample
@@ -7,6 +7,9 @@
 #
 # Config
 # ------
+# hooks.allowannotated
+#   This boolean sets whether annotated tags will be allowed into the
+#   repository.  By default they won't be.
 # hooks.allowunannotated
 #   This boolean sets whether unannotated tags will be allowed into the
 #   repository.  By default they won't be.
@@ -43,6 +46,7 @@ if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then
 fi
 
 # --- Config
+allowannotated=$(git config --bool hooks.allowannotated)
 allowunannotated=$(git config --bool hooks.allowunannotated)
 allowdeletebranch=$(git config --bool hooks.allowdeletebranch)
 denycreatebranch=$(git config --bool hooks.denycreatebranch)
@@ -86,6 +90,11 @@ case "$refname","$newrev_type" in
 		;;
 	refs/tags/*,tag)
 		# annotated tag
+		if [ "$oldrev" = "$zero" -a "$allowannotated" != "true" ]; then
+			echo "*** Creating a tag is not allowed in this repository" >&2
+			exit 1
+		fi
+
 		if [ "$allowmodifytag" != "true" ] && git rev-parse $refname > /dev/null 2>&1
 		then
 			echo "*** Tag '$refname' already exists." >&2
-- 
1.7.1
-- 
Boyd Stephen Smith Jr.                   ,= ,-_-. =.
bss@iguanasuicide.net                   ((_/)o o(\_))
ICQ: 514984 YM/AIM: DaTwinkDaddy         `-'(. .)`-'
http://iguanasuicide.net/                    \_/
Next: Jonathan Nieder
Message 1 of 3 in “Add support in sample hook script for denying annotated tags.”
  1. Add support in sample hook script for denying annotated tags.Boyd Stephen Smith Jr., Oct 31, 2010
  2. Jonathan NiederOct 31, 2010
  3. Boyd Stephen Smith Jr.Nov 1, 2010

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.