Created
June 25, 2009 20:18
-
-
Save austintaylor/136133 to your computer and use it in GitHub Desktop.
.git/hooks
This file contains 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
#!/bin/bash | |
# Print out what changed in a nice format. | |
git log @{1}.. --pretty=format:"%Cblue%an%Creset %ar: %Cred\"%s%b\"%Creset (%h)" --reverse --no-merges | |
# Print out any new migrations | |
diff <(ls -l db/migrate/ | grep "[0-9]\{14\}" | sed -e 's/.*\([0-9]\{14\}\).*/\1/g' | sort) <((test -f db/development.sqlite3 && sqlite3 db/development.sqlite3 "select version from schema_migrations" || mysql -uroot `pwd | xargs basename`_development -e "select version from schema_migrations") | grep [0-9] | sort) | grep "< [0-9]\{14\}" | cut -d' ' -f2 | tr '\n' '|' | sed -e 's/\(.*\)|$/"\\\(\1\\\)"/' -e 's/|/\\\|/g' | xargs -J % grep % <(ls -l db/migrate | tail -100) | sed -e 's/.*\([0-9]\{14\}_.*\.rb\)/[34mPending migration: [31;1m\1[0m/g' | |
# Yes, I know about rake db:about_if_pending_migrations, but it's way too slow. | |
# On the other hand, this makes all kinds of assumptions about your database configuration. | |
# Looks first for db/development.sqlite3, then for a mysql database called [dirname]_development | |
# I'm not sure why, but the | tail -100 keeps it from hanging when there are no pending migrations. | |
# Output any changes to the Gemfile | |
OUTPUT=$(git diff -w -U0 @{1}.. -- Gemfile | sed -e "1,4d" -e "/@@/d" -e "/[+-] *$/d" -e "s/^\+ *\(.*\)$/ \[32m+ \1[0m/" -e "s/^- *\(.*\)$/ \[31m- \1[0m/") | |
if [ -n "$OUTPUT" ] | |
then | |
echo "[30;1m** Gemfile changed **[0m" | |
echo "$OUTPUT" | |
fi |
This file contains 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
#!/bin/sh | |
# Clean up whitespace in any modified files. | |
if git-rev-parse --verify HEAD > /dev/null | |
then | |
against=HEAD | |
else | |
# Initial commit: diff against an empty tree object | |
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 | |
fi | |
old_IFS=$IFS | |
IFS=$'\n' | |
for FILE in `git-diff-index --check --cached $against 2>&1 | sed '/^[\*\+]/d' | sed 's/:.*//' | uniq` ; do | |
sed -ie 's/[[:space:]]*$//' $FILE | |
rm $FILE"e" | |
git add $FILE | |
done | |
IFS=$old_IFS | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment