From f7cad3351856e49f96a44d8e96deea2451026052 Mon Sep 17 00:00:00 2001 From: Matthew Hughes Date: Tue, 23 Feb 2021 21:36:41 +0000 Subject: [PATCH] Use exclusion syntax for git diff filtering Since git 1.8.5 [1], '--diff-filter' can take lowercase args to mean "show everything but these classes". Use this to exclude deleted files rather than specify every other class. [1] https://git.kernel.org/pub/scm/git/git.git/tree/Documentation/RelNotes/1.8.5.txt#n186 --- pre_commit/git.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pre_commit/git.py b/pre_commit/git.py index bec816c9..f11ff842 100644 --- a/pre_commit/git.py +++ b/pre_commit/git.py @@ -127,8 +127,7 @@ def get_staged_files(cwd: Optional[str] = None) -> List[str]: return zsplit( cmd_output( 'git', 'diff', '--staged', '--name-only', '--no-ext-diff', '-z', - # Everything except for D - '--diff-filter=ACMRTUXB', + '--diff-filter=d', cwd=cwd, )[1], )