Skip to content

Instantly share code, notes, and snippets.

@moro
Created January 21, 2011 10:35
Show Gist options
  • Save moro/789517 to your computer and use it in GitHub Desktop.
Save moro/789517 to your computer and use it in GitHub Desktop.
.git/hooks/pre-commit
#!/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:
@moro
Copy link
Author

moro commented Jan 22, 2011

injectつかわないでselectでいいよねぇ。

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