## Enforce that changed lines can only be documentation
#!/bin/sh
#
# This git pre-commit hook makes sure you haven't changed any Ruby code
# while contributing to documentation.
#
# Author: Mislav
#
# To enable this hook, make this file executable.
if git-rev-parse --verify HEAD 2>/dev/null
then
git-diff-index -p -M --cached HEAD
else
# NEEDSWORK: we should produce a diff with an empty tree here
# if we want to do the same verification for the initial import.
:
fi | ruby -e '
file = nil
lineno = nil
errors = []
while gets
case $_
when /^\+{3} (.+)/
file = $1.sub(/^b\//, "")
# puts file
next
when /^-{3} /
next
when /^@@ -\d+,\d+ \+(\d+),(\d+) @@/
lineno = $1.to_i
next
when /^([+-])(.+)/
op = $1 == "+" ? "added" : "removed"
line = $2
if line !~ /^\s*#/
errors << "#{file}:#{lineno}: #{op} #{line.inspect}"
end
end
lineno += 1 if lineno
end
unless errors.empty?
$stderr.puts "Changed Ruby code detected!"
$stderr.puts errors.join
$stderr.puts "COMMIT FAILED."
exit 1
else
exit 0
end
'