forked from rubensayshi/bashtools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-pre-commit-nodebug
More file actions
executable file
·35 lines (28 loc) · 905 Bytes
/
Copy pathgit-pre-commit-nodebug
File metadata and controls
executable file
·35 lines (28 loc) · 905 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/bash
# Pre commit hook that prevents FORBIDDEN code from being commited.
# Add unwanted code to the FORBIDDEN array as necessary
NONE='\033[00m'
RED='\033[01;31m'
GREEN='\033[01;32m'
YELLOW='\033[01;33m'
PURPLE='\033[01;35m'
CYAN='\033[01;36m'
WHITE='\033[01;37m'
BOLD='\033[1m'
UNDERLINE='\033[4m'
FORBIDDEN=( "debugger" "console.log" "nocommit" )
GITDIFF="git diff --cached"
for i in "${FORBIDDEN[@]}"; do
# only process files that are staged
for file in `$GITDIFF --name-only`; do
# check if we can find our forbidden keyword in the staged diff
found=$($GITDIFF $file | grep $i)
if [ -n "$found" ]; then
GREP_COLOR='4;5;37;41' grep --color --with-filename -n $i $file && \
echo 'COMMIT REJECTED Found' $i 'references. Please remove them before commiting' && \
exit 1
fi
done
done
tput sgr0
exit 0