We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Choose python more intelligently in the file installed to .git/hooks/pre-commit
Since we know which python we're running as when `pre-commit install` is run (`sys.executable`), let's put that into `.git/hooks/pre-commit` and try that python first.

This will involve bumping the magic number in the resource file, and probably updating the logic to check for the same sys.executable existing inside that file.


--- 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/output.py`
Content:
```
1 from __future__ import unicode_literals
2 
3 import subprocess
4 import sys
5 
6 from pre_commit import color
7 from pre_commit import five
8 
9 
10 # TODO: smell: import side-effects
11 COLS = int(
12     subprocess.Popen(
13         ['tput', 'cols'], stdout=subprocess.PIPE
14     ).communicate()[0] or
15     # Default in the case of no terminal
16     80
17 )
18 
19 
20 def get_hook_message(
21         start,
22         postfix='',
23         end_msg=None,
24         end_len=0,
25         end_color=None,
26         use_color=None,
27         cols=COLS,
28 ):
29     """Prints a message for running a hook.
30 
31     This currently supports three approaches:
32 
33     # Print `start` followed by dots, leaving 6 characters at the end
34     >>> print_hook_message('start', end_len=6)
35     start...............................................................
36 
37     # Print `start` followed by dots with the end message colored if coloring
38     # is specified and a newline afterwards
39     >>> print_hook_message(
40         'start',
41         end_msg='end',
42         end_color=color.RED,
43         use_color=True,
44     )
45     start...................................................................end
46 
47     # Print `start` followed by dots, followed by the `postfix` message
48     # uncolored, followed by the `end_msg` colored if specified and a newline
49     # afterwards
50     >>> print_hook_message(
51         'start',
52         postfix='postfix ',
53         end_msg='end',
54         end_color=color.RED,
55         use_color=True,
56     )
57     start...........................................................postfix end
58     """
59     if bool(end_msg) == bool(end_len):
60         raise ValueError('Expected one of (`end_msg`, `end_len`)')
61     if end_msg is not None and (end_color is None or use_color is None):
62         raise ValueError(
63             '`end_color` and `use_color` are required with `end_msg`'
64         )
65 
66     if end_len:
67         return start + '.' * (cols - len(start) - end_len - 1)
68     else:
69         return '{0}{1}{2}{3}\n'.format(
70             start,
71             '.' * (cols - len(start) - len(postfix) - len(end_msg) - 1),
72             postfix,
73             color.format_color(end_msg, end_color, use_color),
74         )
75 
76 
77 def sys_stdout_write_wrapper(s, stream=sys.stdout):
78     """Python 2.6 chokes on unicode being passed to sys.stdout.write.
79 
80     This is an adapter because PY2 is ok with bytes and PY3 requires text.
81     """
82     assert type(s) is five.text
83     if five.PY2:  # pragma: no cover (PY2)
84         s = s.encode('UTF-8')
85     stream.write(s)
86
```

Path: `pre_commit/commands/install_uninstall.py`
Content:
```
1 from __future__ import print_function
2 from __future__ import unicode_literals
3 
4 import io
5 import logging
6 import os
7 import os.path
8 import stat
9 
10 from pre_commit.logging_handler import LoggingHandler
11 from pre_commit.util import resource_filename
12 
13 
14 logger = logging.getLogger('pre_commit')
15 
16 
17 # This is used to identify the hook file we install
18 PREVIOUS_IDENTIFYING_HASHES = [
19     'd8ee923c46731b42cd95cc869add4062',
20 ]
21 
22 
23 IDENTIFYING_HASH = '4d9958c90bc262f47553e2c073f14cfe'
24 
25 
26 def is_our_pre_commit(filename):
27     return IDENTIFYING_HASH in io.open(filename).read()
28 
29 
30 def is_previous_pre_commit(filename):
31     contents = io.open(filename).read()
32     return any(hash in contents for hash in PREVIOUS_IDENTIFYING_HASHES)
33 
34 
35 def make_executable(filename):
36     original_mode = os.stat(filename).st_mode
37     os.chmod(
38         filename,
39         original_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH,
40     )
41 
42 
43 def install(runner, overwrite=False, hooks=False):
44     """Install the pre-commit hooks."""
45     pre_commit_file = resource_filename('pre-commit-hook')
46 
47     # If we have an existing hook, move it to pre-commit.legacy
48     if (
49         os.path.exists(runner.pre_commit_path) and
50         not is_our_pre_commit(runner.pre_commit_path) and
51         not is_previous_pre_commit(runner.pre_commit_path)
52     ):
53         os.rename(runner.pre_commit_path, runner.pre_commit_legacy_path)
54 
55     # If we specify overwrite, we simply delete the legacy file
56     if overwrite and os.path.exists(runner.pre_commit_legacy_path):
57         os.remove(runner.pre_commit_legacy_path)
58     elif os.path.exists(runner.pre_commit_legacy_path):
59         print(
60             'Running in migration mode with existing hooks at {0}\n'
61             'Use -f to use only pre-commit.'.format(
62                 runner.pre_commit_legacy_path,
63             )
64         )
65 
66     with open(runner.pre_commit_path, 'w') as pre_commit_file_obj:
67         pre_commit_file_obj.write(open(pre_commit_file).read())
68     make_executable(runner.pre_commit_path)
69 
70     print('pre-commit installed at {0}'.format(runner.pre_commit_path))
71 
72     # If they requested we install all of the hooks, do so.
73     if hooks:
74         # Set up our logging handler
75         logger.addHandler(LoggingHandler(False))
76         logger.setLevel(logging.INFO)
77         for repository in runner.repositories:
78             repository.require_installed()
79 
80     return 0
81 
82 
83 def uninstall(runner):
84     """Uninstall the pre-commit hooks."""
85     # If our file doesn't exist or it isn't ours, gtfo.
86     if (
87         not os.path.exists(runner.pre_commit_path) or (
88             not is_our_pre_commit(runner.pre_commit_path) and
89             not is_previous_pre_commit(runner.pre_commit_path)
90         )
91     ):
92         return 0
93 
94     os.remove(runner.pre_commit_path)
95     print('pre-commit uninstalled')
96 
97     if os.path.exists(runner.pre_commit_legacy_path):
98         os.rename(runner.pre_commit_legacy_path, runner.pre_commit_path)
99         print('Restored previous hooks to {0}'.format(runner.pre_commit_path))
100 
101     return 0
102
```
--- 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()

```

