Created
August 2, 2011 13:48
-
-
Save fhwang/1120210 to your computer and use it in GitHub Desktop.
Git pre-commit hook for JSHint and Rails
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
#!/usr/bin/env ruby | |
# To use this: | |
# * Set up the jshint Gem with your Rails app: https://github.com/liquid/jshint_on_rails | |
# * Copy this file to [YOURPROJECT]/.git/hooks/pre-commit | |
# * chmod 0755 .git/hooks/pre-commit | |
files_changed = `git diff --name-only HEAD` | |
if files_changed.any? { |line| line =~ %r|public/javascripts| } | |
puts "Running jshint to check changes to javascript ..." | |
result = `bundle exec rake jshint` | |
if result =~ /Found \d+ error/ | |
puts "==========================================================================================" | |
puts " COMMIT ABORTED" | |
puts "==========================================================================================" | |
puts result | |
exit 1 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment