prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Newly gitignored (but file still exists) files are linted
  (they should not be)
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `pre_commit/git.py`
  Content:
  ```
  1 from __future__ import unicode_literals
  2 
  3 import functools
  4 import logging
  5 import os
  6 import os.path
  7 import re
  8 
  9 from pre_commit.errors import FatalError
  10 from pre_commit.util import CalledProcessError
  11 from pre_commit.util import cmd_output
  12 from pre_commit.util import memoize_by_cwd
  13 
  14 
  15 logger = logging.getLogger('pre_commit')
  16 
  17 
  18 def get_root():
  19     try:
  20         return cmd_output('git', 'rev-parse', '--show-toplevel')[1].strip()
  21     except CalledProcessError:
  22         raise FatalError(
  23             'Called from outside of the gits.  Please cd to a git repository.'
  24         )
  25 
  26 
  27 def get_git_dir(git_root):
  28     return os.path.normpath(os.path.join(
  29         git_root,
  30         cmd_output('git', 'rev-parse', '--git-dir', cwd=git_root)[1].strip(),
  31     ))
  32 
  33 
  34 def is_in_merge_conflict():
  35     git_dir = get_git_dir('.')
  36     return (
  37         os.path.exists(os.path.join(git_dir, 'MERGE_MSG')) and
  38         os.path.exists(os.path.join(git_dir, 'MERGE_HEAD'))
  39     )
  40 
  41 
  42 def parse_merge_msg_for_conflicts(merge_msg):
  43     # Conflicted files start with tabs
  44     return [
  45         line.lstrip('#').strip()
  46         for line in merge_msg.splitlines()
  47         # '#\t' for git 2.4.1
  48         if line.startswith(('\t', '#\t'))
  49     ]
  50 
  51 
  52 @memoize_by_cwd
  53 def get_conflicted_files():
  54     logger.info('Checking merge-conflict files only.')
  55     # Need to get the conflicted files from the MERGE_MSG because they could
  56     # have resolved the conflict by choosing one side or the other
  57     merge_msg = open(os.path.join(get_git_dir('.'), 'MERGE_MSG')).read()
  58     merge_conflict_filenames = parse_merge_msg_for_conflicts(merge_msg)
  59 
  60     # This will get the rest of the changes made after the merge.
  61     # If they resolved the merge conflict by choosing a mesh of both sides
  62     # this will also include the conflicted files
  63     tree_hash = cmd_output('git', 'write-tree')[1].strip()
  64     merge_diff_filenames = cmd_output(
  65         'git', 'diff', '-m', tree_hash, 'HEAD', 'MERGE_HEAD', '--name-only',
  66     )[1].splitlines()
  67     return set(merge_conflict_filenames) | set(merge_diff_filenames)
  68 
  69 
  70 @memoize_by_cwd
  71 def get_staged_files():
  72     return cmd_output('git', 'diff', '--staged', '--name-only')[1].splitlines()
  73 
  74 
  75 @memoize_by_cwd
  76 def get_all_files():
  77     return cmd_output('git', 'ls-files')[1].splitlines()
  78 
  79 
  80 def get_files_matching(all_file_list_strategy):
  81     @functools.wraps(all_file_list_strategy)
  82     @memoize_by_cwd
  83     def wrapper(include_expr, exclude_expr):
  84         include_regex = re.compile(include_expr)
  85         exclude_regex = re.compile(exclude_expr)
  86         return set(
  87             filename
  88             for filename in all_file_list_strategy()
  89             if (
  90                 include_regex.search(filename) and
  91                 not exclude_regex.search(filename) and
  92                 os.path.lexists(filename)
  93             )
  94         )
  95     return wrapper
  96 
  97 
  98 get_staged_files_matching = get_files_matching(get_staged_files)
  99 get_all_files_matching = get_files_matching(get_all_files)
  100 get_conflicted_files_matching = get_files_matching(get_conflicted_files)
  101
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/pre_commit/git.py b/pre_commit/git.py
  --- a/pre_commit/git.py
  +++ b/pre_commit/git.py
  @@ -69,7 +69,11 @@
   
   @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
  
verification_info: {"golden_diff": "diff --git a/pre_commit/git.py b/pre_commit/git.py\n--- a/pre_commit/git.py\n+++ b/pre_commit/git.py\n@@ -69,7 +69,11 @@\n \n @memoize_by_cwd\n def get_staged_files():\n-    return cmd_output('git', 'diff', '--staged', '--name-only')[1].splitlines()\n+    return cmd_output(\n+        'git', 'diff', '--staged', '--name-only',\n+        # Everything except for D\n+        '--diff-filter=ACMRTUXB'\n+    )[1].splitlines()\n \n \n @memoize_by_cwd\n", "issue": "Newly gitignored (but file still exists) files are linted\n(they should not be)\n\n", "before_files": [{"content": "from __future__ import unicode_literals\n\nimport functools\nimport logging\nimport os\nimport os.path\nimport re\n\nfrom pre_commit.errors import FatalError\nfrom pre_commit.util import CalledProcessError\nfrom pre_commit.util import cmd_output\nfrom pre_commit.util import memoize_by_cwd\n\n\nlogger = logging.getLogger('pre_commit')\n\n\ndef get_root():\n    try:\n        return cmd_output('git', 'rev-parse', '--show-toplevel')[1].strip()\n    except CalledProcessError:\n        raise FatalError(\n            'Called from outside of the gits.  Please cd to a git repository.'\n        )\n\n\ndef get_git_dir(git_root):\n    return os.path.normpath(os.path.join(\n        git_root,\n        cmd_output('git', 'rev-parse', '--git-dir', cwd=git_root)[1].strip(),\n    ))\n\n\ndef is_in_merge_conflict():\n    git_dir = get_git_dir('.')\n    return (\n        os.path.exists(os.path.join(git_dir, 'MERGE_MSG')) and\n        os.path.exists(os.path.join(git_dir, 'MERGE_HEAD'))\n    )\n\n\ndef parse_merge_msg_for_conflicts(merge_msg):\n    # Conflicted files start with tabs\n    return [\n        line.lstrip('#').strip()\n        for line in merge_msg.splitlines()\n        # '#\\t' for git 2.4.1\n        if line.startswith(('\\t', '#\\t'))\n    ]\n\n\n@memoize_by_cwd\ndef get_conflicted_files():\n    logger.info('Checking merge-conflict files only.')\n    # Need to get the conflicted files from the MERGE_MSG because they could\n    # have resolved the conflict by choosing one side or the other\n    merge_msg = open(os.path.join(get_git_dir('.'), 'MERGE_MSG')).read()\n    merge_conflict_filenames = parse_merge_msg_for_conflicts(merge_msg)\n\n    # This will get the rest of the changes made after the merge.\n    # If they resolved the merge conflict by choosing a mesh of both sides\n    # this will also include the conflicted files\n    tree_hash = cmd_output('git', 'write-tree')[1].strip()\n    merge_diff_filenames = cmd_output(\n        'git', 'diff', '-m', tree_hash, 'HEAD', 'MERGE_HEAD', '--name-only',\n    )[1].splitlines()\n    return set(merge_conflict_filenames) | set(merge_diff_filenames)\n\n\n@memoize_by_cwd\ndef get_staged_files():\n    return cmd_output('git', 'diff', '--staged', '--name-only')[1].splitlines()\n\n\n@memoize_by_cwd\ndef get_all_files():\n    return cmd_output('git', 'ls-files')[1].splitlines()\n\n\ndef get_files_matching(all_file_list_strategy):\n    @functools.wraps(all_file_list_strategy)\n    @memoize_by_cwd\n    def wrapper(include_expr, exclude_expr):\n        include_regex = re.compile(include_expr)\n        exclude_regex = re.compile(exclude_expr)\n        return set(\n            filename\n            for filename in all_file_list_strategy()\n            if (\n                include_regex.search(filename) and\n                not exclude_regex.search(filename) and\n                os.path.lexists(filename)\n            )\n        )\n    return wrapper\n\n\nget_staged_files_matching = get_files_matching(get_staged_files)\nget_all_files_matching = get_files_matching(get_all_files)\nget_conflicted_files_matching = get_files_matching(get_conflicted_files)\n", "path": "pre_commit/git.py"}], "after_files": [{"content": "from __future__ import unicode_literals\n\nimport functools\nimport logging\nimport os\nimport os.path\nimport re\n\nfrom pre_commit.errors import FatalError\nfrom pre_commit.util import CalledProcessError\nfrom pre_commit.util import cmd_output\nfrom pre_commit.util import memoize_by_cwd\n\n\nlogger = logging.getLogger('pre_commit')\n\n\ndef get_root():\n    try:\n        return cmd_output('git', 'rev-parse', '--show-toplevel')[1].strip()\n    except CalledProcessError:\n        raise FatalError(\n            'Called from outside of the gits.  Please cd to a git repository.'\n        )\n\n\ndef get_git_dir(git_root):\n    return os.path.normpath(os.path.join(\n        git_root,\n        cmd_output('git', 'rev-parse', '--git-dir', cwd=git_root)[1].strip(),\n    ))\n\n\ndef is_in_merge_conflict():\n    git_dir = get_git_dir('.')\n    return (\n        os.path.exists(os.path.join(git_dir, 'MERGE_MSG')) and\n        os.path.exists(os.path.join(git_dir, 'MERGE_HEAD'))\n    )\n\n\ndef parse_merge_msg_for_conflicts(merge_msg):\n    # Conflicted files start with tabs\n    return [\n        line.lstrip('#').strip()\n        for line in merge_msg.splitlines()\n        # '#\\t' for git 2.4.1\n        if line.startswith(('\\t', '#\\t'))\n    ]\n\n\n@memoize_by_cwd\ndef get_conflicted_files():\n    logger.info('Checking merge-conflict files only.')\n    # Need to get the conflicted files from the MERGE_MSG because they could\n    # have resolved the conflict by choosing one side or the other\n    merge_msg = open(os.path.join(get_git_dir('.'), 'MERGE_MSG')).read()\n    merge_conflict_filenames = parse_merge_msg_for_conflicts(merge_msg)\n\n    # This will get the rest of the changes made after the merge.\n    # If they resolved the merge conflict by choosing a mesh of both sides\n    # this will also include the conflicted files\n    tree_hash = cmd_output('git', 'write-tree')[1].strip()\n    merge_diff_filenames = cmd_output(\n        'git', 'diff', '-m', tree_hash, 'HEAD', 'MERGE_HEAD', '--name-only',\n    )[1].splitlines()\n    return set(merge_conflict_filenames) | set(merge_diff_filenames)\n\n\n@memoize_by_cwd\ndef get_staged_files():\n    return cmd_output(\n        'git', 'diff', '--staged', '--name-only',\n        # Everything except for D\n        '--diff-filter=ACMRTUXB'\n    )[1].splitlines()\n\n\n@memoize_by_cwd\ndef get_all_files():\n    return cmd_output('git', 'ls-files')[1].splitlines()\n\n\ndef get_files_matching(all_file_list_strategy):\n    @functools.wraps(all_file_list_strategy)\n    @memoize_by_cwd\n    def wrapper(include_expr, exclude_expr):\n        include_regex = re.compile(include_expr)\n        exclude_regex = re.compile(exclude_expr)\n        return set(\n            filename\n            for filename in all_file_list_strategy()\n            if (\n                include_regex.search(filename) and\n                not exclude_regex.search(filename) and\n                os.path.lexists(filename)\n            )\n        )\n    return wrapper\n\n\nget_staged_files_matching = get_files_matching(get_staged_files)\nget_all_files_matching = get_files_matching(get_all_files)\nget_conflicted_files_matching = get_files_matching(get_conflicted_files)\n", "path": "pre_commit/git.py"}]}