{"thread":{"id":"18904","subject":"[PATCH 1/1] hook/update: example of how to prevent branch creation","startedAt":"2009-04-16T20:00:44Z","lastAt":"2009-04-17T01:48:34Z","messageCount":2,"participants":["Pierre Habouzit","Eric Raible"],"isPatch":true,"patchVersion":1,"patchTotal":1},"messages":[{"id":"111464","messageId":"1239912044-29923-1-git-send-email-madcoder@debian.org","threadId":"18904","inReplyTo":null,"subject":"[PATCH 1/1] hook/update: example of how to prevent branch creation","fromName":"Pierre Habouzit","fromEmail":"madcoder@debian.org","sentAt":"2009-04-16T20:00:44Z","receivedAt":"2009-04-16T20:00:44Z","isPatch":true,"sender":{"key":"madcoder@debian.org","avatar":"https://avatars.githubusercontent.com/u/44708?v=4"},"body":"Since git doesn't provide a receive.denyBranchCreation or similar, here is\nan example of how to be sure users cannot create branches remotely by\npushing a new reference.\n\nThis setup has been proven useful to prevent creation of spurious branches\nbecause of users having their remote.origin.push set to HEAD, when they\nuse `git push` while being on a local topic branch of theirs instead of\nthe proper one.\n\nSigned-off-by: Pierre Habouzit <madcoder@debian.org>\n---\n templates/hooks--update.sample |   11 ++++++++++-\n 1 files changed, 10 insertions(+), 1 deletions(-)\n\ndiff --git a/templates/hooks--update.sample b/templates/hooks--update.sample\nindex a3f68ae..62b9cfe 100755\n--- a/templates/hooks--update.sample\n+++ b/templates/hooks--update.sample\n@@ -16,6 +16,9 @@\n # hooks.allowdeletebranch\n #   This boolean sets whether deleting branches will be allowed in the\n #   repository.  By default they won't be.\n+# hooks.denycreatebranch\n+#   This boolean sets wether remotely creating branches will be denied\n+#   in the repository.  By default this is allowed.\n #\n \n # --- Command line\n@@ -39,6 +42,7 @@ fi\n # --- Config\n allowunannotated=$(git config --bool hooks.allowunannotated)\n allowdeletebranch=$(git config --bool hooks.allowdeletebranch)\n+denycreatebranch=$(git config --bool hooks.denycreatebranch)\n allowdeletetag=$(git config --bool hooks.allowdeletetag)\n \n # check for no description\n@@ -52,7 +56,8 @@ esac\n \n # --- Check types\n # if $newrev is 0000...0000, it's a commit to delete a ref.\n-if [ \"$newrev\" = \"0000000000000000000000000000000000000000\" ]; then\n+zero=\"0000000000000000000000000000000000000000\"\n+if [ \"$newrev\" = \"$zero\" ]; then\n \tnewrev_type=delete\n else\n \tnewrev_type=$(git-cat-file -t $newrev)\n@@ -80,6 +85,10 @@ case \"$refname\",\"$newrev_type\" in\n \t\t;;\n \trefs/heads/*,commit)\n \t\t# branch\n+\t\tif [ \"$oldrev\" = \"$zero\" -a \"$denycreatebranch\" = \"true\" ]; then\n+\t\t\techo \"*** Creating a branch is not allowed in this repository\" >&2\n+\t\t\texit 1\n+\t\tfi\n \t\t;;\n \trefs/heads/*,delete)\n \t\t# delete branch\n-- \n1.6.3.rc0.201.gadb14\n"},{"id":"111472","messageId":"loom.20090417T014456-100@post.gmane.org","threadId":"18904","inReplyTo":"1239912044-29923-1-git-send-email-madcoder@debian.org","subject":"Re: [PATCH 1/1] hook/update: example of how to prevent branch creation","fromName":"Eric Raible","fromEmail":"raible@gmail.com","sentAt":"2009-04-17T01:48:34Z","receivedAt":"2009-04-17T01:48:34Z","isPatch":true,"sender":{"key":"raible@gmail.com","avatar":null},"body":"Pierre Habouzit <madcoder <at> debian.org> writes:\n\n+# hooks.denycreatebranch\n+#   This boolean sets wether remotely creating branches will be denied\n\ns/wether/whether/\n"}]}