Initial Commit

This commit is contained in:
Brian Buller 2019-02-21 09:02:42 -06:00
parent 07dade08f4
commit 82327f7292
2 changed files with 32 additions and 0 deletions

View File

@ -1,2 +1,12 @@
# git-hooks
This is where I store git hooks that I frequently use in projects.
Right now there is one:
## pre-commit-todos:
A hook that blocks forbidden code from being committed, I use it to make sure
that anything flagged with 'TODO:' gets taken care of before committing.
It also has a chunk in there to display 'TODO-WARN:' as warnings when
committing, but still allows the commit.

22
pre-commit-todos/pre-commit Executable file
View File

@ -0,0 +1,22 @@
#!/bin/bash
#
# Pre commit hook that Warns about code being commited.
# Add unwanted code to the WARNING array as necessary
WARNING=( "TODO-WARN:" )
for i in "${WARNING[@]}"
do
git diff --cached --name-only | \
GREP_COLOR='7;4;37;41' xargs grep --color --with-filename -n $i
done
# Pre commit hook that prevents FORBIDDEN code from being commited.
# Add unwanted code to the FORBIDDEN array as necessary
FORBIDDEN=( "TODO:" )
for i in "${FORBIDDEN[@]}"
do
git diff --cached --name-only | \
GREP_COLOR='4;5;37;41' xargs grep --color --with-filename -n $i && \
echo 'COMMIT REJECTED Found' $i 'references. Please remove them before commiting' && exit 1
done
exit $ERR