Skip to content

Instantly share code, notes, and snippets.

@coryodaniel
Forked from athiththan11/pre-commit
Last active July 9, 2022 22:43
Show Gist options
  • Save coryodaniel/6575466155b1b8e505ecc047fe5c4bcd to your computer and use it in GitHub Desktop.
Save coryodaniel/6575466155b1b8e505ecc047fe5c4bcd to your computer and use it in GitHub Desktop.
Git Pre Commit Hook for FIXME TODO
- id: deny-todos
name: Denies TODOs or FIXME
description: 'Denies TODOs or FIXME in commits'
entry: run.sh
language: script

Usage:

- repo: https://gist.github.com/coryodaniel/6575466155b1b8e505ecc047fe5c4bcd
    rev: 56dcacd575e88fc2b8052a6cf3c4ff9bf77ab62d
    hooks:
      - id: deny-todos
#!/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