Skip to content

Instantly share code, notes, and snippets.

@aalin
Created November 12, 2011 14:49
Show Gist options
  • Select an option

  • Save aalin/1360618 to your computer and use it in GitHub Desktop.

Select an option

Save aalin/1360618 to your computer and use it in GitHub Desktop.
pre-commit hook that checks syntax of changed files.
#!/usr/bin/env ruby
`git diff --cached --name-only --diff-filter=AM`.lines.each do |filename|
path = File.join(Dir.pwd, filename.strip)
puts "Checking syntax of #{ filename.strip }"
case filename
when /.haml$/
exit 1 unless system('haml', '--check', path)
when /.scss$/
exit 1 unless system('scss', '--check', path)
when /.rb$/
exit 1 unless system('ruby', '-c', path)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment