Skip to content

Instantly share code, notes, and snippets.

@justincaldwell
Created June 12, 2012 22:11
Show Gist options
  • Save justincaldwell/2920444 to your computer and use it in GitHub Desktop.
Save justincaldwell/2920444 to your computer and use it in GitHub Desktop.
Pre commit hook to check syntax - Add to ./git/hooks/pre-commit
#!/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..."
#!/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