Skip to content

Instantly share code, notes, and snippets.

@drewdhunter
Last active December 31, 2015 20:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save drewdhunter/8037753 to your computer and use it in GitHub Desktop.
Save drewdhunter/8037753 to your computer and use it in GitHub Desktop.
Pre commit hook useful for Magento projects
#!/usr/bin/env bash
set -eu
declare -a file_patterns=('app/code/core' 'app/Mage.php$' '^index.php$')
exit_status=0
while read x file; do
for file_pattern in ${file_patterns[@]}; do
if [[ $file =~ $file_pattern ]]; then
echo "Core change detected: $file" >&2
exit_status=1
fi
done
done < <(git diff --cached --name-status)
exit $exit_status;
@freestream
Copy link

You should make the following change to the code.

declare -a file_patterns=('app/code/core' 'app/Mage.php$' '^index.php$')

If you only look at index you will get false negatives.

In my case it found error with file Model/Source/Noindex.php

See my fork at https://gist.github.com/freestream/8954807

@ScreamingDev
Copy link

Nice one!
Remember that patches are okay ;)

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