Run syntax checks against file contents actually staged in the index
Run syntax checks against file contents actually staged in the index

Our pre-commit hook was giving us a false sense of security about the
validity of the code we were checking in.

It is possible to stage bad changes in the index (for example, by
staging bad hunks with "git add -i" or "git add --patch", or to "git
add" whole files and then make further modifications before actually
committing) and our syntax checks will end up running against what's in
the work tree, and not against what is actually staged in the index to
be committed.

To fix this we dump the contents of the files as they are staged in the
index into temporary files, and run our syntax checks against those
files and not against the contents of the work tree.

We introduce a StagedFile class to make this as convenient as possible.
Note that because we're using Tempfile from the standard library, the
temporary files will go away once the corresponding objects are
garbage-collected.

With this change we can be more confident about preventing syntax errors
from getting committed, although we are still vulnerable to errors in
Ruby files which don't get checked because they don't have an ".rb"
extension (common examples include "Capfile", "Rakefile", "Gemfile" and
so on).

Story:
  https://www.pivotaltracker.com/story/show/12365833

oxocode/overcommit,gnagel/overcommit,blech75/overcommit,gnagel/overcommit,TheSooth/overcommit,oxocode/overcommit,TheSooth/overcommit,blech75/overcommit