Skip to content

Instantly share code, notes, and snippets.

Last active December 5, 2023 21:11
  • Star 7 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Git Pre Commit Hook for FIXME TODO
# An hook script to verify changes to be committed do not contain
# any 'FIXME:' comments. Called by "git commit" with no arguments.
# The hook should exit with non-zero status after issuing an appropriate
# message if it stops the commit.
# To bypass this hook, use the "--no-verify" parameter when committing.
# Redirect output to stderr.
exec 1>&2
# Define colors
# Define what term will be searched for.
# Check for the presence of the SEARCH_TERM in updated files.
if [[ $(git diff --cached | grep -E "^\+" | grep -v '+++ b/' | cut -c 2-) == *$SEARCH_TERM_FIXME* ] || [ $(git diff --cached | grep -E "^\+" | grep -v '+++ b/' | cut -c 2-) == *$SEARCH_TERM_TODO* ]]
printf "${RED}Error:${NC} Found ${SEARCH_TERM_FIXME} | ${SEARCH_TERM_TODO} in attempted commit.\n"
printf "Please remove all occurances of ${SEARCH_TERM_FIXME} | ${SEARCH_TERM_TODO} before committing.\n"
exit 1
Copy link

isbkch commented Jul 5, 2023

Example of how to use it with pre-commit ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment