{"thread":{"id":"10702","subject":"[PATCH] hooks--update: allow deleting a tag through git push <remote> :<tag>","startedAt":"2007-11-07T10:34:50Z","lastAt":"2007-11-08T09:47:39Z","messageCount":3,"participants":["Gerrit Pape","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"58666","messageId":"20071107103450.29849.qmail@c27a4ce40673ff.315fe32.mid.smarden.org","threadId":"10702","inReplyTo":null,"subject":"[PATCH] hooks--update: allow deleting a tag through git push <remote> :<tag>","fromName":"Gerrit Pape","fromEmail":"pape@smarden.org","sentAt":"2007-11-07T10:34:50Z","receivedAt":"2007-11-07T10:34:50Z","isPatch":true,"sender":{"key":"pape@smarden.org","avatar":"https://avatars.githubusercontent.com/u/143170252?v=4"},"body":"The update hook interpretes deleting a tag, no matter if annotated or not,\nthrough git push <remote> :<tag> as unannotated tag, and declines it by\ndefault:\n\n $ git push origin :atag\n deleting 'refs/tags/atag'\n *** The un-annotated tag, atag, is not allowed in this repository\n *** Use 'git tag [ -a | -s ]' for tags you want to propagate.\n ng refs/tags/atag hook declined\n error: hooks/update exited with error code 1\n error: hook declined to update refs/tags/atag\n error: failed to push to 'monolith:/git/qm/test-repo'\n\nWith this patch deleting a tag is allowed unconditionally, just as\ndeleting a branch.\n\nSigned-off-by: Gerrit Pape <pape@smarden.org>\n---\n templates/hooks--update |    9 ++++++---\n 1 files changed, 6 insertions(+), 3 deletions(-)\n\ndiff --git a/templates/hooks--update b/templates/hooks--update\nindex 65e8c32..a109b1b 100644\n--- a/templates/hooks--update\n+++ b/templates/hooks--update\n@@ -43,7 +43,7 @@ fi\n # --- Check types\n # if $newrev is 0000...0000, it's a commit to delete a branch\n if [ \"$newrev\" = \"0000000000000000000000000000000000000000\" ]; then\n-\tnewrev_type=commit\n+\tnewrev_type=delete\n else\n \tnewrev_type=$(git-cat-file -t $newrev)\n fi\n@@ -58,13 +58,16 @@ case \"$refname\",\"$newrev_type\" in\n \t\t\texit 1\n \t\tfi\n \t\t;;\n+\trefs/tags/*,delete)\n+\t\t# delete tag\n+\t\t;;\n \trefs/tags/*,tag)\n \t\t# annotated tag\n \t\t;;\n-\trefs/heads/*,commit)\n+\trefs/heads/*,commit | refs/heads/*,delete)\n \t\t# branch\n \t\t;;\n-\trefs/remotes/*,commit)\n+\trefs/remotes/*,commit | refs/remotes/*,delete)\n \t\t# tracking branch\n \t\t;;\n \t*)\n-- \n1.5.3.5\n"},{"id":"58782","messageId":"7v640d8skt.fsf@gitster.siamese.dyndns.org","threadId":"10702","inReplyTo":"20071107103450.29849.qmail@c27a4ce40673ff.315fe32.mid.smarden.org","subject":"Re: [PATCH] hooks--update: allow deleting a tag through git push <remote> :<tag>","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-11-08T00:54:42Z","receivedAt":"2007-11-08T00:54:42Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Gerrit Pape <pape@smarden.org> writes:\n\n> The update hook interpretes deleting a tag, no matter if annotated or not,\n> through git push <remote> :<tag> as unannotated tag, and declines it by\n> default:\n> ...\n> With this patch deleting a tag is allowed unconditionally, just as\n> deleting a branch.\n>\n> Signed-off-by: Gerrit Pape <pape@smarden.org>\n> ---\n>  templates/hooks--update |    9 ++++++---\n>  1 files changed, 6 insertions(+), 3 deletions(-)\n\nSince you are allowing deletion for anything, wouldn't this be\nmuch simpler, I wonder...\n\n---\n\n templates/hooks--update |    4 ++--\n 1 files changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/templates/hooks--update b/templates/hooks--update\nindex d8c7626..e12904a 100644\n--- a/templates/hooks--update\n+++ b/templates/hooks--update\n@@ -41,9 +41,9 @@ if [ -z \"$projectdesc\" -o \"$projectdesc\" = \"Unnamed repository; edit this file t\n fi\n \n # --- Check types\n-# if $newrev is 0000...0000, it's a commit to delete a branch\n+# if $newrev is 0000...0000, it's a commit to delete a ref.\n if [ \"$newrev\" = \"0000000000000000000000000000000000000000\" ]; then\n-\tnewrev_type=commit\n+\texit 0 ;# allow anything to be deleted\n else\n \tnewrev_type=$(git-cat-file -t $newrev)\n fi\n"},{"id":"58847","messageId":"20071108094739.22091.qmail@d736483bdc832c.315fe32.mid.smarden.org","threadId":"10702","inReplyTo":"7v640d8skt.fsf@gitster.siamese.dyndns.org","subject":"[PATCH] hooks--update: decline deleting tags or branches by default, add config options","fromName":"Gerrit Pape","fromEmail":"pape@smarden.org","sentAt":"2007-11-08T09:47:39Z","receivedAt":"2007-11-08T09:47:39Z","isPatch":true,"sender":{"key":"pape@smarden.org","avatar":"https://avatars.githubusercontent.com/u/143170252?v=4"},"body":"Decline deleting tags or branches through git push <remote> :<ref> by\ndefault, support config options hooks.allowdeletetag, hooks.allowdeletebranch\nto override this per repository.\n\nBefore this patch the update hook interpreted deleting a tag, no matter if\nannotated or not, through git push <remote> :<tag> as unannotated tag, and\ndeclined it by default, but with an unappropriate error message:\n\n $ git push origin :atag\n deleting 'refs/tags/atag'\n *** The un-annotated tag, atag, is not allowed in this repository\n *** Use 'git tag [ -a | -s ]' for tags you want to propagate.\n ng refs/tags/atag hook declined\n error: hooks/update exited with error code 1\n error: hook declined to update refs/tags/atag\n error: failed to push to 'monolith:/git/qm/test-repo'\n\nSigned-off-by: Gerrit Pape <pape@smarden.org>\n---\n\nOn Wed, Nov 07, 2007 at 04:54:42PM -0800, Junio C Hamano wrote:\n> Since you are allowing deletion for anything, wouldn't this be\n> much simpler, I wonder...\n\nYes, true.  But to be a good axample hook, I suggest to differentiate\nthis in the implementation, and to deny deleting tags, branches by\ndefault.\n\n\n templates/hooks--update |   33 +++++++++++++++++++++++++++++++--\n 1 files changed, 31 insertions(+), 2 deletions(-)\n\ndiff --git a/templates/hooks--update b/templates/hooks--update\nindex 65e8c32..7d7c251 100644\n--- a/templates/hooks--update\n+++ b/templates/hooks--update\n@@ -10,6 +10,12 @@\n # hooks.allowunannotated\n #   This boolean sets whether unannotated tags will be allowed into the\n #   repository.  By default they won't be.\n+# hooks.allowdeletetag\n+#   This boolean sets whether deleting tags will be allowed in the\n+#   repository.  By default they won't be.\n+# hooks.allowdeletebranch\n+#   This boolean sets whether deleting branches will be allowed in the\n+#   repository.  By default they won't be.\n #\n \n # --- Command line\n@@ -32,6 +38,8 @@ fi\n \n # --- Config\n allowunannotated=$(git-repo-config --bool hooks.allowunannotated)\n+allowdeletebranch=$(git-repo-config --bool hooks.allowdeletebranch)\n+allowdeletetag=$(git-repo-config --bool hooks.allowdeletetag)\n \n # check for no description\n projectdesc=$(sed -ne '1p' \"$GIT_DIR/description\")\n@@ -41,9 +49,9 @@ if [ -z \"$projectdesc\" -o \"$projectdesc\" = \"Unnamed repository; edit this file t\n fi\n \n # --- Check types\n-# if $newrev is 0000...0000, it's a commit to delete a branch\n+# if $newrev is 0000...0000, it's a commit to delete a ref.\n if [ \"$newrev\" = \"0000000000000000000000000000000000000000\" ]; then\n-\tnewrev_type=commit\n+\tnewrev_type=delete\n else\n \tnewrev_type=$(git-cat-file -t $newrev)\n fi\n@@ -58,15 +66,36 @@ case \"$refname\",\"$newrev_type\" in\n \t\t\texit 1\n \t\tfi\n \t\t;;\n+\trefs/tags/*,delete)\n+\t\t# delete tag\n+\t\tif [ \"$allowdeletetag\" != \"true\" ]; then\n+\t\t\techo \"*** Deleting a tag is not allowed in this repository\" >&2\n+\t\t\texit 1\n+\t\tfi\n+\t\t;;\n \trefs/tags/*,tag)\n \t\t# annotated tag\n \t\t;;\n \trefs/heads/*,commit)\n \t\t# branch\n \t\t;;\n+\trefs/heads/*,delete)\n+\t\t# delete branch\n+\t\tif [ \"$allowdeletebranch\" != \"true\" ]; then\n+\t\t\techo \"*** Deleting a branch is not allowed in this repository\" >&2\n+\t\t\texit 1\n+\t\tfi\n+\t\t;;\n \trefs/remotes/*,commit)\n \t\t# tracking branch\n \t\t;;\n+\trefs/remotes/*,delete)\n+\t\t# delete tracking branch\n+\t\tif [ \"$allowdeletebranch\" != \"true\" ]; then\n+\t\t\techo \"*** Deleting a tracking branch is not allowed in this repository\" >&2\n+\t\t\texit 1\n+\t\tfi\n+\t\t;;\n \t*)\n \t\t# Anything else (is there anything else?)\n \t\techo \"*** Update hook: unknown type of update to ref $refname of type $newrev_type\" >&2\n-- \n1.5.3.5\n"}]}