Skip to content

Instantly share code, notes, and snippets.

@JJ
Forked from ilyakatz/pre-commit
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JJ/766a982621a1c1c7455f to your computer and use it in GitHub Desktop.
Save JJ/766a982621a1c1c7455f to your computer and use it in GitHub Desktop.
#!/bin/bash -l
# A git hook script to find and fix trailing whitespace
# in your commits. Bypass it with the --no-verify option
# to git-commit
#
.git/hooks/pre-commit-master-no-no
if [[ $? == 1 ]]
then
exit 1
fi
.git/hooks/pre-commit-debugger
.git/hooks/pre-commit-trailing-spaces
.git/hooks/pre-commit-images
.git/hooks/pre-commit-pair
#!/bin/sh
# Originally from http://mark-story.com/posts/view/using-git-commit-hooks-to-prevent-stupid-mistakes,
# but does not work now and can be simplified
if git rev-parse --verify HEAD >/dev/null 2>&1; then
against=HEAD
else
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
for FILE in `git diff-index --name-only $against` ; do
# Check if the file contains 'debugger'
echo $FILE $against
if [ "grep 'debugger' $FILE" ]
then
echo $FILE ' contains debugger!'
exit 1
fi
done
exit
#!/bin/bash -l
echo "Optimizing images"
# Find image files and optimize them
for FILE in `exec git diff --cached --name-status | grep ".png$" | awk '$1 != "R" { print $2 }'`; do
echo "Optimizing $FILE"
bundle exec smusher $FILE
git add "$FILE"
done
#!/bin/bash
#Hook to verify that comments are not done to the master branch accidentally
#Need to check the status and exit the hook if this script exits with a non-zero code
#.git/hooks/pre-commit-master-no-no
#if [[ $? == 1 ]]
#then
# exit 1
#fi
if [[ `git symbolic-ref HEAD` == "refs/heads/master" ]]
then
if [[ ! -f /tmp/master_commit ]]
then
echo "*************************"
echo "CANNOT COMMIT TO MASTER!"
echo "To override this behavior"
echo "touch /tmp/master_commit"
echo "*************************"
exit 1
else
echo "Removing /tmp/master_commit"
rm /tmp/master_commit
fi
fi
#!/bin/bash
#Really, I don't know what this did originally. didn't make too much sense
echo `git var -l |grep user`
#!/bin/bash
echo "Remove trailing spaces"
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
echo $against
# Find files with trailing whitespace
for FILE in `exec git diff-index --check $against -- | sed '/^[+-]/d' | (sed -r 's/:[0-9]+:.*//' > /dev/null 2>&1 || sed -E 's/:[0-9]+:.*//') | uniq` ; do
# Fix them!
echo $FILE
(sed -i 's/[[:space:]]*$//' "$FILE" > /dev/null 2>&1 || sed -i '' -E 's/[[:space:]]*$//' "$FILE")
git add "$FILE"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment