Created
March 15, 2021 03:32
-
-
Save wingkwong/b55a035a274191f35972f626cf5a5dfb to your computer and use it in GitHub Desktop.
A pre-receive hook script to prevent someone to commit certain files
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 | |
# Check to see if this is the first commit in the repository or not | |
if git rev-parse --verify HEAD >/dev/null 2>&1 | |
then | |
# We compare our changes against the previous commit | |
against=HEAD^ | |
else | |
# Initial commit: diff against an empty tree object | |
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 | |
fi | |
# Redirect output to screen. | |
exec 1>&2 | |
# Check to see if we have updated the given file | |
if [ $(git diff-tree -r --name-only $against | grep <FILE_TO_BE_EXCLUDED> ) ]; | |
then | |
# Output colors | |
red='\033[0;31m'; | |
green='\033[0;32m'; | |
yellow='\033[0;33m'; | |
default='\033[0;m'; | |
echo "${red}" | |
echo " " | |
echo " |ZZzzz " | |
echo " | " | |
echo " | " | |
echo " |ZZzzz /^\ |ZZzzz " | |
echo " | |~~~| | " | |
echo " | |- -| / \ " | |
echo " /^\ |[]+ | |^^^| " | |
echo " |^^^^^^^| | +[]| | | " | |
echo " | +[]|/\/\/\/\^/\/\/\/\/|^^^^^^^| " | |
echo " |+[]+ |~~~~~~~~~~~~~~~~~~| +[]| " | |
echo " | | [] /^\ [] |+[]+ | " | |
echo " | +[]+| [] || || [] | +[]+| " | |
echo " |[]+ | || || |[]+ | " | |
echo " |_______|------------------|_______| " | |
echo " " | |
echo " " | |
echo "${red} You are not allowed to commit this file " | |
echo " " | |
echo "${default}" | |
fi; | |
# set the exit code to 0 or 1 based upon your needs | |
# 0 = good to push | |
# 1 = exit without pushing. | |
exit 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment