Last active
July 6, 2020 15:40
-
-
Save aberezin/7078ec087c7e4f8a078dd518d30a75bf to your computer and use it in GitHub Desktop.
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
# from https://medium.com/@ripoche.b/using-global-pre-commit-hook-to-prevent-committing-unwanted-code-edbbf957ad12 | |
# | |
# To prevent debug code from being accidentally committed, simply add a comment near your | |
# debug code containing the keyword NO_GITCOMMIT (with underscore gone) and this script will abort the commit. | |
# | |
# I also made this available here | |
# https://gist.github.com/aberezin/7078ec087c7e4f8a078dd518d30a75bf | |
# | |
if git commit -av --dry-run | grep $(echo NO_GITCOMMIT | tr -d _) >/dev/null 2>&1 | |
then | |
echo "This is a global pre-commit hook talking: Trying to commit non-committable code." | |
echo "Remove the NO_GITCOMMIT (The tag is with the _ gone) string and try again." | |
echo "You might have that tag in a file that is not yet added to staged but this hook rejects all bc it is not yet smart enought to know if you are doing a git commit -a or not. Also, because of the way the this hook is written, it will catch the previous commit that had a this tag. In either case, you can use --no--verify to force the commit." | |
exit 1 | |
fi | |
if [ -d $(git rev-parse --show-toplevel)/.gitsecret ]; then | |
#This is flawed in that it will error out if any of the revealed files are already deleted | |
#We can deal with that by running true after calling it. | |
#But the bigger problem is that when it creates new .secret files, those wont be added to the index | |
#If it could give us a list of file paths that it created, we could add those | |
#We could parse the .gitsecret/paths/mapping.cfg | |
#git secret hide -d -P | |
true | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment