Last active
June 25, 2021 20:24
-
-
Save ryansutc/25843ba02e4f2b44898edb4221f6d57d to your computer and use it in GitHub Desktop.
This is a template [git hook](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks) for Motionary (or any javascript repo). The below file is intended as a client-side pre-commit hook that will prevent you from accidentally committing code with prohibited keywords: `debugger` <-- never worry about accidentally committing a file with this aga…
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
#!/bin/sh | |
# | |
# An example hook script to verify what is about to be committed. | |
# Called by "git commit" with no arguments. The hook should | |
# exit with non-zero status after issuing an appropriate message if | |
# it wants to stop the commit. | |
# | |
# To enable this hook, rename this file to "pre-commit". | |
if git rev-parse --verify HEAD >/dev/null 2>&1 | |
then | |
against=HEAD | |
else | |
# Initial commit: diff against an empty tree object | |
against=$(git hash-object -t tree /dev/null) | |
fi | |
for FILE in `git diff-index --cached --name-status $against -- | cut -c3-` ; do | |
# Check if the file contains 'debugger' | |
if grep --quiet '^\s*debugger' $FILE --include=*.js; then | |
echo $FILE ' contains debugger!' | |
exit 1 | |
fi | |
done | |
for FILE in `git diff-index --cached --name-status $against -- | cut -c3-` ; do | |
# Check if the file contains '.only(' (unit test no-no)' | |
if grep --quiet '\.only(' $FILE --include=*.js; then | |
echo $FILE ' contains .only!' | |
exit 1 | |
fi | |
done | |
for FILE in `git diff-index --cached --name-status $against -- | cut -c3-` ; do | |
# Check if the file contains '.skp(' (unit test no-no) | |
if grep --quiet '\.skip(' $FILE --include=*.js; then | |
echo $FILE ' contains .skip!' | |
exit 1 | |
fi | |
done | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment