Skip to content

Instantly share code, notes, and snippets.

@ebrehault
Created December 4, 2017 16:01
Show Gist options
  • Save ebrehault/e76b64e86dd5c3fc06c11a08d89d1cc0 to your computer and use it in GitHub Desktop.
Save ebrehault/e76b64e86dd5c3fc06c11a08d89d1cc0 to your computer and use it in GitHub Desktop.
.git/hooks/precommit
#!/bin/sh
# Redirect output to stderr.
exec 1>&2
# enable user input
exec < /dev/tty
badimport='../core/lib'
# CHECK
if test $(git diff --cached | grep $badimport | wc -l) != 0
then
exec git diff --cached | grep -n $badimport
read -p "There are some occurrences of ../core/lib import at your modification. Are you sure want to continue? (y/n)" yn
echo $yn | grep ^[Yy]$
if [ $? -eq 0 ]
then
exit 0; #THE USER WANTS TO CONTINUE
else
exit 1; # THE USER DONT WANT TO CONTINUE SO ROLLBACK
fi
fi
badimport='../front-messaging'
# CHECK
if test $(git diff --cached | grep $badimport | wc -l) != 0
then
exec git diff --cached | grep -n $badimport
read -p "There are some occurrences of ../front-messaging import at your modification. Are you sure want to continue? (y/n)" yn
echo $yn | grep ^[Yy]$
if [ $? -eq 0 ]
then
exit 0; #THE USER WANTS TO CONTINUE
else
exit 1; # THE USER DONT WANT TO CONTINUE SO ROLLBACK
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment