Repository: pre-commit/pre-commit

Issue:
Newly gitignored (but file still exists) files are linted
(they should not be)

Discussion:

Patch:
diff --git a/pre_commit/git.py b/pre_commit/git.py
index 796a0b8..1f16b6e 100644
--- a/pre_commit/git.py
+++ b/pre_commit/git.py
@@ -69,7 +69,11 @@ def get_conflicted_files():
 
 @memoize_by_cwd
 def get_staged_files():
-    return cmd_output('git', 'diff', '--staged', '--name-only')[1].splitlines()
+    return cmd_output(
+        'git', 'diff', '--staged', '--name-only',
+        # Everything except for D
+        '--diff-filter=ACMRTUXB'
+    )[1].splitlines()
 
 
 @memoize_by_cwd


Test patch:
diff --git a/tests/git_test.py b/tests/git_test.py
index c4e0145..701d36b 100644
--- a/tests/git_test.py
+++ b/tests/git_test.py
@@ -33,6 +33,16 @@ def test_get_root_not_git_dir(tempdir_factory):
             git.get_root()
 
 
+def test_get_staged_files_deleted(tempdir_factory):
+    path = git_dir(tempdir_factory)
+    with cwd(path):
+        open('test', 'a').close()
+        cmd_output('git', 'add', 'test')
+        cmd_output('git', 'commit', '-m', 'foo', '--allow-empty')
+        cmd_output('git', 'rm', '--cached', 'test')
+        assert git.get_staged_files() == []
+
+
 def test_is_not_in_merge_conflict(tempdir_factory):
     path = git_dir(tempdir_factory)
     with cwd(path):