Skip to content

Instantly share code, notes, and snippets.

@Cazz0r
Created February 16, 2020 23:26
Show Gist options
  • Save Cazz0r/896bf80c184e7077ab219d54ad6d7f31 to your computer and use it in GitHub Desktop.
Save Cazz0r/896bf80c184e7077ab219d54ad6d7f31 to your computer and use it in GitHub Desktop.
git pre-commit disallow user from committing
#!/bin/sh
# Retrieve author information as Git sees it while commiting
AUTHORINFO=$(git var GIT_AUTHOR_IDENT) || exit 1
NAME=$(printf '%s\n\n' "${AUTHORINFO}" | sed -n 's/^\(.*\) <.*$/\1/p')
EMAIL=$(printf '%s\n\n' "${AUTHORINFO}" | sed -n 's/^.* <\(.*\)> .*$/\1/p')
# If we're trying to commit to repo with not allowed email
if [[ $EMAIL == *"<REPLACE_ME>"* ]]; then
printf "NAME: %s\n" "${NAME}"
printf "EMAIL: %s\n" "${EMAIL}"
echo "\nOh, please stop. I cannot allow you to commit with your current email: ${EMAIL}\n"
exit 1;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment