Git pre-commit hook to find text in files
Answer to mark this question as having an answer:
OP ended up with:
disallowed="word1 word2"git diff --cached --name-status | while read x file; do if [ "$x" == 'D' ]; then continue; fi for word in $disallowed do if egrep $word $file ; then echo "ERROR: Disallowed expression \"${word}\" in file: ${file}" exit 1 fi donedone || exit $?
I am using the same logic as above and even though the stagged file contains the disallowed word, it commits the changes to the branch. Any lead would be greatly appreciated.
#!/bin/bashimport osecho "Running pre-commit hook" checks=os.environ["APPSETTING_DEVPASSWORD"],os.environ["APPSETTING_DEVUSER"],os.environ["APPSETTING_DEVPASS_ELMAH"]git diff --cached --name-status | while read x file; do if [ "$x" == 'D' ]; then continue; fi for word in $checks do if egrep $word $file ; then echo "ERROR: Disallowed expression \"${word}\" in file: ${file}" exit 1 fi donedone || exit $?