diff --git a/pre_commit/commands/install_uninstall.py b/pre_commit/commands/install_uninstall.py
--- a/pre_commit/commands/install_uninstall.py
+++ b/pre_commit/commands/install_uninstall.py
@@ -6,6 +6,7 @@
 import os
 import os.path
 import stat
+import sys
 
 from pre_commit.logging_handler import LoggingHandler
 from pre_commit.util import resource_filename
@@ -15,12 +16,13 @@
 
 
 # This is used to identify the hook file we install
-PREVIOUS_IDENTIFYING_HASHES = [
+PREVIOUS_IDENTIFYING_HASHES = (
+    '4d9958c90bc262f47553e2c073f14cfe',
     'd8ee923c46731b42cd95cc869add4062',
-]
+)
 
 
-IDENTIFYING_HASH = '4d9958c90bc262f47553e2c073f14cfe'
+IDENTIFYING_HASH = '49fd668cb42069aa1b6048464be5d395'
 
 
 def is_our_pre_commit(filename):
@@ -63,8 +65,11 @@
             )
         )
 
-    with open(runner.pre_commit_path, 'w') as pre_commit_file_obj:
-        pre_commit_file_obj.write(open(pre_commit_file).read())
+    with io.open(runner.pre_commit_path, 'w') as pre_commit_file_obj:
+        contents = io.open(pre_commit_file).read().format(
+            sys_executable=sys.executable,
+        )
+        pre_commit_file_obj.write(contents)
     make_executable(runner.pre_commit_path)
 
     print('pre-commit installed at {0}'.format(runner.pre_commit_path))
