Skip to content

Instantly share code, notes, and snippets.

@kruzyk
Last active October 22, 2019 12:06
Show Gist options
  • Save kruzyk/8ab4de78d0e37f12c1fd068dedb4317f to your computer and use it in GitHub Desktop.
Save kruzyk/8ab4de78d0e37f12c1fd068dedb4317f to your computer and use it in GitHub Desktop.
GIT pre-commit
#!/bin/sh
# Redirect output to stderr.
exec 1>&2
# enable user input
exec < /dev/tty
consoleregexp='console'
# CHECK
if test $(git diff --cached | grep $consoleregexp | wc -l) != 0
then
exec git diff --cached | grep -ne $consoleregexp
read -p 'There are some occurrences of CONSOLE.log 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
dumpregexp='|dump}'
# CHECK
if test $(git diff --cached | grep $dumpregexp | wc -l) != 0
then
exec git diff --cached | grep -ne $dumpregexp
read -p 'There are some occurrences of DUMP at your modification. Are you sure want to continue? (y/n)' yn
echo -e $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
conflictregexp='/^[<>|=]{4,}/m'
# CHECK
if test $(git diff --cached | grep $conflictregexp | wc -l) != 0
then
exec git diff --cached | grep -ne $conflictregexp
read -p 'You’ve got leftover CONFLICT markers. Are you sure want to continue? (y/n)' yn
echo -e $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