Last active
September 25, 2023 19:50
-
-
Save jeremysears/649db9192301be841e90aba756624ea3 to your computer and use it in GitHub Desktop.
An interactive Git pre-push hook to prevent submission of FIXME tags, unless acknowledged.
This file contains hidden or 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
#!/usr/bin/env bash | |
matches=$(git diff HEAD~1 HEAD | grep -E '\+.*?FIXME') | |
if [ "$matches" != "" ]; then | |
echo >&2 "A 'FIXME' tag has been detected. Please fix all 'FIXME' tags before committing." | |
echo >&2 "" | |
echo >&2 "Matching FIXME:" | |
echo >&2 "${matches}" | |
echo >&2 "" | |
echo >&2 "Type 'FIXME' if you would like to commit anyway, otherwise press any key:" | |
exec < /dev/tty | |
read -p "(FIXME|any key)>: " ack | |
if [ "${ack}" != "FIXME" ]; then | |
echo >&2 "Exiting... Please fix any 'FIXME' tags and resubmit." && exit 1 | |
fi | |
echo "Ignoring 'FIXME' and pushing anyway" | |
exec <&- | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Found this on google. Thanks for making things public =)
Note, though that this only checks the previous commit.
I.e. if you commit changes that include
FIXME
and then commit another patch without anyFIXME
tags, this hook will let you push.Replace
git diff HEAD~1 HEAD
withgit diff @{push} @
to check all commits that would be pushed instead of just the most recent one.