diff --git a/pre_commit/output.py b/pre_commit/output.py
--- a/pre_commit/output.py
+++ b/pre_commit/output.py
@@ -1,5 +1,6 @@
 from __future__ import unicode_literals
 
+import os
 import subprocess
 import sys
 
@@ -10,7 +11,7 @@
 # TODO: smell: import side-effects
 COLS = int(
     subprocess.Popen(
-        ['tput', 'cols'], stdout=subprocess.PIPE
+        ['tput', 'cols'], stdout=subprocess.PIPE, stderr=open(os.devnull, 'w'),
     ).communicate()[0] or
     # Default in the case of no terminal
     80

{"golden_diff": "diff --git a/pre_commit/commands/install_uninstall.py b/pre_commit/commands/install_uninstall.py\n--- a/pre_commit/commands/install_uninstall.py\n+++ b/pre_commit/commands/install_uninstall.py\n@@ -6,6 +6,7 @@\n import os\n import os.path\n import stat\n+import sys\n \n from pre_commit.logging_handler import LoggingHandler\n from pre_commit.util import resource_filename\n@@ -15,12 +16,13 @@\n \n \n # This is used to identify the hook file we install\n-PREVIOUS_IDENTIFYING_HASHES = [\n+PREVIOUS_IDENTIFYING_HASHES = (\n+    '4d9958c90bc262f47553e2c073f14cfe',\n     'd8ee923c46731b42cd95cc869add4062',\n-]\n+)\n \n \n-IDENTIFYING_HASH = '4d9958c90bc262f47553e2c073f14cfe'\n+IDENTIFYING_HASH = '49fd668cb42069aa1b6048464be5d395'\n \n \n def is_our_pre_commit(filename):\n@@ -63,8 +65,11 @@\n             )\n         )\n \n-    with open(runner.pre_commit_path, 'w') as pre_commit_file_obj:\n-        pre_commit_file_obj.write(open(pre_commit_file).read())\n+    with io.open(runner.pre_commit_path, 'w') as pre_commit_file_obj:\n+        contents = io.open(pre_commit_file).read().format(\n+            sys_executable=sys.executable,\n+        )\n+        pre_commit_file_obj.write(contents)\n     make_executable(runner.pre_commit_path)\n \n     print('pre-commit installed at {0}'.format(runner.pre_commit_path))\ndiff --git a/pre_commit/output.py b/pre_commit/output.py\n--- a/pre_commit/output.py\n+++ b/pre_commit/output.py\n@@ -1,5 +1,6 @@\n from __future__ import unicode_literals\n \n+import os\n import subprocess\n import sys\n \n@@ -10,7 +11,7 @@\n # TODO: smell: import side-effects\n COLS = int(\n     subprocess.Popen(\n-        ['tput', 'cols'], stdout=subprocess.PIPE\n+        ['tput', 'cols'], stdout=subprocess.PIPE, stderr=open(os.devnull, 'w'),\n     ).communicate()[0] or\n     # Default in the case of no terminal\n     80\n", "issue": "Choose python more intelligently in the file installed to .git/hooks/pre-commit\nSince we know which python we're running as when `pre-commit install` is run (`sys.executable`), let's put that into `.git/hooks/pre-commit` and try that python first.\n\nThis will involve bumping the magic number in the resource file, and probably updating the logic to check for the same sys.executable existing inside that file.\n\n", "before_files": [{"content": "from __future__ import unicode_literals\n\nimport subprocess\nimport sys\n\nfrom pre_commit import color\nfrom pre_commit import five\n\n\n# TODO: smell: import side-effects\nCOLS = int(\n    subprocess.Popen(\n        ['tput', 'cols'], stdout=subprocess.PIPE\n    ).communicate()[0] or\n    # Default in the case of no terminal\n    80\n)\n\n\ndef get_hook_message(\n        start,\n        postfix='',\n        end_msg=None,\n        end_len=0,\n        end_color=None,\n        use_color=None,\n        cols=COLS,\n):\n    \"\"\"Prints a message for running a hook.\n\n    This currently supports three approaches:\n\n    # Print `start` followed by dots, leaving 6 characters at the end\n    >>> print_hook_message('start', end_len=6)\n    start...............................................................\n\n    # Print `start` followed by dots with the end message colored if coloring\n    # is specified and a newline afterwards\n    >>> print_hook_message(\n        'start',\n        end_msg='end',\n        end_color=color.RED,\n        use_color=True,\n    )\n    start...................................................................end\n\n    # Print `start` followed by dots, followed by the `postfix` message\n    # uncolored, followed by the `end_msg` colored if specified and a newline\n    # afterwards\n    >>> print_hook_message(\n        'start',\n        postfix='postfix ',\n        end_msg='end',\n        end_color=color.RED,\n        use_color=True,\n    )\n    start...........................................................postfix end\n    \"\"\"\n    if bool(end_msg) == bool(end_len):\n        raise ValueError('Expected one of (`end_msg`, `end_len`)')\n    if end_msg is not None and (end_color is None or use_color is None):\n        raise ValueError(\n            '`end_color` and `use_color` are required with `end_msg`'\n        )\n\n    if end_len:\n        return start + '.' * (cols - len(start) - end_len - 1)\n    else:\n        return '{0}{1}{2}{3}\\n'.format(\n            start,\n            '.' * (cols - len(start) - len(postfix) - len(end_msg) - 1),\n            postfix,\n            color.format_color(end_msg, end_color, use_color),\n        )\n\n\ndef sys_stdout_write_wrapper(s, stream=sys.stdout):\n    \"\"\"Python 2.6 chokes on unicode being passed to sys.stdout.write.\n\n    This is an adapter because PY2 is ok with bytes and PY3 requires text.\n    \"\"\"\n    assert type(s) is five.text\n    if five.PY2:  # pragma: no cover (PY2)\n        s = s.encode('UTF-8')\n    stream.write(s)\n", "path": "pre_commit/output.py"}, {"content": "from __future__ import print_function\nfrom __future__ import unicode_literals\n\nimport io\nimport logging\nimport os\nimport os.path\nimport stat\n\nfrom pre_commit.logging_handler import LoggingHandler\nfrom pre_commit.util import resource_filename\n\n\nlogger = logging.getLogger('pre_commit')\n\n\n# This is used to identify the hook file we install\nPREVIOUS_IDENTIFYING_HASHES = [\n    'd8ee923c46731b42cd95cc869add4062',\n]\n\n\nIDENTIFYING_HASH = '4d9958c90bc262f47553e2c073f14cfe'\n\n\ndef is_our_pre_commit(filename):\n    return IDENTIFYING_HASH in io.open(filename).read()\n\n\ndef is_previous_pre_commit(filename):\n    contents = io.open(filename).read()\n    return any(hash in contents for hash in PREVIOUS_IDENTIFYING_HASHES)\n\n\ndef make_executable(filename):\n    original_mode = os.stat(filename).st_mode\n    os.chmod(\n        filename,\n        original_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH,\n    )\n\n\ndef install(runner, overwrite=False, hooks=False):\n    \"\"\"Install the pre-commit hooks.\"\"\"\n    pre_commit_file = resource_filename('pre-commit-hook')\n\n    # If we have an existing hook, move it to pre-commit.legacy\n    if (\n        os.path.exists(runner.pre_commit_path) and\n        not is_our_pre_commit(runner.pre_commit_path) and\n        not is_previous_pre_commit(runner.pre_commit_path)\n    ):\n        os.rename(runner.pre_commit_path, runner.pre_commit_legacy_path)\n\n    # If we specify overwrite, we simply delete the legacy file\n    if overwrite and os.path.exists(runner.pre_commit_legacy_path):\n        os.remove(runner.pre_commit_legacy_path)\n    elif os.path.exists(runner.pre_commit_legacy_path):\n        print(\n            'Running in migration mode with existing hooks at {0}\\n'\n            'Use -f to use only pre-commit.'.format(\n                runner.pre_commit_legacy_path,\n            )\n        )\n\n    with open(runner.pre_commit_path, 'w') as pre_commit_file_obj:\n        pre_commit_file_obj.write(open(pre_commit_file).read())\n    make_executable(runner.pre_commit_path)\n\n    print('pre-commit installed at {0}'.format(runner.pre_commit_path))\n\n    # If they requested we install all of the hooks, do so.\n    if hooks:\n        # Set up our logging handler\n        logger.addHandler(LoggingHandler(False))\n        logger.setLevel(logging.INFO)\n        for repository in runner.repositories:\n            repository.require_installed()\n\n    return 0\n\n\ndef uninstall(runner):\n    \"\"\"Uninstall the pre-commit hooks.\"\"\"\n    # If our file doesn't exist or it isn't ours, gtfo.\n    if (\n        not os.path.exists(runner.pre_commit_path) or (\n            not is_our_pre_commit(runner.pre_commit_path) and\n            not is_previous_pre_commit(runner.pre_commit_path)\n        )\n    ):\n        return 0\n\n    os.remove(runner.pre_commit_path)\n    print('pre-commit uninstalled')\n\n    if os.path.exists(runner.pre_commit_legacy_path):\n        os.rename(runner.pre_commit_legacy_path, runner.pre_commit_path)\n        print('Restored previous hooks to {0}'.format(runner.pre_commit_path))\n\n    return 0\n", "path": "pre_commit/commands/install_uninstall.py"}], "after_files": [{"content": "from __future__ import unicode_literals\n\nimport os\nimport subprocess\nimport sys\n\nfrom pre_commit import color\nfrom pre_commit import five\n\n\n# TODO: smell: import side-effects\nCOLS = int(\n    subprocess.Popen(\n        ['tput', 'cols'], stdout=subprocess.PIPE, stderr=open(os.devnull, 'w'),\n    ).communicate()[0] or\n    # Default in the case of no terminal\n    80\n)\n\n\ndef get_hook_message(\n        start,\n        postfix='',\n        end_msg=None,\n        end_len=0,\n        end_color=None,\n        use_color=None,\n        cols=COLS,\n):\n    \"\"\"Prints a message for running a hook.\n\n    This currently supports three approaches:\n\n    # Print `start` followed by dots, leaving 6 characters at the end\n    >>> print_hook_message('start', end_len=6)\n    start...............................................................\n\n    # Print `start` followed by dots with the end message colored if coloring\n    # is specified and a newline afterwards\n    >>> print_hook_message(\n        'start',\n        end_msg='end',\n        end_color=color.RED,\n        use_color=True,\n    )\n    start...................................................................end\n\n    # Print `start` followed by dots, followed by the `postfix` message\n    # uncolored, followed by the `end_msg` colored if specified and a newline\n    # afterwards\n    >>> print_hook_message(\n        'start',\n        postfix='postfix ',\n        end_msg='end',\n        end_color=color.RED,\n        use_color=True,\n    )\n    start...........................................................postfix end\n    \"\"\"\n    if bool(end_msg) == bool(end_len):\n        raise ValueError('Expected one of (`end_msg`, `end_len`)')\n    if end_msg is not None and (end_color is None or use_color is None):\n        raise ValueError(\n            '`end_color` and `use_color` are required with `end_msg`'\n        )\n\n    if end_len:\n        return start + '.' * (cols - len(start) - end_len - 1)\n    else:\n        return '{0}{1}{2}{3}\\n'.format(\n            start,\n            '.' * (cols - len(start) - len(postfix) - len(end_msg) - 1),\n            postfix,\n            color.format_color(end_msg, end_color, use_color),\n        )\n\n\ndef sys_stdout_write_wrapper(s, stream=sys.stdout):\n    \"\"\"Python 2.6 chokes on unicode being passed to sys.stdout.write.\n\n    This is an adapter because PY2 is ok with bytes and PY3 requires text.\n    \"\"\"\n    assert type(s) is five.text\n    if five.PY2:  # pragma: no cover (PY2)\n        s = s.encode('UTF-8')\n    stream.write(s)\n", "path": "pre_commit/output.py"}, {"content": "from __future__ import print_function\nfrom __future__ import unicode_literals\n\nimport io\nimport logging\nimport os\nimport os.path\nimport stat\nimport sys\n\nfrom pre_commit.logging_handler import LoggingHandler\nfrom pre_commit.util import resource_filename\n\n\nlogger = logging.getLogger('pre_commit')\n\n\n# This is used to identify the hook file we install\nPREVIOUS_IDENTIFYING_HASHES = (\n    '4d9958c90bc262f47553e2c073f14cfe',\n    'd8ee923c46731b42cd95cc869add4062',\n)\n\n\nIDENTIFYING_HASH = '49fd668cb42069aa1b6048464be5d395'\n\n\ndef is_our_pre_commit(filename):\n    return IDENTIFYING_HASH in io.open(filename).read()\n\n\ndef is_previous_pre_commit(filename):\n    contents = io.open(filename).read()\n    return any(hash in contents for hash in PREVIOUS_IDENTIFYING_HASHES)\n\n\ndef make_executable(filename):\n    original_mode = os.stat(filename).st_mode\n    os.chmod(\n        filename,\n        original_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH,\n    )\n\n\ndef install(runner, overwrite=False, hooks=False):\n    \"\"\"Install the pre-commit hooks.\"\"\"\n    pre_commit_file = resource_filename('pre-commit-hook')\n\n    # If we have an existing hook, move it to pre-commit.legacy\n    if (\n        os.path.exists(runner.pre_commit_path) and\n        not is_our_pre_commit(runner.pre_commit_path) and\n        not is_previous_pre_commit(runner.pre_commit_path)\n    ):\n        os.rename(runner.pre_commit_path, runner.pre_commit_legacy_path)\n\n    # If we specify overwrite, we simply delete the legacy file\n    if overwrite and os.path.exists(runner.pre_commit_legacy_path):\n        os.remove(runner.pre_commit_legacy_path)\n    elif os.path.exists(runner.pre_commit_legacy_path):\n        print(\n            'Running in migration mode with existing hooks at {0}\\n'\n            'Use -f to use only pre-commit.'.format(\n                runner.pre_commit_legacy_path,\n            )\n        )\n\n    with io.open(runner.pre_commit_path, 'w') as pre_commit_file_obj:\n        contents = io.open(pre_commit_file).read().format(\n            sys_executable=sys.executable,\n        )\n        pre_commit_file_obj.write(contents)\n    make_executable(runner.pre_commit_path)\n\n    print('pre-commit installed at {0}'.format(runner.pre_commit_path))\n\n    # If they requested we install all of the hooks, do so.\n    if hooks:\n        # Set up our logging handler\n        logger.addHandler(LoggingHandler(False))\n        logger.setLevel(logging.INFO)\n        for repository in runner.repositories:\n            repository.require_installed()\n\n    return 0\n\n\ndef uninstall(runner):\n    \"\"\"Uninstall the pre-commit hooks.\"\"\"\n    # If our file doesn't exist or it isn't ours, gtfo.\n    if (\n        not os.path.exists(runner.pre_commit_path) or (\n            not is_our_pre_commit(runner.pre_commit_path) and\n            not is_previous_pre_commit(runner.pre_commit_path)\n        )\n    ):\n        return 0\n\n    os.remove(runner.pre_commit_path)\n    print('pre-commit uninstalled')\n\n    if os.path.exists(runner.pre_commit_legacy_path):\n        os.rename(runner.pre_commit_legacy_path, runner.pre_commit_path)\n        print('Restored previous hooks to {0}'.format(runner.pre_commit_path))\n\n    return 0\n", "path": "pre_commit/commands/install_uninstall.py"}]}