Skip to content

Instantly share code, notes, and snippets.

@zing-rsa
Created January 23, 2024 09:05
Show Gist options
  • Save zing-rsa/f12e83a9c9ecd56b2365d5579c8e622e to your computer and use it in GitHub Desktop.
Save zing-rsa/f12e83a9c9ecd56b2365d5579c8e622e to your computer and use it in GitHub Desktop.
Pre-commit hook that prompts before commiting changes containing the word "TODO"
#!/bin/sh
. git-sh-setup # for die
if git-diff-index -p -M --cached HEAD -- \
| grep '^+' \
| grep -i TODO; then
# assign stdin to allow read
exec < /dev/tty
# read flag
read -p "[pre-commit hook] TODO detected in patch, abort commit? (Y/n) " yn
# close stdin
exec <&-
case $yn in
[Nn] ) exit 0;;
* ) die "[pre-commit hook] Commit blocked";;
esac
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment