Skip to content

Instantly share code, notes, and snippets.

@Aldaviva
Last active November 5, 2022 12:55
Show Gist options
  • Save Aldaviva/2c6c8c41b3fae66cac32 to your computer and use it in GitHub Desktop.
Save Aldaviva/2c6c8c41b3fae66cac32 to your computer and use it in GitHub Desktop.
Prevent commits with FIXME
#!/bin/sh
if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
filenamePattern='\.(js|json|java|html|htm|php|xml|css|less|groovy|nsi|nsh|properties|cs|xaml|csproj|sh|bash|bat|cmd|ps1|svg|md)$'
disallowedTokenPattern='\bFIXME\b'
git diff-index --cached --name-only --diff-filter=ACMRTUXB $against | \
grep -E $filenamePattern | \
xargs grep -E --with-filename -n --after-context=0 $disallowedTokenPattern && \
echo -e "\nFound FIXME. Get rid of the temporary hacks and use \`git add; git commit\` to proceed." && \
exit 1
exit 0
@Aldaviva
Copy link
Author

Aldaviva commented Nov 5, 2022

To install this for all repositories in your user account:

  1. Save this file as pre-commit in some directory, such as ~/.git-hooks/.
  2. Set the file to be executable.
    chmod +x pre-commit
  3. Tell Git to use that directory to look for hooks.
    git config --global core.hookspath ~/.git-hooks/

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