Skip to content

Instantly share code, notes, and snippets.

@erikcox
Created December 11, 2015 03:31
Show Gist options
  • Save erikcox/5d6d78941ef3faddab9f to your computer and use it in GitHub Desktop.
Save erikcox/5d6d78941ef3faddab9f to your computer and use it in GitHub Desktop.
Add git pre-push hook to check for TODO: in comments
# create the pre-commit file & make it executable
touch .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
# The line below is important!
#!/bin/bash
# Don't push if TODO is in the source for HEAD
dont_push_flag="TODO"
flag_found=`git grep --color "$dont_push_flag" HEAD`
if [ -n "$flag_found" ]
then
# Display which commit the first occurence of the flag was found and exit failure
commit=`git log --pretty=format:'%Cred%h%Creset' -S "$dont_push_flag" | tail -n1`
echo "Found $flag_found, first occurence was in $commit, not pushing"
exit 1
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment