Skip to content

Instantly share code, notes, and snippets.

@dmitrythaler
Last active January 11, 2016 16:52
Show Gist options
  • Select an option

  • Save dmitrythaler/234f8b2446391e52f361 to your computer and use it in GitHub Desktop.

Select an option

Save dmitrythaler/234f8b2446391e52f361 to your computer and use it in GitHub Desktop.
pre-receive gist hook, shared repository
#!/bin/bash
# this pre-receive hook returns error when you are trying to push your silly code to the PRODUCTION branch not being member of repo administrators group
REPOADMINGROUP='repo-admin'
GROUPS_=`groups`
PRODUCTIONBRANCH='master'
while read oldsha newsha REFNAME; do
# GROUPS_ line doesn't contain REPOADMINGROUP and REFNAME contains PRODUCTIONBRANCH
if [[ $GROUPS_ != *$REPOADMINGROUP* ]] && [[ $REFNAME == *PRODUCTIONBRANCH* ]]; then
echo pre-receive check ERROR: refname: $REFNAME - you are NOT ALLOWED to push to this branch
exit 255
else
echo pre-receive check OK
fi
done
@tulachana
Copy link
Copy Markdown

Hi, where did you place this hooks in GitHUb?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment