Created
January 21, 2011 10:35
-
-
Save moro/789517 to your computer and use it in GitHub Desktop.
.git/hooks/pre-commit
This file contains hidden or 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
#!/Users/moro/opt/ruby192/bin/ruby | |
excludes = ['db/schema.rb'] | |
invalids = `git diff --name-only --cached`.each_line.inject([]) do |r, f| | |
f.strip! | |
if (f =~ /\.rb\Z/) && !excludes.include?(f) && (File.open(f, "r", &:gets) !~ /\A\#coding:/) | |
r << f | |
else | |
r | |
end | |
end | |
if invalids.empty? | |
exit 0 | |
else | |
$stderr.puts "-- WARN: no magic-comment --" | |
puts invalids | |
exit 1 | |
end | |
#vim:set ft=ruby: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
injectつかわないでselectでいいよねぇ。