Last active
March 5, 2025 15:49
-
-
Save athiththan11/8d2650a683d7751b5eb9305d8936e3c2 to your computer and use it in GitHub Desktop.
Git Pre Commit Hook for FIXME TODO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For people coming here from Google...
.git/hooks/
folder.pre-commit
.However, this particular script seems to be broken or not portable. Perhaps on @athiththan11's system, /bin/sh is a symlink to zsh?
This one works on my Debian system: https://bia.is/git-pre-commit-hook-avoid-committing-fixmes/