Last active
August 21, 2018 22:13
-
-
Save avandrevitor/a78a60258dcd01922e061c7dffe4f612 to your computer and use it in GitHub Desktop.
Bash Example Pre-Receive
This file contains hidden or 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
#!/usr/bin/env bash | |
zero_commit="0000000000000000000000000000000000000000" | |
excludeExisting="--not --all" | |
while read oldrev newrev refname; do | |
echo $refname $oldrev $newrev | |
# branch or tag get deleted | |
if [ "$newrev" = "$zero_commit" ]; then | |
continue | |
fi | |
# Check for new branch or tag | |
if [ "$oldrev" = "$zero_commit" ]; then | |
span=`git rev-list $newrev $excludeExisting` | |
else | |
span=`git rev-list $oldrev..$newrev $excludeExisting` | |
fi | |
for COMMIT in $span; | |
do | |
commit_message=`git log -1 --format=%s $COMMIT`; | |
echo $commit_message | |
if ! [[ $commit_message =~ ^[[:alnum:]\#\.\'\/[:space:][:blank:]]+$ ]]; then | |
echo "================================================================= " | |
echo "██████╗ ███████╗ ██╗███████╗ ██████╗████████╗███████╗██████╗ " | |
echo "██╔══██╗██╔════╝ ██║██╔════╝██╔════╝╚══██╔══╝██╔════╝██╔══██╗ " | |
echo "██████╔╝█████╗ ██║█████╗ ██║ ██║ █████╗ ██║ ██║ " | |
echo "██╔══██╗██╔══╝ ██ ██║██╔══╝ ██║ ██║ ██╔══╝ ██║ ██║ " | |
echo "██║ ██║███████╗╚█████╔╝███████╗╚██████╗ ██║ ███████╗██████╔╝ " | |
echo "╚═╝ ╚═╝╚══════╝ ╚════╝ ╚══════╝ ╚═════╝ ╚═╝ ╚══════╝╚═════╝ " | |
echo "================================================================= " | |
echo " rule: carateres não permitidos " | |
echo " São permitidos apenas [[:alnum:]\#\.\'\/[:space:][:blank:]] " | |
echo "================================================================= " | |
exit 1 | |
fi | |
if ! [[ $commit_message =~ [[:alnum:]\#\.\'\/[:space:][:blank:]]{10,50} ]]; then | |
echo "================================================================= " | |
echo "██████╗ ███████╗ ██╗███████╗ ██████╗████████╗███████╗██████╗ " | |
echo "██╔══██╗██╔════╝ ██║██╔════╝██╔════╝╚══██╔══╝██╔════╝██╔══██╗ " | |
echo "██████╔╝█████╗ ██║█████╗ ██║ ██║ █████╗ ██║ ██║ " | |
echo "██╔══██╗██╔══╝ ██ ██║██╔══╝ ██║ ██║ ██╔══╝ ██║ ██║ " | |
echo "██║ ██║███████╗╚█████╔╝███████╗╚██████╗ ██║ ███████╗██████╔╝ " | |
echo "╚═╝ ╚═╝╚══════╝ ╚════╝ ╚══════╝ ╚═════╝ ╚═╝ ╚══════╝╚═════╝ " | |
echo "================================================================= " | |
echo " rule: mensagem de commite deve entre 10 e 50 caracteres " | |
echo "================================================================= " | |
exit 1 | |
fi | |
multiples=$(echo $commit_message | grep -ohc "[[:blank:][:punct:][:space:]][[:blank:][:punct:][:space:]][[:blank:][:punct:][:space:]]") | |
if ! [[ $multiples -eq 0 ]]; then | |
echo "================================================================= " | |
echo "██████╗ ███████╗ ██╗███████╗ ██████╗████████╗███████╗██████╗ " | |
echo "██╔══██╗██╔════╝ ██║██╔════╝██╔════╝╚══██╔══╝██╔════╝██╔══██╗ " | |
echo "██████╔╝█████╗ ██║█████╗ ██║ ██║ █████╗ ██║ ██║ " | |
echo "██╔══██╗██╔══╝ ██ ██║██╔══╝ ██║ ██║ ██╔══╝ ██║ ██║ " | |
echo "██║ ██║███████╗╚█████╔╝███████╗╚██████╗ ██║ ███████╗██████╔╝ " | |
echo "╚═╝ ╚═╝╚══════╝ ╚════╝ ╚══════╝ ╚═════╝ ╚═╝ ╚══════╝╚═════╝ " | |
echo "================================================================= " | |
echo " rule: não são permitidos multiplos caracteres de pontuação ou " | |
echo " espaço seguidos. " | |
echo "================================================================= " | |
exit 1 | |
fi | |
done | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment