Initial Commit
This commit is contained in:
		
							
								
								
									
										10
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								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.
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										22
									
								
								pre-commit-todos/pre-commit
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										22
									
								
								pre-commit-todos/pre-commit
									
									
									
									
									
										Executable 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
 | 
			
		||||
		Reference in New Issue
	
	Block a user