How to disable git push when there is TODO in the code?

We have a problem in our team, and we decided to check if there is a way or git to reject git push, where the code has TODO. Any ideas? Thanks in advance.

+7
source share
2 answers

It is not possible to use pre-receive hooks in github, so we use client-side pre-commit hooks instead: http://git-scm.com/book/en/Customizing-Git-Git-Hooks#Client-Side-Hooks

Our pre-commit script (based on http://mark-story.com/posts/view/using-git-commit-hooks-to-prevent-stupid-mistakes ) looks like this:

#!/bin/sh for FILE in `git diff-index -p -M --name-status HEAD -- | cut -c3-` ; do if [ "grep 'TODO' $FILE" ] then echo $FILE ' contains TODO' exit 1 fi done exit 

We have this script under our version control system and create a symbolic link to it in .git / hooks

Thanks for the help:)

EDIT: due to the grep behavior in the if statement, we needed to edit our script:

 #!/bin/sh for FILE in `git diff --name-only --cached`; do grep 'TODO' $FILE 2>&1 >/dev/null if [ $? -eq 0 ]; then echo $FILE ' contains TODO' exit 1 fi done exit 
+9
source

Pre-get the hook on the server, grep files and abort the click :)

More information on the hook for receiving can be found here: http://git-scm.com/book/en/Customizing-Git-Git-Hooks#Server-Side-Hooks

+4
source

All Articles