From aae31993cdad8776518acc49a21628579eadb831 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Thu, 13 Dec 2018 10:08:57 -0800 Subject: [PATCH] Switch back to `diff` instead of `diff-index` `diff-index` appears to act strangely with `git add --intent-to-add` --- pre_commit/staged_files_only.py | 5 ++--- tests/staged_files_only_test.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/pre_commit/staged_files_only.py b/pre_commit/staged_files_only.py index 1d0c3648..fb84e555 100644 --- a/pre_commit/staged_files_only.py +++ b/pre_commit/staged_files_only.py @@ -29,10 +29,9 @@ def staged_files_only(patch_dir): context. """ # Determine if there are unstaged files - tree = cmd_output('git', 'write-tree')[1].strip() retcode, diff_stdout_binary, _ = cmd_output( - 'git', 'diff-index', '--ignore-submodules', '--binary', - '--exit-code', '--no-color', '--no-ext-diff', tree, '--', + 'git', 'diff', '--ignore-submodules', '--binary', + '--exit-code', '--no-color', '--no-ext-diff', '--', retcode=None, encoding=None, ) diff --git a/tests/staged_files_only_test.py b/tests/staged_files_only_test.py index 42f7ecae..142f7a37 100644 --- a/tests/staged_files_only_test.py +++ b/tests/staged_files_only_test.py @@ -350,3 +350,14 @@ def test_autocrlf_commited_crlf(in_git_dir, patch_dir): with staged_files_only(patch_dir): assert_no_diff() + + +def test_intent_to_add(in_git_dir, patch_dir): + """Regression test for #881""" + _write(b'hello\nworld\n') + cmd_output('git', 'add', '--intent-to-add', 'foo') + + with staged_files_only(patch_dir): + # there's another bug with `diff-index` with `--intent-to-add` + # TODO: use `assert_no_diff()` + cmd_output('git', 'diff', '--exit-code', '--')