{"thread":{"id":"24452","subject":"[PATCH] contrib: Add update-http-moderated hook","startedAt":"2010-07-21T01:23:07Z","lastAt":"2010-07-21T10:37:10Z","messageCount":2,"participants":["public_vi@tut.by","Jared Hance"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"145923","messageId":"1279675387-15280-1-git-send-email-public_vi@tut.by","threadId":"24452","inReplyTo":null,"subject":"[PATCH] contrib: Add update-http-moderated hook","fromName":"","fromEmail":"public_vi@tut.by","sentAt":"2010-07-21T01:23:07Z","receivedAt":"2010-07-21T01:23:07Z","isPatch":true,"sender":{"key":"vi0oss@gmail.com","avatar":"https://avatars.githubusercontent.com/u/173219?v=4"},"body":"From: Vitaly _Vi Shukela <public_vi@tut.by>\n\nIf the user of http-backend is \"mod\", allow everything.\nElse prevent editing history or deleting refs.\nCan be used to set up \"anarchic\" repositories with anonymous push access,\nbut also with moderator account that can do \"push --force\" and \"push --delete\".\n\nSigned-off-by: Vitaly _Vi Shukela <public_vi@tut.by>\n---\n contrib/hooks/update-http-moderated |  121 +++++++++++++++++++++++++++++++++++\n 1 files changed, 121 insertions(+), 0 deletions(-)\n create mode 100755 contrib/hooks/update-http-moderated\n\ndiff --git a/contrib/hooks/update-http-moderated b/contrib/hooks/update-http-moderated\nnew file mode 100755\nindex 0000000..cff4fd7\n--- /dev/null\n+++ b/contrib/hooks/update-http-moderated\n@@ -0,0 +1,121 @@\n+#!/bin/sh\n+#\n+# If the user of http-backend is \"mod\", allow everything. Else prevent editing history or deleting refs.\n+# \n+# Apache configuration example:\n+#\n+#       SetEnv GIT_PROJECT_ROOT /var/www/git\n+#       ScriptAlias /git/ /usr/local/libexec/git-core/git-http-backend/\n+#       ScriptAlias /gitmod/ /usr/local/libexec/git-core/git-http-backend/\n+#       \n+#       \n+#       <Location /gitmod/>\n+#           AuthName \"Git forced push access\"\n+#           AuthType Basic\n+#           AuthUserFile /var/www/git/.htpasswd\n+#           AuthGroupFile /dev/null\n+#           Require User mod\n+#       </Location>\n+#\n+# Can be used to set up \"anarchic\" repositories with anonymous push access,\n+# but also with moderator account that has \"push --force\" and \"push --delete\" permissions.\n+#\n+# Based on update.sample.\n+\n+if [ \"$REMOTE_USER\" == \"mod\" ]; then exit 0; fi\n+\n+# --- Command line\n+refname=\"$1\"\n+oldrev=\"$2\"\n+newrev=\"$3\"\n+\n+# --- Safety check\n+if [ -z \"$GIT_DIR\" ]; then\n+\techo \"Don't run this script from the command line.\" >&2\n+\techo \" (if you want, you could supply GIT_DIR then run\" >&2\n+\techo \"  $0 <ref> <oldrev> <newrev>)\" >&2\n+\texit 1\n+fi\n+\n+if [ -z \"$refname\" -o -z \"$oldrev\" -o -z \"$newrev\" ]; then\n+\techo \"Usage: $0 <ref> <oldrev> <newrev>\" >&2\n+\texit 1\n+fi\n+\n+# check for no description\n+projectdesc=$(sed -e '1q' \"$GIT_DIR/description\")\n+case \"$projectdesc\" in\n+\"Unnamed repository\"* | \"\")\n+\techo \"*** Project description file hasn't been set\" >&2\n+\texit 1\n+\t;;\n+esac\n+\n+# --- Check types\n+# if $newrev is 0000...0000, it's a commit to delete a ref.\n+zero=\"0000000000000000000000000000000000000000\"\n+if [ \"$newrev\" = \"$zero\" ]; then\n+\tnewrev_type=delete\n+else\n+\tnewrev_type=$(git-cat-file -t $newrev)\n+\n+\tm=\"`git merge-base $newrev $oldrev`\"\n+\tif [ \"$oldrev\" != \"$zero\" -a \"$m\" != \"$oldrev\" ] ; then\n+\t    echo \"Non-fast-forward!\" >&2;\n+\t    exit 1;\n+\tfi;\n+fi\n+\n+\n+case \"$refname\",\"$newrev_type\" in\n+\trefs/tags/*,commit)\n+\t\t# un-annotated tag\n+\t\tshort_refname=${refname##refs/tags/}\n+\t\t    echo \"*** The un-annotated tag, $short_refname, is not allowed in this repository\" >&2\n+\t\t    echo \"*** Use 'git tag [ -a | -s ]' for tags you want to propagate.\" >&2\n+\t\t    exit 1\n+\t\t;;\n+\trefs/tags/*,delete)\n+\t\t# delete tag\n+\t\t    echo \"*** Deleting a tag is not allowed in this repository\" >&2\n+\t\t    exit 1\n+\t\t;;\n+\trefs/tags/*,tag)\n+\t\t# annotated tag\n+\t\tif git rev-parse $refname > /dev/null 2>&1\n+\t\tthen\n+\t\t\techo \"*** Tag '$refname' already exists.\" >&2\n+\t\t\techo \"*** Modifying a tag is not allowed in this repository.\" >&2\n+\t\t\texit 1\n+\t\tfi\n+\t\t;;\n+\trefs/heads/*,commit)\n+\t\t# create branch\n+\t\tif [ \"$oldrev\" = \"$zero\" ]; then\n+\t\t\t#exit 1  # Uncomment it to disallow creating new branches\n+\t\t\t:;\n+\t\tfi\n+\t\t;;\n+\trefs/heads/*,delete)\n+\t\t# delete branch\n+\t\techo \"*** Deleting a branch is not allowed in this repository\" >&2\n+\t\texit 1\n+\t\t;;\n+\trefs/remotes/*,commit)\n+\t\t# tracking branch\n+\t\texit 1;\n+\t\t;;\n+\trefs/remotes/*,delete)\n+\t\t# delete tracking branch\n+\t\techo \"*** Deleting a tracking branch is not allowed in this repository\" >&2\n+\t\texit 1\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+\t\texit 1\n+\t\t;;\n+esac\n+\n+# --- Finished\n+exit 0\n-- \n1.7.1\n"},{"id":"145930","messageId":"20100721103710.GA2122@localhost.localdomain","threadId":"24452","inReplyTo":"1279675387-15280-1-git-send-email-public_vi@tut.by","subject":"Re: [PATCH] contrib: Add update-http-moderated hook","fromName":"Jared Hance","fromEmail":"jaredhance@gmail.com","sentAt":"2010-07-21T10:37:10Z","receivedAt":"2010-07-21T10:37:10Z","isPatch":true,"sender":{"key":"jaredhance@gmail.com","avatar":"https://avatars.githubusercontent.com/u/170192?v=4"},"body":"On Wed, Jul 21, 2010 at 04:23:07AM +0300, public_vi@tut.by wrote:\n> +#           Require User mod\n\n> +if [ \"$REMOTE_USER\" == \"mod\" ]; then exit 0; fi\n\nPerhaps, for easier configurability, you should at the very least have\na variable at the top such as GIT_MOD_USER=mod in case the users of\nthis script want to change it at some point.\n"}]}