Merge pull request #376 from pre-commit/dont_run_on_deleted_files

Don't run on deleted files.  Resolves #374
This commit is contained in:
Anthony Sottile 2016-05-25 09:32:01 -07:00
commit 00bed9ea2f
2 changed files with 15 additions and 1 deletions

View file

@ -69,7 +69,11 @@ def get_conflicted_files():
@memoize_by_cwd @memoize_by_cwd
def get_staged_files(): 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 @memoize_by_cwd

View file

@ -33,6 +33,16 @@ def test_get_root_not_git_dir(tempdir_factory):
git.get_root() 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): def test_is_not_in_merge_conflict(tempdir_factory):
path = git_dir(tempdir_factory) path = git_dir(tempdir_factory)
with cwd(path): with cwd(path):