Skip to content

Instantly share code, notes, and snippets.

@jeremysears
Last active September 25, 2023 19:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremysears/649db9192301be841e90aba756624ea3 to your computer and use it in GitHub Desktop.
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.
#!/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
@Jakob-Unfried
Copy link

Jakob-Unfried commented Sep 25, 2023

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 any FIXME tags, this hook will let you push.

Replace git diff HEAD~1 HEAD with git diff @{push} @ to check all commits that would be pushed instead of just the most recent one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment