Skip to content

Instantly share code, notes, and snippets.

@athiththan11
Last active December 5, 2023 21:11
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save athiththan11/8d2650a683d7751b5eb9305d8936e3c2 to your computer and use it in GitHub Desktop.
Save athiththan11/8d2650a683d7751b5eb9305d8936e3c2 to your computer and use it in GitHub Desktop.
Git Pre Commit Hook for FIXME TODO
#!/bin/sh
# 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
RED='\033[0;31m'
NC='\033[0m'
# Define what term will be searched for.
SEARCH_TERM_FIXME="FIXME:"
SEARCH_TERM_TODO="TODO:"
# 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* ]]
then
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
fi
@isbkch
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