From 82327f729241ce9bc12d01f3bcb8017487d5e92a Mon Sep 17 00:00:00 2001 From: Brian Buller Date: Thu, 21 Feb 2019 09:02:42 -0600 Subject: [PATCH] Initial Commit --- README.md | 10 ++++++++++ pre-commit-todos/pre-commit | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100755 pre-commit-todos/pre-commit diff --git a/README.md b/README.md index e8f67d9..7cb0955 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/pre-commit-todos/pre-commit b/pre-commit-todos/pre-commit new file mode 100755 index 0000000..d517456 --- /dev/null +++ b/pre-commit-todos/pre-commit @@ -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