Created
June 12, 2012 22:11
-
-
Save justincaldwell/2920444 to your computer and use it in GitHub Desktop.
Pre commit hook to check syntax - Add to ./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
| #!/usr/bin/env ruby | |
| # vim: set syntax=ruby | |
| flag = false | |
| staged_files = `git diff --cached --name-only`.split | |
| ruby_files = staged_files.select{|s| s =~ /\.rb$/} | |
| ruby_files.each do |file| | |
| puts "Checking #{file}" | |
| result = `ruby -c #{file}` | |
| flag = true if $?.exitstatus > 0 | |
| end | |
| abort("Failed syntax check. Fix and recommit.") if flag | |
| puts "All staged files passed syntax check. Continuing 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
| #!/usr/bin/env ruby | |
| # vim: set syntax=ruby | |
| flag = false | |
| staged_files = `git diff --cached --name-only`.split | |
| ruby_files = staged_files.select{|s| s =~ /\.(rb|rhtml)$/} | |
| ruby_files.each do |file| | |
| puts "Checking #{file}" | |
| command = (file =~ /rb$/) ? 'ruby -c' : './script/tv' | |
| result = `#{command} #{file}` | |
| flag = true if $?.exitstatus > 0 | |
| end | |
| abort("Failed syntax check. Fix and recommit.") if flag | |
| puts "All staged files passed syntax check. Continuing commit..." | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment