We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Incorrect shebang in .git/hooks/pre-commit for python3 only installations
The shebang for `.git/hooks/pre-commit` is `#!/usr/bin/env python`. I work with setups where `python3` is the only python in env.

Could the shebang be the install python instead? I.e. the installation under `INSTALL_PYTHON = '/usr/bin/python3'`

--- 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/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.path
7 import sys
8 
9 from pre_commit import git
10 from pre_commit import output
11 from pre_commit.repository import repositories
12 from pre_commit.util import cmd_output
13 from pre_commit.util import make_executable
14 from pre_commit.util import mkdirp
15 from pre_commit.util import resource_text
16 
17 
18 logger = logging.getLogger(__name__)
19 
20 # This is used to identify the hook file we install
21 PRIOR_HASHES = (
22     '4d9958c90bc262f47553e2c073f14cfe',
23     'd8ee923c46731b42cd95cc869add4062',
24     '49fd668cb42069aa1b6048464be5d395',
25     '79f09a650522a87b0da915d0d983b2de',
26     'e358c9dae00eac5d06b38dfdb1e33a8c',
27 )
28 CURRENT_HASH = '138fd403232d2ddd5efb44317e38bf03'
29 TEMPLATE_START = '# start templated\n'
30 TEMPLATE_END = '# end templated\n'
31 
32 
33 def _hook_paths(git_root, hook_type):
34     pth = os.path.join(git.get_git_dir(git_root), 'hooks', hook_type)
35     return pth, '{}.legacy'.format(pth)
36 
37 
38 def is_our_script(filename):
39     if not os.path.exists(filename):
40         return False
41     with io.open(filename) as f:
42         contents = f.read()
43     return any(h in contents for h in (CURRENT_HASH,) + PRIOR_HASHES)
44 
45 
46 def install(
47         runner, store, overwrite=False, hooks=False, hook_type='pre-commit',
48         skip_on_missing_conf=False,
49 ):
50     """Install the pre-commit hooks."""
51     if cmd_output('git', 'config', 'core.hooksPath', retcode=None)[1].strip():
52         logger.error(
53             'Cowardly refusing to install hooks with `core.hooksPath` set.\n'
54             'hint: `git config --unset-all core.hooksPath`',
55         )
56         return 1
57 
58     hook_path, legacy_path = _hook_paths(runner.git_root, hook_type)
59 
60     mkdirp(os.path.dirname(hook_path))
61 
62     # If we have an existing hook, move it to pre-commit.legacy
63     if os.path.lexists(hook_path) and not is_our_script(hook_path):
64         os.rename(hook_path, legacy_path)
65 
66     # If we specify overwrite, we simply delete the legacy file
67     if overwrite and os.path.exists(legacy_path):
68         os.remove(legacy_path)
69     elif os.path.exists(legacy_path):
70         output.write_line(
71             'Running in migration mode with existing hooks at {}\n'
72             'Use -f to use only pre-commit.'.format(legacy_path),
73         )
74 
75     params = {
76         'CONFIG': runner.config_file,
77         'HOOK_TYPE': hook_type,
78         'INSTALL_PYTHON': sys.executable,
79         'SKIP_ON_MISSING_CONFIG': skip_on_missing_conf,
80     }
81 
82     with io.open(hook_path, 'w') as hook_file:
83         contents = resource_text('hook-tmpl')
84         before, rest = contents.split(TEMPLATE_START)
85         to_template, after = rest.split(TEMPLATE_END)
86 
87         hook_file.write(before + TEMPLATE_START)
88         for line in to_template.splitlines():
89             var = line.split()[0]
90             hook_file.write('{} = {!r}\n'.format(var, params[var]))
91         hook_file.write(TEMPLATE_END + after)
92     make_executable(hook_path)
93 
94     output.write_line('pre-commit installed at {}'.format(hook_path))
95 
96     # If they requested we install all of the hooks, do so.
97     if hooks:
98         install_hooks(runner, store)
99 
100     return 0
101 
102 
103 def install_hooks(runner, store):
104     for repository in repositories(runner.config, store):
105         repository.require_installed()
106 
107 
108 def uninstall(runner, hook_type='pre-commit'):
109     """Uninstall the pre-commit hooks."""
110     hook_path, legacy_path = _hook_paths(runner.git_root, hook_type)
111 
112     # If our file doesn't exist or it isn't ours, gtfo.
113     if not os.path.exists(hook_path) or not is_our_script(hook_path):
114         return 0
115 
116     os.remove(hook_path)
117     output.write_line('{} uninstalled'.format(hook_type))
118 
119     if os.path.exists(legacy_path):
120         os.rename(legacy_path, hook_path)
121         output.write_line('Restored previous hooks to {}'.format(hook_path))
122 
123     return 0
124
```
--- 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
@@ -8,6 +8,7 @@
 
 from pre_commit import git
 from pre_commit import output
+from pre_commit.languages import python
 from pre_commit.repository import repositories
 from pre_commit.util import cmd_output
 from pre_commit.util import make_executable
@@ -43,6 +44,16 @@
     return any(h in contents for h in (CURRENT_HASH,) + PRIOR_HASHES)
 
 
+def shebang():
+    if sys.platform == 'win32':
+        py = 'python'
+    else:
+        py = python.get_default_version()
+        if py == 'default':
+            py = 'python'
+    return '#!/usr/bin/env {}'.format(py)
+
+
 def install(
         runner, store, overwrite=False, hooks=False, hook_type='pre-commit',
         skip_on_missing_conf=False,
@@ -84,6 +95,8 @@
         before, rest = contents.split(TEMPLATE_START)
         to_template, after = rest.split(TEMPLATE_END)
 
+        before = before.replace('#!/usr/bin/env python', shebang())
+
         hook_file.write(before + TEMPLATE_START)
         for line in to_template.splitlines():
             var = line.split()[0]

{"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@@ -8,6 +8,7 @@\n \n from pre_commit import git\n from pre_commit import output\n+from pre_commit.languages import python\n from pre_commit.repository import repositories\n from pre_commit.util import cmd_output\n from pre_commit.util import make_executable\n@@ -43,6 +44,16 @@\n     return any(h in contents for h in (CURRENT_HASH,) + PRIOR_HASHES)\n \n \n+def shebang():\n+    if sys.platform == 'win32':\n+        py = 'python'\n+    else:\n+        py = python.get_default_version()\n+        if py == 'default':\n+            py = 'python'\n+    return '#!/usr/bin/env {}'.format(py)\n+\n+\n def install(\n         runner, store, overwrite=False, hooks=False, hook_type='pre-commit',\n         skip_on_missing_conf=False,\n@@ -84,6 +95,8 @@\n         before, rest = contents.split(TEMPLATE_START)\n         to_template, after = rest.split(TEMPLATE_END)\n \n+        before = before.replace('#!/usr/bin/env python', shebang())\n+\n         hook_file.write(before + TEMPLATE_START)\n         for line in to_template.splitlines():\n             var = line.split()[0]\n", "issue": "Incorrect shebang in .git/hooks/pre-commit for python3 only installations\nThe shebang for `.git/hooks/pre-commit` is `#!/usr/bin/env python`. I work with setups where `python3` is the only python in env.\r\n\r\nCould the shebang be the install python instead? I.e. the installation under `INSTALL_PYTHON = '/usr/bin/python3'`\n", "before_files": [{"content": "from __future__ import print_function\nfrom __future__ import unicode_literals\n\nimport io\nimport logging\nimport os.path\nimport sys\n\nfrom pre_commit import git\nfrom pre_commit import output\nfrom pre_commit.repository import repositories\nfrom pre_commit.util import cmd_output\nfrom pre_commit.util import make_executable\nfrom pre_commit.util import mkdirp\nfrom pre_commit.util import resource_text\n\n\nlogger = logging.getLogger(__name__)\n\n# This is used to identify the hook file we install\nPRIOR_HASHES = (\n    '4d9958c90bc262f47553e2c073f14cfe',\n    'd8ee923c46731b42cd95cc869add4062',\n    '49fd668cb42069aa1b6048464be5d395',\n    '79f09a650522a87b0da915d0d983b2de',\n    'e358c9dae00eac5d06b38dfdb1e33a8c',\n)\nCURRENT_HASH = '138fd403232d2ddd5efb44317e38bf03'\nTEMPLATE_START = '# start templated\\n'\nTEMPLATE_END = '# end templated\\n'\n\n\ndef _hook_paths(git_root, hook_type):\n    pth = os.path.join(git.get_git_dir(git_root), 'hooks', hook_type)\n    return pth, '{}.legacy'.format(pth)\n\n\ndef is_our_script(filename):\n    if not os.path.exists(filename):\n        return False\n    with io.open(filename) as f:\n        contents = f.read()\n    return any(h in contents for h in (CURRENT_HASH,) + PRIOR_HASHES)\n\n\ndef install(\n        runner, store, overwrite=False, hooks=False, hook_type='pre-commit',\n        skip_on_missing_conf=False,\n):\n    \"\"\"Install the pre-commit hooks.\"\"\"\n    if cmd_output('git', 'config', 'core.hooksPath', retcode=None)[1].strip():\n        logger.error(\n            'Cowardly refusing to install hooks with `core.hooksPath` set.\\n'\n            'hint: `git config --unset-all core.hooksPath`',\n        )\n        return 1\n\n    hook_path, legacy_path = _hook_paths(runner.git_root, hook_type)\n\n    mkdirp(os.path.dirname(hook_path))\n\n    # If we have an existing hook, move it to pre-commit.legacy\n    if os.path.lexists(hook_path) and not is_our_script(hook_path):\n        os.rename(hook_path, legacy_path)\n\n    # If we specify overwrite, we simply delete the legacy file\n    if overwrite and os.path.exists(legacy_path):\n        os.remove(legacy_path)\n    elif os.path.exists(legacy_path):\n        output.write_line(\n            'Running in migration mode with existing hooks at {}\\n'\n            'Use -f to use only pre-commit.'.format(legacy_path),\n        )\n\n    params = {\n        'CONFIG': runner.config_file,\n        'HOOK_TYPE': hook_type,\n        'INSTALL_PYTHON': sys.executable,\n        'SKIP_ON_MISSING_CONFIG': skip_on_missing_conf,\n    }\n\n    with io.open(hook_path, 'w') as hook_file:\n        contents = resource_text('hook-tmpl')\n        before, rest = contents.split(TEMPLATE_START)\n        to_template, after = rest.split(TEMPLATE_END)\n\n        hook_file.write(before + TEMPLATE_START)\n        for line in to_template.splitlines():\n            var = line.split()[0]\n            hook_file.write('{} = {!r}\\n'.format(var, params[var]))\n        hook_file.write(TEMPLATE_END + after)\n    make_executable(hook_path)\n\n    output.write_line('pre-commit installed at {}'.format(hook_path))\n\n    # If they requested we install all of the hooks, do so.\n    if hooks:\n        install_hooks(runner, store)\n\n    return 0\n\n\ndef install_hooks(runner, store):\n    for repository in repositories(runner.config, store):\n        repository.require_installed()\n\n\ndef uninstall(runner, hook_type='pre-commit'):\n    \"\"\"Uninstall the pre-commit hooks.\"\"\"\n    hook_path, legacy_path = _hook_paths(runner.git_root, hook_type)\n\n    # If our file doesn't exist or it isn't ours, gtfo.\n    if not os.path.exists(hook_path) or not is_our_script(hook_path):\n        return 0\n\n    os.remove(hook_path)\n    output.write_line('{} uninstalled'.format(hook_type))\n\n    if os.path.exists(legacy_path):\n        os.rename(legacy_path, hook_path)\n        output.write_line('Restored previous hooks to {}'.format(hook_path))\n\n    return 0\n", "path": "pre_commit/commands/install_uninstall.py"}], "after_files": [{"content": "from __future__ import print_function\nfrom __future__ import unicode_literals\n\nimport io\nimport logging\nimport os.path\nimport sys\n\nfrom pre_commit import git\nfrom pre_commit import output\nfrom pre_commit.languages import python\nfrom pre_commit.repository import repositories\nfrom pre_commit.util import cmd_output\nfrom pre_commit.util import make_executable\nfrom pre_commit.util import mkdirp\nfrom pre_commit.util import resource_text\n\n\nlogger = logging.getLogger(__name__)\n\n# This is used to identify the hook file we install\nPRIOR_HASHES = (\n    '4d9958c90bc262f47553e2c073f14cfe',\n    'd8ee923c46731b42cd95cc869add4062',\n    '49fd668cb42069aa1b6048464be5d395',\n    '79f09a650522a87b0da915d0d983b2de',\n    'e358c9dae00eac5d06b38dfdb1e33a8c',\n)\nCURRENT_HASH = '138fd403232d2ddd5efb44317e38bf03'\nTEMPLATE_START = '# start templated\\n'\nTEMPLATE_END = '# end templated\\n'\n\n\ndef _hook_paths(git_root, hook_type):\n    pth = os.path.join(git.get_git_dir(git_root), 'hooks', hook_type)\n    return pth, '{}.legacy'.format(pth)\n\n\ndef is_our_script(filename):\n    if not os.path.exists(filename):\n        return False\n    with io.open(filename) as f:\n        contents = f.read()\n    return any(h in contents for h in (CURRENT_HASH,) + PRIOR_HASHES)\n\n\ndef shebang():\n    if sys.platform == 'win32':\n        py = 'python'\n    else:\n        py = python.get_default_version()\n        if py == 'default':\n            py = 'python'\n    return '#!/usr/bin/env {}'.format(py)\n\n\ndef install(\n        runner, store, overwrite=False, hooks=False, hook_type='pre-commit',\n        skip_on_missing_conf=False,\n):\n    \"\"\"Install the pre-commit hooks.\"\"\"\n    if cmd_output('git', 'config', 'core.hooksPath', retcode=None)[1].strip():\n        logger.error(\n            'Cowardly refusing to install hooks with `core.hooksPath` set.\\n'\n            'hint: `git config --unset-all core.hooksPath`',\n        )\n        return 1\n\n    hook_path, legacy_path = _hook_paths(runner.git_root, hook_type)\n\n    mkdirp(os.path.dirname(hook_path))\n\n    # If we have an existing hook, move it to pre-commit.legacy\n    if os.path.lexists(hook_path) and not is_our_script(hook_path):\n        os.rename(hook_path, legacy_path)\n\n    # If we specify overwrite, we simply delete the legacy file\n    if overwrite and os.path.exists(legacy_path):\n        os.remove(legacy_path)\n    elif os.path.exists(legacy_path):\n        output.write_line(\n            'Running in migration mode with existing hooks at {}\\n'\n            'Use -f to use only pre-commit.'.format(legacy_path),\n        )\n\n    params = {\n        'CONFIG': runner.config_file,\n        'HOOK_TYPE': hook_type,\n        'INSTALL_PYTHON': sys.executable,\n        'SKIP_ON_MISSING_CONFIG': skip_on_missing_conf,\n    }\n\n    with io.open(hook_path, 'w') as hook_file:\n        contents = resource_text('hook-tmpl')\n        before, rest = contents.split(TEMPLATE_START)\n        to_template, after = rest.split(TEMPLATE_END)\n\n        before = before.replace('#!/usr/bin/env python', shebang())\n\n        hook_file.write(before + TEMPLATE_START)\n        for line in to_template.splitlines():\n            var = line.split()[0]\n            hook_file.write('{} = {!r}\\n'.format(var, params[var]))\n        hook_file.write(TEMPLATE_END + after)\n    make_executable(hook_path)\n\n    output.write_line('pre-commit installed at {}'.format(hook_path))\n\n    # If they requested we install all of the hooks, do so.\n    if hooks:\n        install_hooks(runner, store)\n\n    return 0\n\n\ndef install_hooks(runner, store):\n    for repository in repositories(runner.config, store):\n        repository.require_installed()\n\n\ndef uninstall(runner, hook_type='pre-commit'):\n    \"\"\"Uninstall the pre-commit hooks.\"\"\"\n    hook_path, legacy_path = _hook_paths(runner.git_root, hook_type)\n\n    # If our file doesn't exist or it isn't ours, gtfo.\n    if not os.path.exists(hook_path) or not is_our_script(hook_path):\n        return 0\n\n    os.remove(hook_path)\n    output.write_line('{} uninstalled'.format(hook_type))\n\n    if os.path.exists(legacy_path):\n        os.rename(legacy_path, hook_path)\n        output.write_line('Restored previous hooks to {}'.format(hook_path))\n\n    return 0\n", "path": "pre_commit/commands/install_uninstall.py"}]}