Skip to content

Instantly share code, notes, and snippets.

@cice
Forked from athiththan11/pre-commit
Last active March 9, 2023 08:28
Show Gist options
  • Save cice/153005554ff5438d0524d6ae428da647 to your computer and use it in GitHub Desktop.
Save cice/153005554ff5438d0524d6ae428da647 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 'DONTCOMMIT:' 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_DONTCOMMIT="DONTCOMMIT:"
# 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_DONTCOMMIT* ]]
then
printf "${RED}Error:${NC} Found ${SEARCH_TERM_DONTCOMMIT} in attempted commit.\n"
printf "Please remove all occurances of ${SEARCH_TERM_DONTCOMMIT} before committing.\n"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment