@matheusbsbs / matheus-bagliano / commits / ad7638b2ed
Fork 0

hooks--update: decline deleting tags or branches by default, add config options

Decline deleting tags or branches through git push <remote> :<ref> by default, support config options hooks.allowdeletetag, hooks.allowdeletebranch to override this per repository. Before this patch the update hook interpreted deleting a tag, no matter if annotated or not, through git push <remote> :<tag> as unannotated tag, and declined it by default, but with an unappropriate error message: $ git push origin :atag deleting 'refs/tags/atag' *** The un-annotated tag, atag, is not allowed in this repository *** Use 'git tag [ -a | -s ]' for tags you want to propagate. ng refs/tags/atag hook declined error: hooks/update exited with error code 1 error: hook declined to update refs/tags/atag error: failed to push to 'monolith:/git/qm/test-repo' Signed-off-by: Gerrit Pape <pape@smarden.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Gerrit Pape committed Nov 8, 2007 at 09:47 UTC ad7638b2edbad05d5f5581ec76d49094d8ba9237
1 file changed +31 -2
templates/hooks--update
+31 -2
@@ -10,6 +10,12 @@
10 # hooks.allowunannotated
11 # This boolean sets whether unannotated tags will be allowed into the
12 # repository. By default they won't be.
13 +# hooks.allowdeletetag
14 +# This boolean sets whether deleting tags will be allowed in the
15 +# repository. By default they won't be.
16 +# hooks.allowdeletebranch
17 +# This boolean sets whether deleting branches will be allowed in the
18 +# repository. By default they won't be.
19 #
20
21 # --- Command line
@@ -32,6 +38,8 @@ fi
38
39 # --- Config
40 allowunannotated=$(git-repo-config --bool hooks.allowunannotated)
41 +allowdeletebranch=$(git-repo-config --bool hooks.allowdeletebranch)
42 +allowdeletetag=$(git-repo-config --bool hooks.allowdeletetag)
43
44 # check for no description
45 projectdesc=$(sed -e '1q' "$GIT_DIR/description")
@@ -41,9 +49,9 @@ if [ -z "$projectdesc" -o "$projectdesc" = "Unnamed repository; edit this file t
49 fi
50
51 # --- Check types
44 -# if $newrev is 0000...0000, it's a commit to delete a branch
52 +# if $newrev is 0000...0000, it's a commit to delete a ref.
53 if [ "$newrev" = "0000000000000000000000000000000000000000" ]; then
46 - newrev_type=commit
54 + newrev_type=delete
55 else
56 newrev_type=$(git-cat-file -t $newrev)
57 fi
@@ -58,15 +66,36 @@ case "$refname","$newrev_type" in
66 exit 1
67 fi
68 ;;
69 + refs/tags/*,delete)
70 + # delete tag
71 + if [ "$allowdeletetag" != "true" ]; then
72 + echo "*** Deleting a tag is not allowed in this repository" >&2
73 + exit 1
74 + fi
75 + ;;
76 refs/tags/*,tag)
77 # annotated tag
78 ;;
79 refs/heads/*,commit)
80 # branch
81 ;;
82 + refs/heads/*,delete)
83 + # delete branch
84 + if [ "$allowdeletebranch" != "true" ]; then
85 + echo "*** Deleting a branch is not allowed in this repository" >&2
86 + exit 1
87 + fi
88 + ;;
89 refs/remotes/*,commit)
90 # tracking branch
91 ;;
92 + refs/remotes/*,delete)
93 + # delete tracking branch
94 + if [ "$allowdeletebranch" != "true" ]; then
95 + echo "*** Deleting a tracking branch is not allowed in this repository" >&2
96 + exit 1
97 + fi
98 + ;;
99 *)
100 # Anything else (is there anything else?)
101 echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2