3 # A hook script that blocks committer and author names that are
4 # root (or a configured blacklisted name).
5 # XXX: should allow only applying this to certain branches.
7 # Called by "git receive-pack" with arguments: refname sha1-old sha1-new
11 # hooks.noroot.branches
12 # List of branches for which commits by root should be disallowed.
14 # XXX: figure out format
25 if [ -z "$GIT_DIR" ]; then
26 echo "Don't run this script from the command line." >&2
27 echo " (if you want, you could supply GIT_DIR then run" >&2
28 echo " $0 <ref> <oldrev> <newrev>)" >&2
32 if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then
33 echo "Usage: $0 <ref> <oldrev> <newrev>" >&2
38 branches=$(git config --get hooks.noroot.branches || echo "")
39 # XXX: hooks.noroot.match
42 # if $newrev is 0000...0000, it's a commit to delete a ref.
43 zero="0000000000000000000000000000000000000000"
44 if [ "$newrev" = "$zero" ]; then
47 newrev_type=$(git cat-file -t $newrev)
50 case "$refname","$newrev_type" in
52 git log --pretty="format:%h \"%an\" \"%cn\"%n" "$oldrev".."$newrev" | \
53 while read hash an cn; do
54 if [ "$an" = "\"root\"" -o "$cn" = "\"root\"" ]; then
55 echo "*** Committing as root not allowed in this repository," >&2
56 echo "*** Please fix your GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL,"
57 echo "*** GIT_COMMITTER_NAME and GIT_COMMITTER_EMAIL."
58 echo "*** Offending commit was $hash."
63 refs/remotes/*,commit)
67 # we could track tags, but we've decided they're not
74 # Anything else (is there anything else?)
75 echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2