Created
December 21, 2011 22:03
-
-
Save davefearon/1507927 to your computer and use it in GitHub Desktop.
A pre-receive hook for rejecting things not tagged
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
validate_ref() | |
{ | |
# --- Arguments | |
oldrev=$(git rev-parse $1) | |
newrev=$(git rev-parse $2) | |
refname="$3" | |
# oldrev could be 0s which means creating refname | |
# newrev could be 0s which means deleting refname | |
case "$refname" in | |
refs/tags/*) | |
tag=$(expr "$refname" : "refs/tags/\(.*\)") | |
topictag=$(expr "$tag" : "\(.*/.*\)") | |
if [ 0 -ne $(expr "$newrev" : "0*$") ]; then # deleting | |
# only topic tags can be deleted | |
if [ -z $topictag ]; then | |
fail=1 | |
echo >&2 "*** Deleting the tag $tag is not permitted. ***" | |
return | |
fi | |
return | |
fi | |
if [ "tag" != $(git cat-file -t $newrev) ]; then # unannotated tag | |
fail=1 | |
echo >&2 "*** The un-annotated tag, $tag, is not allowed in this repository." | |
echo >&2 "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." | |
return | |
fi | |
;; | |
*) | |
fail=1 | |
echo >&2 "*** pre-receive hook does not understand ref $refname in this repository. ***" | |
echo >&2 "*** Contact the repository administrator. ***" | |
;; | |
esac | |
} | |
fail="" | |
# Allow dual mode: run from the command line just like the update hook, or | |
# if no arguments are given then run as a hook script | |
if [ -n "$1" -a -n "$2" -a -n "$3" ]; then | |
# Output to the terminal in command line mode - if someone wanted to | |
# resend an email; they could redirect the output to sendmail | |
# themselves | |
PAGER= validate_ref $2 $3 $1 | |
else | |
while read oldrev newrev refname | |
do | |
validate_ref $oldrev $newrev $refname | |
done | |
fi | |
if [ -n "$fail" ]; then | |
exit $fail | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is this for github or git? github doesn't support pre-receive, does it? so I assume this is for git only?