Take 2 at properly linting merge commits.
Take 2 at properly linting merge commits.

Summary:
My previous approach ignored any files that were touched after the
'git merge' command was run.  So if in the course of resolving
conflicts you touched an entirely new file, or even 'git rm'ed a file,
we wouldn't notice.  This caused a problem when a conflict resolver
git-rm'ed a file and then the linter tried to lint it anyway:
   https://app.asana.com/0/27216215224639/42492845311895

This makes it clear that any solution I use has to use '--cached' to
take into account staged changes.  I think this limits me to 'git
diff' (though my git-fu isn't so great).  I use a simple technique to
use git-diff against the branches being merged, and take the files
that are listed in both of them.

This technique isn't perfect because if a file was modified in both of
the merge parents, we'll mark it as needing to be linted, even if that
file had a 'trivial' merge (because the modifications were in
unrelated parts of the file, say).  But at worst that means we'll lint
a bit more than we have to, which is inefficient but not a bug.

Test Plan:
I changed githook.py to add
    raise ValueError(files_to_lint)
at the end of the is_merge_commit branch, and ran the following in the
webapp repo:
   git co d564cad11e89d15513915c0f1dcfd2fa417593ee
   git m 1972df702333849366cf0347dff76664070a9c92
   git checkout --theirs api/internal/test/topics_test.py
   make test_db
   git add api/internal/test/topics_test.py testutil/test_db.sqlite
   git commit
and it said:
   ValueError: ['testutil/make_test_db.py', 'testutil/test_db.sqlite', 'testutil/test_db.sqlite.blobdir/dev~khan-academy/n/ncoded_gs_file:a2FfZGVyaXZlZC92aWRlb19zY29yZXMvYjJhMjdmMjgtMjZiMS00MDRlLWExNWQtZmM3MmEyMWQ3NzBiLnR4dA==']

which are indeed the files that were modified and need to be linted.

In particular, it did //not// say:
   testutil/test_db.sqlite.blobdir/dev~khan-academy/n/ncoded_gs_file:a2FfZGVyaXZlZC92aWRlb19zY29yZXMvZjM3YjBiMTktYjkzOS00NWM3LTg4OTYtZWQyZTg0ZDA2MDMwLnR4dA==
(yes, I know that file looks the same as the other one, but it's not:
the end is MwLnR4dA==, instead of BiLnR4dA==) which is the file that
was deleted.

I then removed the 'raise ValueError' line and ran 'git commit' again,
and it succeeded.

Reviewers: chris, neel

Reviewed By: neel

Subscribers: alexirpan, davidwang, kevinb

Differential Revision: https://phabricator.khanacademy.org/D19844

Khan/khan-linter,Khan/khan-linter,Khan/khan-linter,Khan/khan-linter