Skip to content

Instantly share code, notes, and snippets.

@romanosipenko
Last active March 29, 2017 15:05
Show Gist options
  • Select an option

  • Save romanosipenko/a49ab6afaddf34cc447df6add50bd439 to your computer and use it in GitHub Desktop.

Select an option

Save romanosipenko/a49ab6afaddf34cc447df6add50bd439 to your computer and use it in GitHub Desktop.
Git pre-commit hook to check alowance of making commit acording to autors/contributors file in repository.
#!/bin/sh
REPO_ROOT=`git rev-parse --show-toplevel`
AUTHORS_FILE="AUTHORS.txt"
if grep -xq "${GIT_AUTHOR_NAME} <${GIT_AUTHOR_EMAIL}>" "${REPO_ROOT}/${AUTHORS_FILE}"
then
exit 0;
else
echo "********************************************************************************"
echo "* ERROR 100500: You are not allowed to commit into this repository. *"
echo "********************************************************************************"
echo ""
echo " Reason: Your git author name and email are not found in ${AUTHORS_FILE}."
echo " Provided author name: ${GIT_AUTHOR_NAME}"
echo " email: ${GIT_AUTHOR_EMAIL}"
echo ""
echo " You have to run:"
echo " \tgit config user.name \"YOUR NAME\""
echo " \tgit config user.email \"YOUR EMAIL\""
echo " or, add yourself into ${REPO_ROOT}/${AUTHORS_FILE}."
exit 1
fi
Copy link

ghost commented Mar 29, 2017

yourself

@alexryabtsev
Copy link

Passes the test from 2 meters

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